/// <inheritdoc /> public void Configure(MetricEndpointsOptions options) { options.MetricsOutputFormatters = _metricsFormatters; if (options.MetricsTextEndpointOutputFormatter == null) { options.MetricsTextEndpointOutputFormatter = _metricsFormatters.GetType <MetricsTextOutputFormatter>() ?? _metricsFormatters.LastOrDefault(); } if (options.MetricsEndpointOutputFormatter == null) { options.MetricsEndpointOutputFormatter = _metricsFormatters.GetType <MetricsJsonOutputFormatter>() ?? _metricsFormatters.LastOrDefault(); } if (options.EnvInfoEndpointOutputFormatter == null) { options.EnvInfoEndpointOutputFormatter = _envFormatters.GetType <EnvInfoTextOutputFormatter>() ?? _envFormatters.LastOrDefault(); } }
public void Can_get_formatter_by_type() { // Arrange var formatters = new MetricsFormatterCollection(); formatters.TryAdd(new MetricsJsonOutputFormatter()); formatters.TryAdd(new MetricsTextOutputFormatter()); // Act var result = formatters.GetType <MetricsTextOutputFormatter>(); // Assert result.Should().BeOfType(typeof(MetricsTextOutputFormatter)); }
public void Can_get_formatter_by_media_type() { // Arrange var formatters = new MetricsFormatterCollection(); formatters.TryAdd(new MetricsJsonOutputFormatter()); formatters.TryAdd(new MetricsTextOutputFormatter()); var mediaType = new MetricsMediaTypeValue("text", "vnd.appmetrics.metrics", "v1", "plain"); // Act var result = formatters.GetType(mediaType); // Assert result.Should().BeOfType(typeof(MetricsTextOutputFormatter)); }
/// <inheritdoc /> public Task WriteAsync(HttpContext context, MetricsDataValueSource metricsData, CancellationToken token = default) { var formatter = _formatter ?? context.Request.GetTypedHeaders().ResolveFormatter( _fallbackFormatter, metricsMediaTypeValue => _formatters.GetType(metricsMediaTypeValue)); context.SetNoCacheHeaders(); if (formatter == default(IMetricsOutputFormatter)) { context.Response.StatusCode = StatusCodes.Status406NotAcceptable; context.Response.Headers[HeaderNames.ContentType] = new[] { context.Request.ContentType }; return(Task.CompletedTask); } context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.Headers[HeaderNames.ContentType] = new[] { formatter.MediaType.ContentType }; return(formatter.WriteAsync(context.Response.Body, metricsData, token)); }