Search in sources :

Example 6 with LongPointData

use of io.opentelemetry.sdk.metrics.data.LongPointData in project opentelemetry-plugin by jenkinsci.

the class JenkinsOtelPluginIntegrationTest method testMetricsWithDiskUsagePlugin.

@Ignore("Lifecycle problem, the InMemoryMetricExporter gets reset too much and the disk usage is not captured")
@Test
@WithPlugin("cloudbees-disk-usage-simple")
public void testMetricsWithDiskUsagePlugin() throws Exception {
    LOGGER.log(Level.INFO, "testMetricsWithDiskUsagePlugin...");
    // WORKAROUND because we don't know how to force the IntervalMetricReader to collect metrics
    // FIXME
    Thread.sleep(100);
    LOGGER.log(Level.INFO, "slept");
    openTelemetrySdkProvider.getOpenTelemetrySdk().getSdkMeterProvider().forceFlush();
    LOGGER.log(Level.INFO, "InMemoryMetricExporterProvider.LAST_CREATED_INSTANCE: " + InMemoryMetricExporterProvider.LAST_CREATED_INSTANCE);
    Map<String, MetricData> exportedMetrics = InMemoryMetricExporterUtils.getLastExportedMetricByMetricName(InMemoryMetricExporterProvider.LAST_CREATED_INSTANCE.getFinishedMetricItems());
    dumpMetrics(exportedMetrics);
    MetricData diskUsageData = exportedMetrics.get(JenkinsSemanticMetrics.JENKINS_DISK_USAGE_BYTES);
    MatcherAssert.assertThat(diskUsageData, CoreMatchers.notNullValue());
    // TODO TEST METRICS WITH PROPER RESET BETWEEN TESTS
    MatcherAssert.assertThat(diskUsageData.getType(), CoreMatchers.is(MetricDataType.LONG_GAUGE));
    Collection<LongPointData> metricPoints = diskUsageData.getLongGaugeData().getPoints();
    MatcherAssert.assertThat(Iterables.getLast(metricPoints).getValue(), CoreMatchers.notNullValue());
}
Also used : LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Ignore(org.junit.Ignore) Test(org.junit.Test) WithPlugin(org.jvnet.hudson.test.recipes.WithPlugin)

Example 7 with LongPointData

use of io.opentelemetry.sdk.metrics.data.LongPointData in project opentelemetry-plugin by jenkinsci.

the class JenkinsOtelPluginIntegrationTest method testSimplePipeline.

@Test
public void testSimplePipeline() throws Exception {
    assumeFalse(SystemUtils.IS_OS_WINDOWS);
    // BEFORE
    String pipelineScript = "def xsh(cmd) {if (isUnix()) {sh cmd} else {bat cmd}};\n" + "node() {\n" + "    stage('ze-stage1') {\n" + "       xsh (label: 'shell-1', script: 'echo ze-echo-1') \n" + "    }\n" + "    stage('ze-stage2') {\n" + "       xsh (label: 'shell-2', script: 'echo ze-echo-2') \n" + "    }\n" + "}";
    final Node agent = jenkinsRule.createOnlineSlave();
    final String jobName = "test-simple-pipeline-" + jobNameSuffix.incrementAndGet();
    WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, jobName);
    pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
    WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
    String rootSpanName = JenkinsOtelSemanticAttributes.CI_PIPELINE_RUN_ROOT_SPAN_NAME_PREFIX + jobName;
    final Tree<SpanDataWrapper> spans = getGeneratedSpans();
    checkChainOfSpans(spans, "Phase: Start", rootSpanName);
    checkChainOfSpans(spans, JenkinsOtelSemanticAttributes.AGENT_ALLOCATION_UI, JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run", rootSpanName);
    checkChainOfSpans(spans, "shell-1", "Stage: ze-stage1", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run", rootSpanName);
    checkChainOfSpans(spans, "shell-2", "Stage: ze-stage2", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run", rootSpanName);
    checkChainOfSpans(spans, "Phase: Finalise", rootSpanName);
    MatcherAssert.assertThat(spans.cardinality(), CoreMatchers.is(10L));
    // WORKAROUND because we don't know how to force the IntervalMetricReader to collect metrics
    openTelemetrySdkProvider.getOpenTelemetrySdk().getSdkMeterProvider().forceFlush();
    Map<String, MetricData> exportedMetrics = InMemoryMetricExporterUtils.getLastExportedMetricByMetricName(InMemoryMetricExporterProvider.LAST_CREATED_INSTANCE.getFinishedMetricItems());
    dumpMetrics(exportedMetrics);
    MetricData runStartedCounterData = exportedMetrics.get(JenkinsSemanticMetrics.CI_PIPELINE_RUN_STARTED);
    MatcherAssert.assertThat(runStartedCounterData, CoreMatchers.notNullValue());
    // TODO TEST METRICS WITH PROPER RESET BETWEEN TESTS
    MatcherAssert.assertThat(runStartedCounterData.getType(), CoreMatchers.is(MetricDataType.LONG_SUM));
    Collection<LongPointData> metricPoints = runStartedCounterData.getLongSumData().getPoints();
// MatcherAssert.assertThat(Iterables.getLast(metricPoints).getValue(), CoreMatchers.is(1L));
// we dont test the metric CI_PIPELINE_RUN_COMPLETED because there is flakiness on it
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Node(hudson.model.Node) LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Test(org.junit.Test)

Example 8 with LongPointData

use of io.opentelemetry.sdk.metrics.data.LongPointData in project opentelemetry-java by open-telemetry.

the class SdkMeterProviderTest method removeAsyncInstrument.

@Test
void removeAsyncInstrument() {
    InMemoryMetricReader reader = InMemoryMetricReader.create();
    Meter meter = sdkMeterProviderBuilder.registerMetricReader(reader).build().get(getClass().getName());
    ObservableLongCounter observableCounter1 = meter.counterBuilder("foo").buildWithCallback(measurement -> measurement.record(10, Attributes.builder().put("callback", "one").build()));
    ObservableLongCounter observableCounter2 = meter.counterBuilder("foo").buildWithCallback(measurement -> measurement.record(10, Attributes.builder().put("callback", "two").build()));
    assertThat(reader.collectAllMetrics()).hasSize(1).satisfiesExactly(metricData -> assertThat(metricData).hasLongSum().points().hasSize(2).satisfiesExactlyInAnyOrder(pointData -> assertThat(pointData).hasAttributes(Attributes.builder().put("callback", "one").build()), (Consumer<LongPointData>) longPointData -> assertThat(longPointData).hasAttributes(Attributes.builder().put("callback", "two").build())));
    observableCounter1.close();
    assertThat(reader.collectAllMetrics()).hasSize(1).satisfiesExactly(metricData -> assertThat(metricData).hasLongSum().points().hasSize(1).satisfiesExactlyInAnyOrder((Consumer<LongPointData>) longPointData -> assertThat(longPointData).hasAttributes(Attributes.builder().put("callback", "two").build())));
    observableCounter2.close();
    assertThat(reader.collectAllMetrics()).hasSize(0);
}
Also used : LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) Resource(io.opentelemetry.sdk.resources.Resource) Mock(org.mockito.Mock) Attributes(io.opentelemetry.api.common.Attributes) Aggregation(io.opentelemetry.sdk.metrics.view.Aggregation) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) ViewBuilderImpl(io.opentelemetry.sdk.metrics.internal.view.ViewBuilderImpl) MetricReader(io.opentelemetry.sdk.metrics.export.MetricReader) View(io.opentelemetry.sdk.metrics.view.View) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) LongUpDownCounter(io.opentelemetry.api.metrics.LongUpDownCounter) ObservableLongCounter(io.opentelemetry.api.metrics.ObservableLongCounter) LongCounter(io.opentelemetry.api.metrics.LongCounter) Context(io.opentelemetry.context.Context) DoubleUpDownCounter(io.opentelemetry.api.metrics.DoubleUpDownCounter) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Scope(io.opentelemetry.context.Scope) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) Mockito.when(org.mockito.Mockito.when) InstrumentType(io.opentelemetry.sdk.metrics.common.InstrumentType) InstrumentSelector(io.opentelemetry.sdk.metrics.view.InstrumentSelector) Assertions.entry(org.assertj.core.api.Assertions.entry) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Baggage(io.opentelemetry.api.baggage.Baggage) DoubleCounter(io.opentelemetry.api.metrics.DoubleCounter) AttributeKey(io.opentelemetry.api.common.AttributeKey) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Consumer(java.util.function.Consumer) Meter(io.opentelemetry.api.metrics.Meter) ObservableLongCounter(io.opentelemetry.api.metrics.ObservableLongCounter) Test(org.junit.jupiter.api.Test)

Example 9 with LongPointData

use of io.opentelemetry.sdk.metrics.data.LongPointData in project opentelemetry-java by open-telemetry.

the class MetricAdapter method convertLongPoints.

static Collection<LongPointData> convertLongPoints(Metric censusMetric) {
    // TODO - preallocate array to correct size.
    List<LongPointData> result = new ArrayList<>();
    for (TimeSeries ts : censusMetric.getTimeSeriesList()) {
        long startTimestamp = mapTimestamp(ts.getStartTimestamp());
        Attributes attributes = mapAttributes(censusMetric.getMetricDescriptor().getLabelKeys(), ts.getLabelValues());
        for (Point point : ts.getPoints()) {
            result.add(ImmutableLongPointData.create(startTimestamp, mapTimestamp(point.getTimestamp()), attributes, longValue(point)));
        }
    }
    return result;
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) ImmutableLongPointData(io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData) ArrayList(java.util.ArrayList) Attributes(io.opentelemetry.api.common.Attributes) Point(io.opencensus.metrics.export.Point)

Aggregations

LongPointData (io.opentelemetry.sdk.metrics.data.LongPointData)9 DoublePointData (io.opentelemetry.sdk.metrics.data.DoublePointData)4 MetricData (io.opentelemetry.sdk.metrics.data.MetricData)4 Attributes (io.opentelemetry.api.common.Attributes)3 HistogramPointData (io.opentelemetry.sdk.metrics.data.HistogramPointData)2 PointData (io.opentelemetry.sdk.metrics.data.PointData)2 SummaryPointData (io.opentelemetry.sdk.metrics.data.SummaryPointData)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Node (hudson.model.Node)1 Point (io.opencensus.metrics.export.Point)1 TimeSeries (io.opencensus.metrics.export.TimeSeries)1 Baggage (io.opentelemetry.api.baggage.Baggage)1 AttributeKey (io.opentelemetry.api.common.AttributeKey)1 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)1 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)1 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)1 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)1 LongCounter (io.opentelemetry.api.metrics.LongCounter)1 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)1