Skip to content

Commit 0d31d69

Browse files
Merge pull request #96 from alanconway/korrel8r-trace-fixes
fix: trace fixes for troubleshooting panel
2 parents 1b2d594 + 7592bb9 commit 0d31d69

5 files changed

Lines changed: 51 additions & 34 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.PHONY: test
2+
test: test-frontend
3+
14
.PHONY: test-frontend
25
test-frontend: lint-frontend
36
cd web && npm run test:unit

web/src/__tests__/node-factory.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ const testdata = [
3535
},
3636
{
3737
url:
38-
`observe/traces?name=platform&namespace=openshift-tracing&tenant=platform&` +
39-
`q=${encodeURIComponent('{resource.service.name = "article-service"}')}`,
40-
query: `trace:trace:{resource.service.name = "article-service"}`,
38+
`observe/traces/1599dfd76bc896101a9811857ae3c3c9?` +
39+
`namespace=openshift-tracing&name=platform&tenant=platform`,
40+
query: `trace:span:{trace:id="1599dfd76bc896101a9811857ae3c3c9"}`,
4141
},
4242
{
4343
url: `monitoring/logs?q=${encodeURIComponent(
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
import { TraceNode } from '../korrel8r/trace';
22

3+
const tempo = 'namespace=openshift-tracing&name=platform&tenant=platform';
4+
35
const roundtrip = [
46
{
5-
url:
6-
`observe/traces?name=platform&namespace=openshift-tracing&tenant=platform&` +
7-
`q=${encodeURIComponent('{resource.service.name = "article-service"}')}`,
8-
query: `trace:trace:{resource.service.name = "article-service"}`,
7+
url: `observe/traces?${tempo}`,
8+
query: `trace:span:{}`,
9+
},
10+
{
11+
url: `observe/traces?${tempo}&q=%7Bresource.service.name%3D%22article-service%22%7D`,
12+
query: `trace:span:{resource.service.name="article-service"}`,
13+
},
14+
{
15+
url: `observe/traces/1599dfd76bc896101a9811857ae3c3c9?${tempo}`,
16+
query: `trace:span:{trace:id="1599dfd76bc896101a9811857ae3c3c9"}`,
917
},
1018
];
1119

1220
describe('TraceNode.fromURL', () => {
13-
it.each(roundtrip)('$url', ({ url, query }) =>
14-
expect(TraceNode.fromURL(url)?.toQuery()).toEqual(query),
15-
);
21+
it.each([
22+
...roundtrip,
23+
{
24+
url: `observe/traces`,
25+
query: `trace:span:{}`,
26+
},
27+
])('$url', ({ url, query }) => expect(TraceNode.fromURL(url)?.toQuery()).toEqual(query));
1628
});
1729

1830
describe('TraceNode.fromQuery', () => {
19-
it.each(roundtrip)('$query', ({ query, url }) =>
20-
expect(TraceNode.fromQuery(query)?.toURL()).toEqual(url),
21-
);
22-
23-
it('Query => URL => Query', () => {
24-
const query = 'trace:trace:{resource.service.name="shop-backend"}';
25-
const expectedKorrel8rURL =
26-
'observe/traces?name=platform&namespace=openshift-tracing&tenant=platform&' +
27-
'q=%7Bresource.service.name%3D%22shop-backend%22%7D';
28-
const actualKorrel8rURL = TraceNode.fromQuery(query)?.toURL();
29-
expect(actualKorrel8rURL).toEqual(expectedKorrel8rURL);
30-
expect(TraceNode.fromURL(actualKorrel8rURL)?.toQuery()).toEqual(query);
31+
it.each([
32+
...roundtrip,
33+
{
34+
query: `trace:span:{resource.service.name="shop-backend"}`,
35+
url: `observe/traces?${tempo}&q=%7Bresource.service.name%3D%22shop-backend%22%7D`,
36+
},
37+
])('$query', ({ query, url }) => {
38+
expect(TraceNode.fromQuery(query).toURL()).toEqual(url);
3139
});
3240
});

web/src/korrel8r/trace.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Korrel8rNode } from './korrel8r.types';
22
import { parseQuery, parseURL } from './query-url';
33

4-
// URL format:
5-
// `observe/traces?namespace=<tempoNamespace>&name=<tempoName>&tenant=<tempoTenant>&q=<traceQL>`
4+
// URL formats:
5+
// Get all spans in a single trace:
6+
// observe/traces/<trace-id>
7+
// Search for get selected spans
8+
// observe/traces/?namespace=<tempoNamespace>&name=<tempoName>&tenant=<tempoTenant>&q=<traceQL>
69

7-
// FIXME hard-coded tempo location, need to make this configurable between console & korrel8r.
10+
// TODO hard-coded tempo location, need to make this configurable between console & korrel8r.
811
// Get from the console page environment (change from using URL as context?)
912
const [tempoNamespace, tempoName, tempoTenant] = ['openshift-tracing', 'platform', 'platform'];
1013

@@ -19,18 +22,20 @@ export class TraceNode extends Korrel8rNode {
1922
}
2023

2124
static fromURL(url: string): Korrel8rNode {
22-
const [, params] = parseURL('trace', 'observe/traces', url);
23-
const traceQL = params.get('q');
24-
// FIXME need to handle store location params also.
25-
return new TraceNode(url, `trace:trace:${traceQL}`);
25+
const [urlPath, params] = parseURL('trace', 'observe/traces', url);
26+
const traceID = urlPath.match(/observe\/traces\/([0-9a-fA-F]{32})(\/.*)?$/)?.[1];
27+
const traceQL = traceID ? `{trace:id="${traceID}"}` : params.get('q') || '{}';
28+
return new TraceNode(url, `trace:span:${traceQL}`);
2629
}
2730

2831
static fromQuery(query: string): Korrel8rNode {
29-
const [, traceQL] = parseQuery('trace', query);
30-
// FIME get variable tempo address info from query or config...
32+
const traceQL = parseQuery('trace', query)?.[1] || '';
33+
const traceID = traceQL.match(/\{ *trace:id *= *"([0-9a-fA-F]{32})" *\}/)?.[1] || '';
34+
const q = traceID || traceQL.match(/\{ *\}/) ? '' : `&q=${encodeURIComponent(traceQL)}`;
3135
return new TraceNode(
32-
`observe/traces?name=${tempoName}&namespace=${tempoNamespace}&tenant=${tempoTenant}&` +
33-
`q=${encodeURIComponent(traceQL)}`,
36+
`observe/traces${
37+
traceID && `/${traceID}`
38+
}?namespace=${tempoNamespace}&name=${tempoName}&tenant=${tempoTenant}${q}`,
3439
query,
3540
);
3641
}

web/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"allowJs": true,
99
"strict": false,
1010
"noUnusedLocals": true,
11-
"sourceMap": true
11+
"sourceMap": true,
12+
"plugins": [{ "name": "typescript-eslint-language-service" }]
1213
},
1314
"include": [
1415
"src"

0 commit comments

Comments
 (0)