@kopai/ui 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopai/ui",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Vladimir Adamic",
6
6
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "@tanstack/react-query": "^5",
34
34
  "@tanstack/react-virtual": "^3.13.22",
35
35
  "recharts": "^3.8.0",
36
- "@kopai/core": "0.8.0",
37
- "@kopai/sdk": "0.6.0"
36
+ "@kopai/core": "0.9.0",
37
+ "@kopai/sdk": "0.7.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^19.2.4",
@@ -17,6 +17,9 @@ function createMockClient(): MockClient {
17
17
  searchTracesPage: vi.fn().mockResolvedValue({ data: [] }),
18
18
  searchLogsPage: vi.fn().mockResolvedValue({ data: [] }),
19
19
  searchMetricsPage: vi.fn().mockResolvedValue({ data: [] }),
20
+ searchAggregatedMetrics: vi
21
+ .fn()
22
+ .mockResolvedValue({ data: [], nextCursor: null }),
20
23
  getTrace: vi.fn().mockResolvedValue({ data: [] }),
21
24
  discoverMetrics: vi.fn().mockResolvedValue({ data: [] }),
22
25
  searchTraces: vi.fn().mockResolvedValue({ data: [] }),
@@ -16,6 +16,10 @@ export interface ThresholdConfig {
16
16
 
17
17
  export interface MetricStatProps {
18
18
  rows: OtelMetricsRow[];
19
+ /** Pre-computed value (e.g. from aggregated queries). Bypasses row extraction when set. */
20
+ value?: number;
21
+ /** Unit string for formatting when using pre-computed value. */
22
+ unit?: string;
19
23
  isLoading?: boolean;
20
24
  error?: Error;
21
25
  label?: string;
@@ -140,6 +144,8 @@ function buildStatData(rows: OtelMetricsRow[]): {
140
144
 
141
145
  export function MetricStat({
142
146
  rows,
147
+ value: directValue,
148
+ unit: directUnit,
143
149
  isLoading = false,
144
150
  error,
145
151
  label,
@@ -155,10 +161,12 @@ export function MetricStat({
155
161
  colorBackground,
156
162
  colorValue = false,
157
163
  }: MetricStatProps) {
158
- const { latestValue, unit, timestamp, dataPoints, metricName } = useMemo(
159
- () => buildStatData(rows),
160
- [rows]
161
- );
164
+ const statData = useMemo(() => buildStatData(rows), [rows]);
165
+
166
+ // Pre-computed value (aggregated queries) bypasses row extraction
167
+ const latestValue = directValue ?? statData.latestValue;
168
+ const unit = directUnit ?? statData.unit;
169
+ const { timestamp, dataPoints, metricName } = statData;
162
170
 
163
171
  const sparklineData = useMemo(() => {
164
172
  if (!showSparkline || dataPoints.length === 0) return [];
@@ -5,11 +5,23 @@ import { formatOtelValue } from "../utils/units.js";
5
5
  import type { denormalizedSignals } from "@kopai/core";
6
6
 
7
7
  type OtelMetricsRow = denormalizedSignals.OtelMetricsRow;
8
+ type AggregatedMetricRow = denormalizedSignals.AggregatedMetricRow;
8
9
 
9
10
  type Props = RendererComponentProps<
10
11
  typeof observabilityCatalog.components.MetricStat
11
12
  >;
12
13
 
14
+ const EMPTY_ROWS: never[] = [];
15
+ const GROUPED_AGGREGATE_ERROR = new Error(
16
+ "MetricStat cannot display grouped aggregates. Remove groupBy or use MetricTable."
17
+ );
18
+
19
+ function isAggregatedRequest(props: Props & { hasData: true }): boolean {
20
+ const ds = props.element.dataSource;
21
+ if (!ds || ds.method !== "searchMetricsPage" || !ds.params) return false;
22
+ return !!ds.params.aggregate;
23
+ }
24
+
13
25
  export function OtelMetricStat(props: Props) {
14
26
  if (!props.hasData) {
15
27
  return (
@@ -17,6 +29,34 @@ export function OtelMetricStat(props: Props) {
17
29
  );
18
30
  }
19
31
 
32
+ if (isAggregatedRequest(props)) {
33
+ const response = props.data as { data: AggregatedMetricRow[] } | null;
34
+ const rows = response?.data ?? [];
35
+
36
+ if (rows.length > 1) {
37
+ return (
38
+ <MetricStat
39
+ rows={EMPTY_ROWS}
40
+ error={GROUPED_AGGREGATE_ERROR}
41
+ label={props.element.props.label ?? undefined}
42
+ formatValue={formatOtelValue}
43
+ />
44
+ );
45
+ }
46
+
47
+ return (
48
+ <MetricStat
49
+ rows={EMPTY_ROWS}
50
+ value={rows[0]?.value}
51
+ isLoading={props.loading}
52
+ error={props.error ?? undefined}
53
+ label={props.element.props.label ?? undefined}
54
+ showSparkline={false}
55
+ formatValue={formatOtelValue}
56
+ />
57
+ );
58
+ }
59
+
20
60
  const response = props.data as { data?: OtelMetricsRow[] } | null;
21
61
 
22
62
  return (
@@ -16,6 +16,7 @@ const createMockClient = () => ({
16
16
  searchTracesPage: vi.fn(),
17
17
  searchLogsPage: vi.fn(),
18
18
  searchMetricsPage: vi.fn(),
19
+ searchAggregatedMetrics: vi.fn(),
19
20
  getTrace: vi.fn(),
20
21
  discoverMetrics: vi.fn(),
21
22
  getDashboard: vi.fn(),
@@ -151,6 +152,36 @@ describe("useKopaiData", () => {
151
152
  expect(result.current.data).toEqual(mockData);
152
153
  expect(mockClient.searchMetricsPage).toHaveBeenCalled();
153
154
  });
155
+
156
+ it("routes to searchAggregatedMetrics when aggregate is set", async () => {
157
+ const mockData = {
158
+ data: [{ groups: { signal: "/v1/traces" }, value: 1024 }],
159
+ nextCursor: null,
160
+ };
161
+ mockClient.searchAggregatedMetrics.mockResolvedValue(mockData);
162
+
163
+ const dataSource: DataSource = {
164
+ method: "searchMetricsPage",
165
+ params: {
166
+ metricType: "Sum",
167
+ metricName: "kopai.ingestion.bytes",
168
+ aggregate: "sum",
169
+ groupBy: ["signal"],
170
+ },
171
+ };
172
+
173
+ const { result } = renderHook(() => useKopaiData(dataSource), {
174
+ wrapper: wrapper(mockClient),
175
+ });
176
+
177
+ await waitFor(() => {
178
+ expect(result.current.loading).toBe(false);
179
+ });
180
+
181
+ expect(result.current.data).toEqual(mockData);
182
+ expect(mockClient.searchAggregatedMetrics).toHaveBeenCalled();
183
+ expect(mockClient.searchMetricsPage).not.toHaveBeenCalled();
184
+ });
154
185
  });
155
186
 
156
187
  describe("getTrace", () => {
@@ -25,11 +25,18 @@ function fetchForDataSource(
25
25
  dataSource.params as Parameters<typeof client.searchLogsPage>[0],
26
26
  { signal }
27
27
  );
28
- case "searchMetricsPage":
29
- return client.searchMetricsPage(
30
- dataSource.params as Parameters<typeof client.searchMetricsPage>[0],
31
- { signal }
32
- );
28
+ case "searchMetricsPage": {
29
+ const params = dataSource.params as Parameters<
30
+ typeof client.searchMetricsPage
31
+ >[0];
32
+ if (params.aggregate) {
33
+ return client.searchAggregatedMetrics(
34
+ { ...params, aggregate: params.aggregate },
35
+ { signal }
36
+ );
37
+ }
38
+ return client.searchMetricsPage(params, { signal });
39
+ }
33
40
  case "getTrace":
34
41
  return client.getTrace(dataSource.params.traceId, { signal });
35
42
  case "discoverMetrics":
@@ -19,6 +19,7 @@ const createMockClient = () => ({
19
19
  searchTracesPage: vi.fn(),
20
20
  searchLogsPage: vi.fn(),
21
21
  searchMetricsPage: vi.fn(),
22
+ searchAggregatedMetrics: vi.fn(),
22
23
  getTrace: vi.fn(),
23
24
  discoverMetrics: vi.fn(),
24
25
  getDashboard: vi.fn(),
@@ -29,7 +29,7 @@ Accepts dataSource: yes
29
29
 
30
30
  ## Output Schema
31
31
 
32
- {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"root":{"type":"string","description":"root uiElement key in the elements array"},"elements":{"type":"object","propertyNames":{"type":"string","description":"equal to the element key"},"additionalProperties":{"oneOf":[{"type":"object","properties":{"key":{"type":"string"},"type":{"type":"string","const":"Card"},"children":{"type":"array","items":{"type":"string"}},"parentKey":{"type":"string"},"dataSource":{"$ref":"#/$defs/DataSource"},"props":{"type":"object","properties":{"title":{"type":"string"}},"required":["title"],"additionalProperties":false}},"required":["key","type","children","parentKey","props"],"additionalProperties":false},{"type":"object","properties":{"key":{"type":"string"},"type":{"type":"string","const":"Button"},"children":{"type":"array","items":{"type":"string"}},"parentKey":{"type":"string"},"dataSource":{"$ref":"#/$defs/DataSource"},"props":{"type":"object","properties":{"label":{"type":"string"}},"required":["label"],"additionalProperties":false}},"required":["key","type","children","parentKey","props"],"additionalProperties":false}]}}},"required":["root","elements"],"additionalProperties":false,"$defs":{"DataSource":{"$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"type":"object","properties":{"method":{"type":"string","const":"searchTracesPage"},"params":{"type":"object","properties":{"traceId":{"description":"Unique identifier for a trace. All spans from the same trace share the same trace_id. The ID is a 16-byte array.","type":"string"},"spanId":{"description":"Unique identifier for a span within a trace. The ID is an 8-byte array.","type":"string"},"parentSpanId":{"description":"The span_id of this span's parent span. Empty if this is a root span.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"spanName":{"description":"Description of the span's operation. E.g., qualified method name or file name with line number.","type":"string"},"spanKind":{"description":"Type of span (INTERNAL, SERVER, CLIENT, PRODUCER, CONSUMER). Used to identify relationships between spans.","type":"string"},"statusCode":{"description":"Status code (UNSET, OK, ERROR).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"timestampMin":{"description":"Minimum start time of the span. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"timestampMax":{"description":"Maximum start time of the span. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"durationMin":{"description":"Minimum duration of the span in nanoseconds (end_time - start_time). Expressed as string in JSON.","type":"string"},"durationMax":{"description":"Maximum duration of the span in nanoseconds (end_time - start_time). Expressed as string in JSON.","type":"string"},"spanAttributes":{"description":"Key/value pairs describing the span.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"eventsAttributes":{"description":"Attribute key/value pairs on the event.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"linksAttributes":{"description":"Attribute key/value pairs on the link.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchLogsPage"},"params":{"type":"object","properties":{"traceId":{"description":"Unique identifier for a trace. All logs from the same trace share the same trace_id. The ID is a 16-byte array.","type":"string"},"spanId":{"description":"Unique identifier for a span within a trace. The ID is an 8-byte array.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"severityText":{"description":"Severity text (also known as log level). Original string representation as known at the source.","type":"string"},"severityNumberMin":{"description":"Minimum severity number (inclusive). Normalized to values described in Log Data Model.","type":"number"},"severityNumberMax":{"description":"Maximum severity number (inclusive). Normalized to values described in Log Data Model.","type":"number"},"bodyContains":{"description":"Filter logs where body contains this substring.","type":"string"},"timestampMin":{"description":"Minimum time when the event occurred. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"timestampMax":{"description":"Maximum time when the event occurred. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"logAttributes":{"description":"Additional attributes that describe the specific event occurrence.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"scopeAttributes":{"description":"Attributes of the instrumentation scope.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchMetricsPage"},"params":{"type":"object","properties":{"metricType":{"type":"string","enum":["Gauge","Sum","Histogram","ExponentialHistogram","Summary"],"description":"Metric type to query."},"metricName":{"description":"The name of the metric.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"timeUnixMin":{"description":"Minimum time when the data point was recorded. UNIX Epoch time in nanoseconds. Expressed as string in JSON.","type":"string"},"timeUnixMax":{"description":"Maximum time when the data point was recorded. UNIX Epoch time in nanoseconds. Expressed as string in JSON.","type":"string"},"attributes":{"description":"Key/value pairs that uniquely identify the timeseries.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"scopeAttributes":{"description":"Attributes of the instrumentation scope.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"required":["metricType"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getTrace"},"params":{"type":"object","properties":{"traceId":{"type":"string"}},"required":["traceId"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"discoverMetrics"},"params":{"type":"object","properties":{},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getServices"},"params":{"type":"object","properties":{},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getOperations"},"params":{"type":"object","properties":{"serviceName":{"type":"string"}},"required":["serviceName"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchTraceSummariesPage"},"params":{"type":"object","properties":{"serviceName":{"type":"string"},"spanName":{"type":"string"},"timestampMin":{"type":"string"},"timestampMax":{"type":"string"},"durationMin":{"type":"string"},"durationMax":{"type":"string"},"spanAttributes":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"default":20,"type":"integer","minimum":1,"maximum":1000},"cursor":{"type":"string"},"sortOrder":{"default":"DESC","type":"string","enum":["ASC","DESC"]}},"required":["limit","sortOrder"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false}]}}}
32
+ {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"root":{"type":"string","description":"root uiElement key in the elements array"},"elements":{"type":"object","propertyNames":{"type":"string","description":"equal to the element key"},"additionalProperties":{"oneOf":[{"type":"object","properties":{"key":{"type":"string"},"type":{"type":"string","const":"Card"},"children":{"type":"array","items":{"type":"string"}},"parentKey":{"type":"string"},"dataSource":{"$ref":"#/$defs/DataSource"},"props":{"type":"object","properties":{"title":{"type":"string"}},"required":["title"],"additionalProperties":false}},"required":["key","type","children","parentKey","props"],"additionalProperties":false},{"type":"object","properties":{"key":{"type":"string"},"type":{"type":"string","const":"Button"},"children":{"type":"array","items":{"type":"string"}},"parentKey":{"type":"string"},"dataSource":{"$ref":"#/$defs/DataSource"},"props":{"type":"object","properties":{"label":{"type":"string"}},"required":["label"],"additionalProperties":false}},"required":["key","type","children","parentKey","props"],"additionalProperties":false}]}}},"required":["root","elements"],"additionalProperties":false,"$defs":{"DataSource":{"$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"type":"object","properties":{"method":{"type":"string","const":"searchTracesPage"},"params":{"type":"object","properties":{"traceId":{"description":"Unique identifier for a trace. All spans from the same trace share the same trace_id. The ID is a 16-byte array.","type":"string"},"spanId":{"description":"Unique identifier for a span within a trace. The ID is an 8-byte array.","type":"string"},"parentSpanId":{"description":"The span_id of this span's parent span. Empty if this is a root span.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"spanName":{"description":"Description of the span's operation. E.g., qualified method name or file name with line number.","type":"string"},"spanKind":{"description":"Type of span (INTERNAL, SERVER, CLIENT, PRODUCER, CONSUMER). Used to identify relationships between spans.","type":"string"},"statusCode":{"description":"Status code (UNSET, OK, ERROR).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"timestampMin":{"description":"Minimum start time of the span. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"timestampMax":{"description":"Maximum start time of the span. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"durationMin":{"description":"Minimum duration of the span in nanoseconds (end_time - start_time). Expressed as string in JSON.","type":"string"},"durationMax":{"description":"Maximum duration of the span in nanoseconds (end_time - start_time). Expressed as string in JSON.","type":"string"},"spanAttributes":{"description":"Key/value pairs describing the span.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"eventsAttributes":{"description":"Attribute key/value pairs on the event.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"linksAttributes":{"description":"Attribute key/value pairs on the link.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchLogsPage"},"params":{"type":"object","properties":{"traceId":{"description":"Unique identifier for a trace. All logs from the same trace share the same trace_id. The ID is a 16-byte array.","type":"string"},"spanId":{"description":"Unique identifier for a span within a trace. The ID is an 8-byte array.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"severityText":{"description":"Severity text (also known as log level). Original string representation as known at the source.","type":"string"},"severityNumberMin":{"description":"Minimum severity number (inclusive). Normalized to values described in Log Data Model.","type":"number"},"severityNumberMax":{"description":"Maximum severity number (inclusive). Normalized to values described in Log Data Model.","type":"number"},"bodyContains":{"description":"Filter logs where body contains this substring.","type":"string"},"timestampMin":{"description":"Minimum time when the event occurred. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"timestampMax":{"description":"Maximum time when the event occurred. UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. Expressed as string in JSON.","type":"string"},"logAttributes":{"description":"Additional attributes that describe the specific event occurrence.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"scopeAttributes":{"description":"Attributes of the instrumentation scope.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchMetricsPage"},"params":{"type":"object","properties":{"metricType":{"type":"string","enum":["Gauge","Sum","Histogram","ExponentialHistogram","Summary"],"description":"Metric type to query."},"metricName":{"description":"The name of the metric.","type":"string"},"serviceName":{"description":"Service name from resource attributes (service.name).","type":"string"},"scopeName":{"description":"Name denoting the instrumentation scope.","type":"string"},"timeUnixMin":{"description":"Minimum time when the data point was recorded. UNIX Epoch time in nanoseconds. Expressed as string in JSON.","type":"string"},"timeUnixMax":{"description":"Maximum time when the data point was recorded. UNIX Epoch time in nanoseconds. Expressed as string in JSON.","type":"string"},"attributes":{"description":"Key/value pairs that uniquely identify the timeseries.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"description":"Attributes that describe the resource.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"scopeAttributes":{"description":"Attributes of the instrumentation scope.","type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"aggregate":{"description":"Aggregation function to apply to metric values. When set, returns aggregated results instead of raw data points.","type":"string","enum":["sum","avg","min","max","count"]},"groupBy":{"description":"Attribute keys to group by when aggregating (e.g. ['tenant.id', 'signal']).","type":"array","items":{"type":"string"}},"limit":{"description":"Max items to return. Default determined by datasource.","type":"integer","exclusiveMinimum":0,"maximum":1000},"cursor":{"description":"Opaque cursor from previous response for next page.","type":"string"},"sortOrder":{"description":"Sort by timestamp. ASC = oldest first, DESC = newest first.","type":"string","enum":["ASC","DESC"]}},"required":["metricType"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getTrace"},"params":{"type":"object","properties":{"traceId":{"type":"string"}},"required":["traceId"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"discoverMetrics"},"params":{"type":"object","properties":{},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getServices"},"params":{"type":"object","properties":{},"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"getOperations"},"params":{"type":"object","properties":{"serviceName":{"type":"string"}},"required":["serviceName"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false},{"type":"object","properties":{"method":{"type":"string","const":"searchTraceSummariesPage"},"params":{"type":"object","properties":{"serviceName":{"type":"string"},"spanName":{"type":"string"},"timestampMin":{"type":"string"},"timestampMax":{"type":"string"},"durationMin":{"type":"string"},"durationMax":{"type":"string"},"spanAttributes":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"resourceAttributes":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},"limit":{"default":20,"type":"integer","minimum":1,"maximum":1000},"cursor":{"type":"string"},"sortOrder":{"default":"DESC","type":"string","enum":["ASC","DESC"]}},"required":["limit","sortOrder"],"additionalProperties":false},"refetchIntervalMs":{"type":"number"}},"required":["method","params"],"additionalProperties":false}]}}}
33
33
 
34
34
  ---
35
35
 
@@ -52,6 +52,7 @@ type MockClient = {
52
52
  searchTracesPage: ReturnType<typeof vi.fn>;
53
53
  searchLogsPage: ReturnType<typeof vi.fn>;
54
54
  searchMetricsPage: ReturnType<typeof vi.fn>;
55
+ searchAggregatedMetrics: ReturnType<typeof vi.fn>;
55
56
  getTrace: ReturnType<typeof vi.fn>;
56
57
  discoverMetrics: ReturnType<typeof vi.fn>;
57
58
  searchTraces: ReturnType<typeof vi.fn>;
@@ -281,6 +282,7 @@ describe("Renderer with dataSource", () => {
281
282
  searchTracesPage: vi.fn(),
282
283
  searchLogsPage: vi.fn(),
283
284
  searchMetricsPage: vi.fn(),
285
+ searchAggregatedMetrics: vi.fn(),
284
286
  getTrace: vi.fn(),
285
287
  discoverMetrics: vi.fn(),
286
288
  searchTraces: vi.fn(),
@@ -17,6 +17,9 @@ function createMockClient(): MockClient {
17
17
  searchTracesPage: vi.fn().mockResolvedValue({ data: [] }),
18
18
  searchLogsPage: vi.fn().mockResolvedValue({ data: [] }),
19
19
  searchMetricsPage: vi.fn().mockResolvedValue({ data: [] }),
20
+ searchAggregatedMetrics: vi
21
+ .fn()
22
+ .mockResolvedValue({ data: [], nextCursor: null }),
20
23
  getTrace: vi.fn().mockResolvedValue({ data: [] }),
21
24
  discoverMetrics: vi.fn().mockResolvedValue({ data: [] }),
22
25
  searchTraces: vi.fn().mockResolvedValue({ data: [] }),
@@ -743,7 +743,14 @@ const METRICS_TREE = {
743
743
  root: {
744
744
  key: "root",
745
745
  type: "Stack" as const,
746
- children: ["heading", "description", "discovery-card"],
746
+ children: [
747
+ "heading",
748
+ "ingestion-heading",
749
+ "ingestion-grid",
750
+ "discovery-heading",
751
+ "description",
752
+ "discovery-card",
753
+ ],
747
754
  parentKey: "",
748
755
  props: {
749
756
  direction: "vertical" as const,
@@ -758,6 +765,81 @@ const METRICS_TREE = {
758
765
  parentKey: "root",
759
766
  props: { text: "Metrics", level: "h2" as const },
760
767
  },
768
+ "ingestion-heading": {
769
+ key: "ingestion-heading",
770
+ type: "Heading" as const,
771
+ children: [],
772
+ parentKey: "root",
773
+ props: { text: "OTEL Ingestion", level: "h3" as const },
774
+ },
775
+ "ingestion-grid": {
776
+ key: "ingestion-grid",
777
+ type: "Grid" as const,
778
+ children: ["card-bytes", "card-requests"],
779
+ parentKey: "root",
780
+ props: { columns: 2, gap: "md" as const },
781
+ },
782
+ "card-bytes": {
783
+ key: "card-bytes",
784
+ type: "Card" as const,
785
+ children: ["stat-bytes"],
786
+ parentKey: "ingestion-grid",
787
+ props: {
788
+ title: "Total Bytes Ingested",
789
+ description: null,
790
+ padding: null,
791
+ },
792
+ },
793
+ "stat-bytes": {
794
+ key: "stat-bytes",
795
+ type: "MetricStat" as const,
796
+ children: [],
797
+ parentKey: "card-bytes",
798
+ dataSource: {
799
+ method: "searchMetricsPage" as const,
800
+ params: {
801
+ metricType: "Sum" as const,
802
+ metricName: "kopai.ingestion.bytes",
803
+ aggregate: "sum" as const,
804
+ },
805
+ refetchIntervalMs: 10_000,
806
+ },
807
+ props: { label: "Bytes", showSparkline: false },
808
+ },
809
+ "card-requests": {
810
+ key: "card-requests",
811
+ type: "Card" as const,
812
+ children: ["stat-requests"],
813
+ parentKey: "ingestion-grid",
814
+ props: {
815
+ title: "Total Requests",
816
+ description: null,
817
+ padding: null,
818
+ },
819
+ },
820
+ "stat-requests": {
821
+ key: "stat-requests",
822
+ type: "MetricStat" as const,
823
+ children: [],
824
+ parentKey: "card-requests",
825
+ dataSource: {
826
+ method: "searchMetricsPage" as const,
827
+ params: {
828
+ metricType: "Sum" as const,
829
+ metricName: "kopai.ingestion.requests",
830
+ aggregate: "sum" as const,
831
+ },
832
+ refetchIntervalMs: 10_000,
833
+ },
834
+ props: { label: "Requests", showSparkline: false },
835
+ },
836
+ "discovery-heading": {
837
+ key: "discovery-heading",
838
+ type: "Heading" as const,
839
+ children: [],
840
+ parentKey: "root",
841
+ props: { text: "Discovered Metrics", level: "h3" as const },
842
+ },
761
843
  description: {
762
844
  key: "description",
763
845
  type: "Text" as const,
@@ -7,6 +7,7 @@ export type KopaiClient = Pick<
7
7
  | "searchTracesPage"
8
8
  | "searchLogsPage"
9
9
  | "searchMetricsPage"
10
+ | "searchAggregatedMetrics"
10
11
  | "getTrace"
11
12
  | "discoverMetrics"
12
13
  | "getDashboard"