|
1 |
| -import { TelemetryMetricConfiguration, TelemetryConfiguration, TelemetryMetricConfig } from "../../telemetry/configuration"; |
| 1 | +import { TelemetryConfiguration, TelemetryMetricConfig } from "../../telemetry/configuration"; |
2 | 2 | import { TelemetryAttribute } from "../../telemetry/attributes";
|
3 | 3 | import { TelemetryMetric } from "../../telemetry/metrics";
|
4 | 4 |
|
5 |
| -describe("TelemetryMetricConfiguration", () => { |
6 |
| - test("should create a default TelemetryMetricConfiguration instance", () => { |
7 |
| - const config = new TelemetryMetricConfiguration(); |
8 |
| - |
9 |
| - expect(config.attributes.has(TelemetryAttribute.HttpHost)); |
10 |
| - expect(config.attributes.has(TelemetryAttribute.HttpResponseStatusCode)); |
11 |
| - expect(config.attributes.has(TelemetryAttribute.UserAgentOriginal)); |
12 |
| - expect(config.attributes.has(TelemetryAttribute.HttpRequestMethod)); |
13 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientRequestMethod)); |
14 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientRequestClientId)); |
15 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientRequestStoreId)); |
16 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientRequestModelId)); |
17 |
| - expect(config.attributes.has(TelemetryAttribute.HttpRequestResendCount)); |
18 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientResponseModelId)); |
19 |
| - |
20 |
| - // should not be there |
21 |
| - expect(config.attributes.has(TelemetryAttribute.UrlScheme)).toBe(false); |
22 |
| - expect(config.attributes.has(TelemetryAttribute.HttpRequestMethod)).toBe(false); |
23 |
| - expect(config.attributes.has(TelemetryAttribute.UrlFull)).toBe(false); |
24 |
| - expect(config.attributes.has(TelemetryAttribute.FgaClientUser)).toBe(false); |
25 |
| - }); |
26 |
| - |
27 |
| - test("should return correct attributes based on enabled properties", () => { |
28 |
| - const config = new TelemetryMetricConfiguration( |
29 |
| - new Set<TelemetryAttribute>([ |
30 |
| - TelemetryAttribute.FgaClientRequestClientId, |
31 |
| - TelemetryAttribute.HttpResponseStatusCode, |
32 |
| - TelemetryAttribute.UrlScheme, |
33 |
| - TelemetryAttribute.HttpRequestMethod, |
34 |
| - ]) |
35 |
| - ); |
36 |
| - |
37 |
| - const attributes = config.attributes; |
38 |
| - |
39 |
| - expect(attributes.size).toBe(4); |
40 |
| - expect(attributes.has(TelemetryAttribute.FgaClientRequestClientId)); |
41 |
| - expect(attributes.has(TelemetryAttribute.HttpResponseStatusCode)); |
42 |
| - expect(attributes.has(TelemetryAttribute.UrlScheme)); |
43 |
| - expect(attributes.has(TelemetryAttribute.HttpRequestMethod)); |
44 |
| - }); |
45 |
| -}); |
46 |
| - |
47 | 5 | describe("TelemetryConfiguration", () => {
|
48 |
| - test("should create a default TelemetryConfiguration instance", () => { |
49 |
| - const config = new TelemetryConfiguration(); |
50 |
| - |
51 |
| - const counters = config.metrics.counterCredentialsRequest; |
52 |
| - expect(counters).toBeInstanceOf(TelemetryMetricConfiguration); |
53 |
| - expect(counters?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
54 |
| - |
55 |
| - const histogramQueryDuration = config.metrics.histogramQueryDuration; |
56 |
| - expect(histogramQueryDuration).toBeInstanceOf(TelemetryMetricConfiguration); |
57 |
| - expect(histogramQueryDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
58 |
| - |
59 |
| - const histogramRequestDuration = config.metrics.histogramRequestDuration; |
60 |
| - expect(counters).toBeInstanceOf(TelemetryMetricConfiguration); |
61 |
| - expect(counters?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
62 |
| - }); |
63 |
| - |
64 | 6 | test("should use defaults if not all metrics defined", () => {
|
65 | 7 | const config = new TelemetryConfiguration({
|
66 |
| - [TelemetryMetric.CounterCredentialsRequest]: new TelemetryMetricConfiguration(), |
67 |
| - [TelemetryMetric.HistogramQueryDuration]: new TelemetryMetricConfiguration( |
68 |
| - new Set<TelemetryAttribute>([ |
| 8 | + [TelemetryMetric.CounterCredentialsRequest]: {}, |
| 9 | + [TelemetryMetric.HistogramQueryDuration]: { |
| 10 | + attributes: new Set<TelemetryAttribute>([ |
69 | 11 | TelemetryAttribute.FgaClientRequestClientId,
|
70 | 12 | TelemetryAttribute.HttpResponseStatusCode,
|
71 | 13 | TelemetryAttribute.UrlScheme,
|
72 | 14 | TelemetryAttribute.HttpRequestMethod,
|
73 | 15 | ])
|
74 |
| - ), |
| 16 | + } |
75 | 17 | });
|
76 | 18 |
|
77 |
| - expect(config.metrics.counterCredentialsRequest?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
78 |
| - expect(config.metrics.histogramQueryDuration?.attributes).toEqual(new Set<TelemetryAttribute>( |
| 19 | + expect(config.metrics?.counterCredentialsRequest?.attributes).toEqual(undefined); |
| 20 | + expect(config.metrics?.histogramQueryDuration?.attributes).toEqual(new Set<TelemetryAttribute>( |
79 | 21 | new Set<TelemetryAttribute>([
|
80 | 22 | TelemetryAttribute.FgaClientRequestClientId,
|
81 | 23 | TelemetryAttribute.HttpResponseStatusCode,
|
82 | 24 | TelemetryAttribute.UrlScheme,
|
83 | 25 | TelemetryAttribute.HttpRequestMethod,
|
84 | 26 | ])));
|
85 |
| - expect(config.metrics.histogramRequestDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
| 27 | + expect(config.metrics?.histogramRequestDuration?.attributes).toEqual(undefined); |
86 | 28 | });
|
| 29 | + |
| 30 | + test("should use defaults", () => { |
| 31 | + const config = new TelemetryConfiguration(); |
| 32 | + |
| 33 | + expect(config.metrics?.counterCredentialsRequest?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
| 34 | + expect(config.metrics?.histogramQueryDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
| 35 | + expect(config.metrics?.histogramRequestDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); |
| 36 | + }); |
| 37 | + |
| 38 | + test("should be undefined if empty object passed", () => { |
| 39 | + const config = new TelemetryConfiguration({}); |
| 40 | + |
| 41 | + expect(config.metrics?.counterCredentialsRequest?.attributes).toEqual(undefined); |
| 42 | + expect(config.metrics?.histogramQueryDuration?.attributes).toEqual(undefined); |
| 43 | + expect(config.metrics?.histogramRequestDuration?.attributes).toEqual(undefined); |
| 44 | + }); |
87 | 45 | });
|
0 commit comments