Elasticsearch: Fix creating of span link with no tags (#61753)

Elasticsearch: Fix create span link if no tags
This commit is contained in:
Ivana Huckova 2023-01-20 10:52:33 +01:00 committed by GitHub
parent 3b3059c9ce
commit 46722679b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 9 deletions

View File

@ -665,6 +665,34 @@ describe('createSpanLinkFactory', () => {
);
});
it('formats query correctly if only filterByTraceID is true', () => {
const createLink = setupSpanLinkFactory(
{
datasourceUid: searchUID,
filterByTraceID: true,
},
searchUID
);
expect(createLink).toBeDefined();
const links = createLink!(
createTraceSpan({
process: {
serviceName: 'service',
tags: [],
},
})
);
const linkDef = links?.logLinks?.[0];
expect(linkDef).toBeDefined();
expect(linkDef!.href).toBe(
`/explore?left=${encodeURIComponent(
`{"range":{"from":"2020-10-14T01:00:00.000Z","to":"2020-10-14T01:00:01.000Z"},"datasource":"searchUID","queries":[{"query":"\\"7946b05c2e2e4e5a\\"","refId":"","metrics":[{"id":"1","type":"logs"}]}],"panelsState":{}}`
)}`
);
});
it('should format one tag correctly', () => {
const createLink = setupSpanLinkFactory(
{

View File

@ -318,15 +318,19 @@ function getLinkForElasticsearchOrOpensearch(
return acc;
}, []);
let query = '';
if (tags.length > 0) {
query += `${tags.join(' AND ')}`;
}
if (filterByTraceID && span.traceID) {
query = `"${span.traceID}" AND ` + query;
}
let queryArr = [];
if (filterBySpanID && span.spanID) {
query = `"${span.spanID}" AND ` + query;
queryArr.push(`"${span.spanID}"`);
}
if (filterByTraceID && span.traceID) {
queryArr.push(`"${span.traceID}"`);
}
if (tags.length > 0) {
for (const tag of tags) {
queryArr.push(tag);
}
}
const dataLink: DataLink<ElasticsearchOrOpensearchQuery> = {
@ -336,7 +340,7 @@ function getLinkForElasticsearchOrOpensearch(
datasourceUid: dataSourceSettings.uid,
datasourceName: dataSourceSettings.name,
query: {
query: query,
query: queryArr.join(' AND '),
refId: '',
metrics: [
{