use of io.opencensus.proto.agent.metrics.v1.ExportMetricsServiceRequest in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsExporterIntegrationTest method testExportMetrics.
@Test
public void testExportMetrics() throws InterruptedException, IOException {
// Mock a real-life scenario in production, where Agent is not enabled at first, then enabled
// after an outage. Users should be able to see metrics shortly after Agent is up.
registerAllViews();
LongGauge gauge = registerGauge();
// Register the OcAgent Exporter first.
// Agent is not yet up and running so Exporter will just retry connection.
OcAgentMetricsExporter.createAndRegister(OcAgentMetricsExporterConfiguration.builder().setServiceName(SERVICE_NAME).setUseInsecure(true).setRetryInterval(RETRY_INTERVAL).setExportInterval(EXPORT_INTERVAL).build());
doWork(5, gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("First work"))));
// Wait 3s so that all metrics get exported.
Thread.sleep(3000);
// No interaction with Agent so far.
assertThat(fakeOcAgentMetricsServiceGrpc.getExportMetricsServiceRequests()).isEmpty();
// Imagine that an outage happened, now start Agent. Exporter should be able to connect to Agent
// after the next retry interval.
agent.start();
// Wait 3s for Exporter to start another attempt to connect to Agent.
Thread.sleep(3000);
doWork(8, gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("Second work"))));
// Wait 3s so that all metrics get exported.
Thread.sleep(3000);
List<ExportMetricsServiceRequest> exportRequests = fakeOcAgentMetricsServiceGrpc.getExportMetricsServiceRequests();
assertThat(exportRequests.size()).isAtLeast(2);
ExportMetricsServiceRequest firstRequest = exportRequests.get(0);
Node expectedNode = OcAgentNodeUtils.getNodeInfo(SERVICE_NAME);
Node actualNode = firstRequest.getNode();
assertThat(actualNode.getIdentifier().getHostName()).isEqualTo(expectedNode.getIdentifier().getHostName());
assertThat(actualNode.getIdentifier().getPid()).isEqualTo(expectedNode.getIdentifier().getPid());
assertThat(actualNode.getLibraryInfo()).isEqualTo(expectedNode.getLibraryInfo());
assertThat(actualNode.getServiceInfo()).isEqualTo(expectedNode.getServiceInfo());
List<Metric> metricProtos = new ArrayList<>();
for (int i = 1; i < exportRequests.size(); i++) {
metricProtos.addAll(exportRequests.get(i).getMetricsList());
}
// There should be at least one metric exported for each view and gauge (4 + 1).
assertThat(metricProtos.size()).isAtLeast(5);
Set<String> expectedMetrics = new HashSet<>();
expectedMetrics.add("jobs");
for (View view : VIEWS) {
expectedMetrics.add(view.getName().asString());
}
Set<String> actualMetrics = new HashSet<>();
for (Metric metricProto : metricProtos) {
actualMetrics.add(metricProto.getMetricDescriptor().getName());
}
assertThat(actualMetrics).containsAtLeastElementsIn(expectedMetrics);
}
use of io.opencensus.proto.agent.metrics.v1.ExportMetricsServiceRequest in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsServiceExportRpcHandlerTest method export_createAndExport.
@Test
public void export_createAndExport() {
OcAgentMetricsServiceExportRpcHandler exportRpcHandler = OcAgentMetricsServiceExportRpcHandler.create(getStub(serverName));
ExportMetricsServiceRequest request = ExportMetricsServiceRequest.newBuilder().setNode(NODE).build();
exportRpcHandler.onExport(request);
assertThat(traceServiceGrpc.getExportMetricsServiceRequests()).containsExactly(request);
}
Aggregations