Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics - Cluster Overview over Schedulers and Computers (incl. Avg. & Max. Compute Times) #1956

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/sirius/biz/analytics/checks/DailyCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sirius.biz.analytics.scheduler.AnalyticalTask;
import sirius.db.mixing.BaseEntity;
import sirius.kernel.di.std.AutoRegister;
import sirius.kernel.health.Average;

import java.time.LocalDate;

Expand All @@ -28,6 +29,18 @@
@AutoRegister
public abstract class DailyCheck<E extends BaseEntity<?>> implements AnalyticalTask<E> {

/**
* Contains the maximum duration of a computation in milliseconds.
*/
private long maxDurationMillis = 0;

/**
* Contains the average duration of computations in milliseconds.
* <p>
* This keeps track of the average duration via a sliding window.
*/
private final Average avgDurationMillis = new Average();

@Override
public void compute(LocalDate date, E entity, boolean bestEffort) {
execute(entity);
Expand All @@ -49,4 +62,27 @@ public boolean isEnabled() {
public int getLevel() {
return AnalyticalTask.DEFAULT_LEVEL;
}

@Override
public void trackDuration(long durationMillis) {
this.avgDurationMillis.addValue(durationMillis);
this.maxDurationMillis = Math.max(this.maxDurationMillis, durationMillis);
}

@Override
public void resetDurations() {
this.avgDurationMillis.getAndClear();
this.maxDurationMillis = 0;

}

@Override
public long getMaxDurationMillis() {
return maxDurationMillis;
}

@Override
public Average getAvgDurationMillis() {
return avgDurationMillis;
}
}
28 changes: 14 additions & 14 deletions src/main/java/sirius/biz/analytics/events/EventRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ public void record(@Nonnull Event<?> event) {
event.getDescriptor().beforeSave(event);
buffer.offer(event);
bufferedEvents.incrementAndGet();
} catch (HandledException e) {
} catch (HandledException exception) {
Log.BACKGROUND.WARN("An event was not recorded due to a before-save warning. Event: %s (%s): %s",
event.toString(),
event.getClass().getSimpleName(),
e.getMessage());
} catch (Exception e) {
Exceptions.handle(Log.BACKGROUND, e);
exception.getMessage());
} catch (Exception exception) {
Exceptions.handle(Log.BACKGROUND, exception);
}
}

Expand Down Expand Up @@ -490,10 +490,10 @@ protected int process() {

nextEvent = fetchBufferedEvent();
}
} catch (HandledException e) {
Exceptions.ignore(e);
} catch (Exception e) {
Exceptions.handle(Log.BACKGROUND, e);
} catch (HandledException exception) {
Exceptions.ignore(exception);
} catch (Exception exception) {
Exceptions.handle(Log.BACKGROUND, exception);
}

return processedEvents;
Expand All @@ -512,16 +512,16 @@ private void processEvent(BatchContext ctx,
Map<Class<? extends Event<?>>, InsertQuery<Event<?>>> queries,
Event<?> event) {
try {
InsertQuery<Event<?>> qry = queries.computeIfAbsent((Class<Event<?>>) event.getClass(),
type -> (InsertQuery<Event<?>>) ctx.insertQuery(type,
false));
qry.insert(event, false, true);
} catch (Exception e) {
InsertQuery<Event<?>> query = queries.computeIfAbsent((Class<Event<?>>) event.getClass(),
type -> (InsertQuery<Event<?>>) ctx.insertQuery(type,
false));
query.insert(event, false, true);
} catch (Exception exception) {
if (!event.retried) {
event.retried = true;
record(event);
}
throw e;
throw exception;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public Future chartApi(WebContext webContext, JSONStructuredOutput output) throw
computeGranularity(range),
comparisonPeriod,
output);
} catch (Exception error) {
throw Exceptions.handle(Log.APPLICATION, error);
} catch (Exception exception) {
throw Exceptions.handle(Log.APPLICATION, exception);
}
});
}
Expand Down Expand Up @@ -211,10 +211,10 @@ private Stream<Dataset> exportTimeSeriesAsDatasets(String identifier,
timeSeries,
comparisonPeriod)
.stream();
} catch (Exception error) {
} catch (Exception exception) {
Exceptions.handle()
.to(Log.BACKGROUND)
.error(error)
.error(exception)
.withSystemErrorMessage("DataExplorerController: Failed to compute time series for %s: %s (%s)",
identifier)
.handle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public void commit() {
.set(PerformanceFlagged.PERFORMANCE_DATA.inner(SQLPerformanceData.FLAGS), target.flags)
.where(SQLEntity.ID, target.getOwner().getId())
.executeUpdate();
} catch (SQLException e) {
} catch (SQLException exception) {
Exceptions.handle()
.to(Log.BACKGROUND)
.error(e)
.error(exception)
.withSystemErrorMessage("Failed to update performance flags of %s (%s): %s (%s)",
target.getOwner().getIdAsString(),
target.getOwner().getClass().getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public void commit() {
.addEachToSet(PerformanceFlagged.PERFORMANCE_DATA.inner(MongoPerformanceData.FLAGS), flagsToAdd)
.executeFor((MongoEntity) target.getOwner());
}
} catch (Exception e) {
} catch (Exception exception) {
Exceptions.handle()
.to(Log.BACKGROUND)
.error(e)
.error(exception)
.withSystemErrorMessage("Failed to update performance flags of %s (%s): %s (%s)",
target.getOwner().getIdAsString(),
target.getOwner().getClass().getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected void execute(E entity) {
try {
entity.getIndicators()
.updateIndication(indicator.getName(), ((Indicator<E>) indicator).executeFor(entity));
} catch (Exception e) {
Exceptions.handle(Log.BACKGROUND, e);
} catch (Exception exception) {
Exceptions.handle(Log.BACKGROUND, exception);
entity.getIndicators().updateIndication(indicator.getName(), false);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ protected void beforeSave() {
for (Indicator<?> indicator : indicators) {
try {
executeIndicator(indicator);
} catch (Exception e) {
Exceptions.handle(Log.BACKGROUND, e);
} catch (Exception exception) {
Exceptions.handle(Log.BACKGROUND, exception);
updateIndication(indicator.getName(), false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sirius.db.mixing.BaseEntity;
import sirius.kernel.di.std.AutoRegister;
import sirius.kernel.di.std.Part;
import sirius.kernel.health.Average;

import javax.annotation.Nullable;
import java.time.LocalDate;
Expand All @@ -32,6 +33,18 @@ public abstract class DailyMetricComputer<E extends BaseEntity<?>> implements An
@Nullable
protected Metrics metrics;

/**
* Contains the maximum duration of a computation in milliseconds.
*/
private long maxDurationMillis = 0;

/**
* Contains the average duration of computations in milliseconds.
* <p>
* This keeps track of the average duration via a sliding window.
*/
private final Average avgDurationMillis = new Average();

@Override
public boolean isEnabled() {
return true;
Expand All @@ -42,6 +55,29 @@ public int getLevel() {
return AnalyticalTask.DEFAULT_LEVEL;
}

@Override
public void trackDuration(long durationMillis) {
this.avgDurationMillis.addValue(durationMillis);
this.maxDurationMillis = Math.max(this.maxDurationMillis, durationMillis);
}

@Override
public void resetDurations() {
this.avgDurationMillis.getAndClear();
this.maxDurationMillis = 0;

}

@Override
public long getMaxDurationMillis() {
return maxDurationMillis;
}

@Override
public Average getAvgDurationMillis() {
return avgDurationMillis;
}

@Override
public final void compute(LocalDate date, E entity, boolean bestEffort) throws Exception {
boolean sameDay = LocalDate.now().equals(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sirius.db.mixing.BaseEntity;
import sirius.kernel.di.std.AutoRegister;
import sirius.kernel.di.std.Part;
import sirius.kernel.health.Average;

import javax.annotation.Nullable;
import java.time.LocalDate;
Expand All @@ -34,6 +35,18 @@ public abstract class MonthlyLargeMetricComputer<E extends BaseEntity<?>> implem
@Nullable
protected Metrics metrics;

/**
* Contains the maximum duration of a computation in milliseconds.
*/
private long maxDurationMillis = 0;

/**
* Contains the average duration of computations in milliseconds.
* <p>
* This keeps track of the average duration via a sliding window.
*/
private final Average avgDurationMillis = new Average();

@Override
public boolean isEnabled() {
return true;
Expand All @@ -44,6 +57,28 @@ public int getLevel() {
return AnalyticalTask.DEFAULT_LEVEL;
}

@Override
public void trackDuration(long durationMillis) {
this.avgDurationMillis.addValue(durationMillis);
this.maxDurationMillis = Math.max(this.maxDurationMillis, durationMillis);
}

@Override
public void resetDurations() {
this.avgDurationMillis.getAndClear();
this.maxDurationMillis = 0;
}

@Override
public long getMaxDurationMillis() {
return maxDurationMillis;
}

@Override
public Average getAvgDurationMillis() {
return avgDurationMillis;
}

@Override
public final void compute(LocalDate date, E entity, boolean bestEffort) throws Exception {
boolean sameMonth = LocalDate.now().withDayOfMonth(1).equals(date.withDayOfMonth(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sirius.db.mixing.BaseEntity;
import sirius.kernel.di.std.AutoRegister;
import sirius.kernel.di.std.Part;
import sirius.kernel.health.Average;

import javax.annotation.Nullable;
import java.time.LocalDate;
Expand All @@ -35,11 +36,46 @@ public abstract class MonthlyMetricComputer<E extends BaseEntity<?>> implements
@Nullable
protected Metrics metrics;

/**
* Contains the maximum duration of a computation in milliseconds.
*/
private long maxDurationMillis = 0;

/**
* Contains the average duration of computations in milliseconds.
* <p>
* This keeps track of the average duration via a sliding window.
*/
private final Average avgDurationMillis = new Average();

@Override
public int getLevel() {
return AnalyticalTask.DEFAULT_LEVEL;
}

@Override
public void trackDuration(long durationMillis) {
this.avgDurationMillis.addValue(durationMillis);
this.maxDurationMillis = Math.max(this.maxDurationMillis, durationMillis);
}

@Override
public void resetDurations() {
this.avgDurationMillis.getAndClear();
this.maxDurationMillis = 0;

}

@Override
public long getMaxDurationMillis() {
return maxDurationMillis;
}

@Override
public Average getAvgDurationMillis() {
return avgDurationMillis;
}

@Override
public boolean isEnabled() {
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/sirius/biz/analytics/metrics/jdbc/SQLMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ protected void deleteMetric(Class<? extends SQLEntity> table,
.whereIgnoreNull(MonthlyMetric.MONTH, month)
.whereIgnoreNull(DailyMetric.DAY, day)
.executeUpdate();
} catch (SQLException e) {
} catch (SQLException exception) {
throw Exceptions.handle()
.to(Mixing.LOG)
.error(e)
.error(exception)
.withSystemErrorMessage("Failed to delete a metric in %s: %s (%s)", table)
.handle();
}
Expand All @@ -104,10 +104,10 @@ protected boolean updateMetric(Class<? extends SQLEntity> table,
.executeUpdate();

return numModified > 0;
} catch (SQLException e) {
} catch (SQLException exception) {
throw Exceptions.handle()
.to(Mixing.LOG)
.error(e)
.error(exception)
.withSystemErrorMessage("Failed to update a metric in %s: %s (%s)", table)
.handle();
}
Expand Down Expand Up @@ -190,8 +190,8 @@ protected Optional<Integer> queryMetric(Class<? extends SQLEntity> table,
.asSQLQuery()
.first()
.map(row -> row.getValue(Fact.VALUE).asInt(0));
} catch (SQLException ex) {
throw Exceptions.handle(OMA.LOG, ex);
} catch (SQLException exception) {
throw Exceptions.handle(OMA.LOG, exception);
}
}
}
Loading