Search in sources :

Example 6 with IntegrationMetricsSummary

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();
}
Also used : SyndesisServerException(io.syndesis.common.util.SyndesisServerException) IntegrationMetricsSummary(io.syndesis.common.model.metrics.IntegrationMetricsSummary) ParseException(java.text.ParseException) Date(java.util.Date)

Example 7 with IntegrationMetricsSummary

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();
}
Also used : IntegrationDeploymentMetrics(io.syndesis.common.model.metrics.IntegrationDeploymentMetrics) HashMap(java.util.HashMap) IntegrationMetricsSummary(io.syndesis.common.model.metrics.IntegrationMetricsSummary) ArrayList(java.util.ArrayList) IntegrationDeploymentMetrics(io.syndesis.common.model.metrics.IntegrationDeploymentMetrics)

Example 8 with IntegrationMetricsSummary

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();
}
Also used : IntegrationMetricsSummary(io.syndesis.common.model.metrics.IntegrationMetricsSummary) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with IntegrationMetricsSummary

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();
}
Also used : IntegrationMetricsSummary(io.syndesis.common.model.metrics.IntegrationMetricsSummary) IntegrationDeploymentMetrics(io.syndesis.common.model.metrics.IntegrationDeploymentMetrics) Date(java.util.Date)

Example 10 with IntegrationMetricsSummary

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();
}
Also used : IntegrationMetricsSummary(io.syndesis.common.model.metrics.IntegrationMetricsSummary) List(java.util.List) Test(org.junit.Test)

Aggregations

IntegrationMetricsSummary (io.syndesis.common.model.metrics.IntegrationMetricsSummary)10 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 Date (java.util.Date)3 List (java.util.List)3 IntegrationDeploymentMetrics (io.syndesis.common.model.metrics.IntegrationDeploymentMetrics)2 Then (cucumber.api.java.en.Then)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 Readiness (io.fabric8.kubernetes.client.internal.readiness.Readiness)1 Integration (io.syndesis.common.model.integration.Integration)1 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)1 DataManager (io.syndesis.server.dao.manager.DataManager)1 JsonDB (io.syndesis.server.jsondb.JsonDB)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1