use of io.syndesis.common.model.metrics.IntegrationMetricsSummary in project syndesis by syndesisio.
the class SQLMetricsProviderImpl method rollup.
private IntegrationMetricsSummary rollup(List<IntegrationMetricsSummary> metricsSummaryList) {
Long totalMessages = 0L;
Long totalErrors = 0L;
Optional<Date> totalLastProcessed = Optional.empty();
Optional<Date> totalStart = Optional.empty();
for (IntegrationMetricsSummary summary : metricsSummaryList) {
totalMessages += summary.getMessages();
totalErrors += summary.getErrors();
if (totalLastProcessed.isPresent()) {
totalLastProcessed = summary.getLastProcessed().isPresent() && totalLastProcessed.get().before(summary.getLastProcessed().get()) ? totalLastProcessed : summary.getLastProcessed();
} else {
totalLastProcessed = summary.getLastProcessed();
}
try {
totalStart = Optional.of(dateFormat.parse(openShiftClient.pods().withLabelSelector(SELECTOR).list().getItems().get(0).getStatus().getStartTime()));
} catch (ParseException e) {
throw new SyndesisServerException(e.getMessage(), e);
}
}
return new IntegrationMetricsSummary.Builder().metricsProvider("sql").messages(totalMessages).errors(totalErrors).lastProcessed(totalLastProcessed).start(totalStart).build();
}
use of io.syndesis.common.model.metrics.IntegrationMetricsSummary in project syndesis by syndesisio.
the class IntegrationMetricsHandler method compute.
/**
* Computes the IntegrationMetricsSummary from the RawMetrics available for the
* current integration.
*
* @param integrationId
* @param metrics
* @param livePodIds
* @return
*/
public IntegrationMetricsSummary compute(String integrationId, Map<String, RawMetrics> metrics, Set<String> livePodIds) {
Map<String, Metrics> m = new HashMap<>();
Metrics tm = new Metrics();
for (RawMetrics raw : metrics.values()) {
String version = raw.getVersion();
Metrics mh = m.containsKey(version) ? m.get(version) : new Metrics();
mh.add(livePodIds, raw);
m.put(version, mh);
tm = tm.add(livePodIds, raw);
}
List<IntegrationDeploymentMetrics> dmList = new ArrayList<>();
for (Metrics mh : m.values()) {
IntegrationDeploymentMetrics dm = new IntegrationDeploymentMetrics.Builder().version(mh.getVersion()).messages(mh.getMessages()).errors(mh.getErrors()).start(mh.getStartDate()).lastProcessed(mh.getLastProcessed()).build();
dmList.add(dm);
}
return new IntegrationMetricsSummary.Builder().id(integrationId).messages(tm.getMessages()).errors(tm.getErrors()).start(tm.getStartDate()).lastProcessed(tm.getLastProcessed()).integrationDeploymentMetrics(dmList).build();
}
use of io.syndesis.common.model.metrics.IntegrationMetricsSummary in project syndesis by syndesisio.
the class MetricsCollectorTest method testGetIntegrationSummary.
@Test
public void testGetIntegrationSummary() throws IOException, ParseException {
String integrationId = "intId1";
Set<String> livePodIds = new HashSet<String>(Arrays.asList("pod1", "pod2", "pod3", "pod4", "pod5"));
MetricsCollector collector = new MetricsCollector(null, jsondb, null);
Map<String, RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId);
IntegrationMetricsSummary summary = intMH.compute(integrationId, metrics, livePodIds);
assertThat(summary.getMessages()).isEqualTo(9);
assertThat(summary.getErrors()).isEqualTo(3);
// Oldest living pod
assertThat(summary.getStart().get()).isEqualTo(sdf.parse("31-01-2018 10:20:56"));
// Update pod2, add 6 messages
jsondb.update(JsonDBRawMetrics.path("intId1", "pod2"), Json.writer().writeValueAsString(raw("intId1", "2", "pod2", 9L, "31-01-2018 10:22:56")));
Map<String, RawMetrics> updatedMetrics = jsondbRM.getRawMetrics(integrationId);
IntegrationMetricsSummary updatedSummary = intMH.compute(integrationId, updatedMetrics, livePodIds);
assertThat(updatedSummary.getMessages()).isEqualTo(15);
assertThat(updatedSummary.getErrors()).isEqualTo(3);
collector.close();
}
use of io.syndesis.common.model.metrics.IntegrationMetricsSummary in project syndesis by syndesisio.
the class PrometheusMetricsProviderImpl method createIntegrationMetricsSummary.
private IntegrationMetricsSummary createIntegrationMetricsSummary(Map<String, Long> totalMessagesMap, Map<String, Long> failedMessagesMap, Map<String, Date> startTimeMap, Map<String, Date> lastProcessingTimeMap, Optional<Date> startTime, Optional<Date> lastProcessedTime) {
final long[] totalMessages = { 0L };
final long[] totalErrors = { 0L };
final List<IntegrationDeploymentMetrics> deploymentMetrics = totalMessagesMap.entrySet().stream().map(entry -> {
final String version = entry.getKey();
final Long messages = entry.getValue();
final Long errors = failedMessagesMap.get(version);
final Date start = startTimeMap.get(version);
final Date lastProcessed = lastProcessingTimeMap.get(version);
// aggregate values while we are at it
totalMessages[0] = SUM_LONGS.apply(totalMessages[0], messages);
totalErrors[0] = SUM_LONGS.apply(totalErrors[0], errors);
return new IntegrationDeploymentMetrics.Builder().version(version).messages(messages).errors(errors).start(Optional.ofNullable(start)).lastProcessed(Optional.ofNullable(lastProcessed)).build();
}).sorted(Comparator.comparing(IntegrationDeploymentMetrics::getVersion)).collect(Collectors.toList());
return new IntegrationMetricsSummary.Builder().metricsProvider("prometheus").integrationDeploymentMetrics(deploymentMetrics).start(startTime).lastProcessed(lastProcessedTime).messages(totalMessages[0]).errors(totalErrors[0]).build();
}
use of io.syndesis.common.model.metrics.IntegrationMetricsSummary in project syndesis by syndesisio.
the class PrometheusMetricsProviderImplTest method testGetTotalIntegrationMetricsSummary.
@Test
public void testGetTotalIntegrationMetricsSummary() throws Exception {
final IntegrationMetricsSummary summary = metricsProvider.getTotalIntegrationMetricsSummary();
assertThat(summary.getMessages()).isNotNull();
final Optional<List<IntegrationDeploymentMetrics>> deploymentMetrics = summary.getIntegrationDeploymentMetrics();
assertThat(deploymentMetrics).isEmpty();
}
Aggregations