public async void HandlePrometheusRequestAsync_ReturnsExpected() { var opts = new PrometheusEndpointOptions(); var mopts = TestHelper.GetManagementOptions(opts); var exporter = new PrometheusExporter(); var processor = new SteeltoeProcessor(exporter); var factory = AutoCollectingMeterFactory.Create(processor); var meter = factory.GetMeter("Test"); SetupTestView(meter); factory.CollectAllMetrics(); processor.ExportMetrics(); Task.Delay(1000).Wait(); var ep = new PrometheusScraperEndpoint(opts, exporter); var middle = new PrometheusScraperEndpointMiddleware(null, ep, mopts); var context = CreateRequest("GET", "/actuator/prometheus"); await middle.HandleMetricsRequestAsync(context); context.Response.Body.Seek(0, SeekOrigin.Begin); var rdr = new StreamReader(context.Response.Body); var text = await rdr.ReadToEndAsync(); Assert.Equal("# HELP test Testtest\n# TYPE test counter\ntest{a=\"v1\",b=\"v1\",c=\"v1\"} 45\n", text); }
public async Task MultipleExportersTestAsync() { var opts = new PrometheusEndpointOptions(); var mopts = new ActuatorManagementOptions(); mopts.EndpointOptions.Add(opts); var exporter1 = new PrometheusExporter(); var exporter2 = new SteeltoeExporter(); var multiExporter = new MultiExporter(new MetricExporter[] { exporter1, exporter2 }.ToList()); var processor = new SteeltoeProcessor(multiExporter); var factory = AutoCollectingMeterFactory.Create(processor); var meter = factory.GetMeter("Test"); SetupTestView(meter); factory.CollectAllMetrics(); processor.ExportMetrics(); Task.Delay(1000).Wait(); var ep = new PrometheusScraperEndpoint(opts, exporter1); var middle = new PrometheusScraperEndpointMiddleware(null, ep, mopts); var context = CreateRequest("GET", "/actuator/prometheus"); await middle.HandleMetricsRequestAsync(context); context.Response.Body.Seek(0, SeekOrigin.Begin); var rdr = new StreamReader(context.Response.Body); var text = await rdr.ReadToEndAsync(); Assert.Equal("# HELP test Testtest\n# TYPE test counter\ntest{a=\"v1\",b=\"v1\",c=\"v1\"} 45\n", text); var meopts = new MetricsEndpointOptions(); var ep2 = new MetricsEndpoint(meopts, exporter2); var middle2 = new MetricsEndpointMiddleware(null, ep2, mopts); var context2 = CreateRequest("GET", "/actuator/metrics/test", "?tag=a:v1"); await middle2.HandleMetricsRequestAsync(context2); Assert.Equal(200, context.Response.StatusCode); context2.Response.Body.Seek(0, SeekOrigin.Begin); StreamReader rdr2 = new StreamReader(context2.Response.Body); string json = await rdr2.ReadToEndAsync(); Assert.Equal("{\"name\":\"test\",\"measurements\":[{\"statistic\":\"COUNT\",\"value\":45}],\"availableTags\":[{\"tag\":\"a\",\"values\":[\"v1\"]},{\"tag\":\"b\",\"values\":[\"v1\"]},{\"tag\":\"c\",\"values\":[\"v1\"]}]}", json); }