Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exact phrase search syntax #2028

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export function TracePageSearchBarFn(props: TracePageSearchBarProps & { forwarde
span ID, and key-value pairs in tags and logs. The spans that match any of the search terms will be
highlighted.
</p>
<p>
For exact phrase search surround the query in double quotes like{' '}
<code>&quot;The quick brown fox&quot;</code>
</p>
<p>
When matching key-value pairs, the substring search is applied separately against the key, the
value, and the concatenated <code>&quot;key=value&quot;</code> string. The latter allows searching
Expand Down
22 changes: 21 additions & 1 deletion packages/jaeger-ui/src/utils/filter-spans.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe('filterSpans', () => {
key: 'processTagKey1',
value: 'processTagValue1',
},
{
key: 'processTagKey3',
value: 'processTagValue3',
},
],
},
tags: [
Expand All @@ -42,6 +46,10 @@ describe('filterSpans', () => {
key: 'tagKey1',
value: 'tagValue1',
},
{
key: 'tagKey3',
value: 'tagValue3',
},
],
logs: [
{
Expand Down Expand Up @@ -75,6 +83,10 @@ describe('filterSpans', () => {
key: 'processTagKey1',
value: 'processTagValue2',
},
{
key: 'processTagKey3',
value: 'processTag Value3',
},
],
},
tags: [
Expand All @@ -86,6 +98,10 @@ describe('filterSpans', () => {
key: 'tagKey1',
value: 'tagValue2',
},
{
key: 'tagKey3',
value: 'tag Value3',
},
],
logs: [
{
Expand Down Expand Up @@ -158,6 +174,7 @@ describe('filterSpans', () => {
expect(filterSpans('tagValue1', spans)).toEqual(new Set([spanID0, spanID2]));
expect(filterSpans('tagValue0', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('tagValue2', spans)).toEqual(new Set([spanID2]));
expect(filterSpans('"tag Value3"', spans)).toEqual(new Set([spanID2]));
});

it("should return spans whose tags' kv.key=kv.value match a filter", () => {
Expand All @@ -169,6 +186,7 @@ describe('filterSpans', () => {
it("should exclude span whose tags' kv.value or kv.key match a filter if the key matches an excludeKey", () => {
expect(filterSpans('tagValue1 -tagKey2', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('tagValue1 -tagKey1', spans)).toEqual(new Set([spanID2]));
expect(filterSpans('"tag Value3" -tagKey3', spans)).toEqual(new Set());
});

it('should return spans whose logs have a field whose kv.key match a filter', () => {
Expand Down Expand Up @@ -209,9 +227,10 @@ describe('filterSpans', () => {
expect(filterSpans('processTagValue1', spans)).toEqual(new Set([spanID0, spanID2]));
expect(filterSpans('processTagValue0', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('processTagValue2', spans)).toEqual(new Set([spanID2]));
expect(filterSpans('"processTag Value3"', spans)).toEqual(new Set([spanID2]));
});

it("should return spans whose process.processTags' kv.keykv.value match a filter", () => {
it("should return spans whose process.processTags' kv.key=kv.value match a filter", () => {
expect(filterSpans('processTagKey1=processTagValue1', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('processTagKey0=processTagValue0', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('processTagKey2=processTagValue1', spans)).toEqual(new Set([spanID2]));
Expand All @@ -220,6 +239,7 @@ describe('filterSpans', () => {
it("should exclude span whose process.processTags' kv.value or kv.key match a filter if the key matches an excludeKey", () => {
expect(filterSpans('processTagValue1 -processTagKey2', spans)).toEqual(new Set([spanID0]));
expect(filterSpans('processTagValue1 -processTagKey1', spans)).toEqual(new Set([spanID2]));
expect(filterSpans('"processTag Value3" -processTagKey3', spans)).toEqual(new Set());
});

// This test may false positive if other tests are failing
Expand Down
23 changes: 12 additions & 11 deletions packages/jaeger-ui/src/utils/filter-spans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ export default function filterSpans(textFilter: string, spans: Span[] | TNil) {
// values with keys that include text in any one of the excludeKeys will be ignored
const excludeKeys: string[] = [];

// split textFilter by whitespace, remove empty strings, and extract includeFilters and excludeKeys
textFilter
.split(/\s+/)
.filter(Boolean)
.forEach(w => {
if (w[0] === '-') {
excludeKeys.push(w.substr(1).toLowerCase());
} else {
includeFilters.push(w.toLowerCase());
}
});
// split textFilter by whitespace, but not that in double quotes, remove empty strings, and extract includeFilters and excludeKeys
const regex = /[^\s"]+|"([^"]*)"/g;
const match = textFilter.match(regex);
const results = match ? match.map(e => e.replace(/"(.*)"/, '$1')) : [];

results.filter(Boolean).forEach(w => {
if (w[0] === '-') {
excludeKeys.push(w.substr(1).toLowerCase());
} else {
includeFilters.push(w.toLowerCase());
}
});

const isTextInFilters = (filters: Array<string>, text: string) =>
filters.some(filter => text.toLowerCase().includes(filter));
Expand Down
Loading