Elasticsearch: Fix creating of span link with no tags (#61753)
Elasticsearch: Fix create span link if no tags
This commit is contained in:
@@ -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', () => {
|
it('should format one tag correctly', () => {
|
||||||
const createLink = setupSpanLinkFactory(
|
const createLink = setupSpanLinkFactory(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -318,15 +318,19 @@ function getLinkForElasticsearchOrOpensearch(
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
let query = '';
|
let queryArr = [];
|
||||||
if (tags.length > 0) {
|
|
||||||
query += `${tags.join(' AND ')}`;
|
|
||||||
}
|
|
||||||
if (filterByTraceID && span.traceID) {
|
|
||||||
query = `"${span.traceID}" AND ` + query;
|
|
||||||
}
|
|
||||||
if (filterBySpanID && span.spanID) {
|
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> = {
|
const dataLink: DataLink<ElasticsearchOrOpensearchQuery> = {
|
||||||
@@ -336,7 +340,7 @@ function getLinkForElasticsearchOrOpensearch(
|
|||||||
datasourceUid: dataSourceSettings.uid,
|
datasourceUid: dataSourceSettings.uid,
|
||||||
datasourceName: dataSourceSettings.name,
|
datasourceName: dataSourceSettings.name,
|
||||||
query: {
|
query: {
|
||||||
query: query,
|
query: queryArr.join(' AND '),
|
||||||
refId: '',
|
refId: '',
|
||||||
metrics: [
|
metrics: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user