コード例 #1
0
        public void Request_timestamp_is_set_on_request_start()
        {
            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);
            _httpContext.GetRequestDuration().ShouldNotBe(TimeSpan.Zero);
        }
コード例 #2
0
        public void Sli_exceptions_set_sli_error()
        {
            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnUnhandledException(_httpContext, new SliException(ErrorType.InternalDependency, "dep"));

            _httpContext.HasError(out var error).ShouldBeTrue();
            error.ShouldNotBeNull();
            error.Value.Item1.ShouldBe(ErrorType.InternalDependency);
            error.Value.Item2.ShouldBe("dep");
        }
コード例 #3
0
        public void Can_configure_request_duration_histogram()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationHistogram = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
コード例 #4
0
        public void Can_configure_requests_in_progress_gauge()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestsInProgressGauge = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
コード例 #5
0
        public void Can_configure_error_total_counter()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureErrorTotalCounter = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
コード例 #6
0
        public void With_prometheus_metrics()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), new PrometheusMetrics());

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnEndpointMatched(_httpContext);
            _httpContext.Response.StatusCode = 200;
            observer.OnHttpRequestCompleted(_httpContext);
        }
コード例 #7
0
        public void Can_configure_request_duration_summary()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationSummary = config => invoked = true,
                RequestDurationMetricType       = ObserverMetricType.Summary
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
コード例 #8
0
        public void Sli_errors_increment_counter()
        {
            _httpContext.SetSliError(ErrorType.InternalDependency, "client-service");
            _httpContext.SetOperation("error-op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnHttpRequestCompleted(_httpContext);

            var metric = _metrics.GetMetric <ICounter>("http_server_errors_total");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("error-op", "internal_dependency", "client-service"), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);
        }
コード例 #9
0
        public void Server_errors_increment_error_counter()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnEndpointMatched(_httpContext);
            _httpContext.Response.StatusCode = 504;
            observer.OnHttpRequestCompleted(_httpContext);

            var metric = _metrics.GetMetric <ICounter>("http_server_errors_total");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("op", "internal", String.Empty), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);
        }
コード例 #10
0
        public void Can_track_requests()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);

            observer.OnEndpointMatched(_httpContext);

            var metric = _metrics.GetMetric <IGauge>("http_server_requests_in_progress");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("op"), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);

            _httpContext.Response.StatusCode = 200;
            observer.OnHttpRequestCompleted(_httpContext);
        }