Skip to content

Commit

Permalink
Add test case for use with CreateServiceTimeSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Apr 1, 2024
1 parent 3490b46 commit 7802ca6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public class FakeData {
ImmutableSumData.create(
true, AggregationTemporality.CUMULATIVE, ImmutableList.of(aLongPoint)));

static final MetricData googleComputeServiceMetricData =
ImmutableMetricData.createLongSum(
aGceResource,
anInstrumentationLibraryInfo,
"guest/disk/io_time",
"description",
"ns",
ImmutableSumData.create(
true, AggregationTemporality.CUMULATIVE, ImmutableList.of(aLongPoint)));

static final String aTraceId = "00000000000000000000000000000001";
static final String aSpanId = "0000000000000002";
static final SpanContext aSpanContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static com.google.cloud.opentelemetry.metric.FakeData.aSpanId;
import static com.google.cloud.opentelemetry.metric.FakeData.aTraceId;
import static com.google.cloud.opentelemetry.metric.FakeData.anInstrumentationLibraryInfo;
import static com.google.cloud.opentelemetry.metric.FakeData.googleComputeServiceMetricData;
import static com.google.cloud.opentelemetry.metric.MetricConfiguration.DEFAULT_PREFIX;
import static com.google.cloud.opentelemetry.metric.MetricConfiguration.DEFAULT_RESOURCE_ATTRIBUTES_FILTER;
import static com.google.cloud.opentelemetry.metric.MetricConfiguration.NO_RESOURCE_ATTRIBUTES;
Expand Down Expand Up @@ -456,6 +457,26 @@ public void verifyExporterCreationErrorDoesNotBreakMetricExporter() {
}
}

@Test
public void verifyExporterExportGoogleServiceMetrics() {
MetricExporter exporter =
InternalMetricExporter.createWithClient(
aProjectId,
"compute.googleapis.com",
mockClient,
MetricDescriptorStrategy.ALWAYS_SEND,
NO_RESOURCE_ATTRIBUTES,
true);

CompletableResultCode result =
exporter.export(ImmutableList.of(googleComputeServiceMetricData));
verify(mockClient, times(0)).createMetricDescriptor(any());
verify(mockClient, times(0)).createTimeSeries(any(ProjectName.class), any());
verify(mockClient, times(1)).createServiceTimeSeries(any(ProjectName.class), any());

assertTrue(result.isSuccess());
}

private void generateOpenTelemetryUsingGoogleCloudMetricExporter(MetricExporter metricExporter) {
SdkMeterProvider meterProvider =
SdkMeterProvider.builder()
Expand Down

0 comments on commit 7802ca6

Please sign in to comment.