Skip to content

Commit

Permalink
Span Search - Improve search logic (jaegertracing#237)
Browse files Browse the repository at this point in the history
* Add result count, navigation and clear buttons

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Correct imports

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Move and delete files

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Review fixes

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Fix TracePageHeader test

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Lighten buttons when disabled

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Review fixes

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Fix tests

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Add shortcuts

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Fix merge changes

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Fix TracePageHeader and TracePageSearchBar tests

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Delay TracePageHeader testing until release of Enzyme v3.5.0

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Improve search logic

Signed-off-by: Davit Yeghshatyan <[email protected]>

* Misc cleanup to fix a lint issue

Signed-off-by: Joe Farro <[email protected]>

Signed-off-by: vvvprabhakar <[email protected]>
  • Loading branch information
davit-y authored and yurishkuro committed Sep 30, 2018
1 parent 80367a6 commit 01f182f
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions packages/jaeger-ui/src/components/TracePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import TraceTimelineViewer from './TraceTimelineViewer';
import ErrorMessage from '../common/ErrorMessage';
import LoadingIndicator from '../common/LoadingIndicator';
import * as jaegerApiActions from '../../actions/jaeger-api';
import { filterSpansForText } from '../../selectors/span';
import { fetchedState } from '../../constants';
import { getTraceName } from '../../model/trace-viewer';
import prefixUrl from '../../utils/prefix-url';

import type { CombokeysHandler, ShortcutCallbacks } from './keyboard-shortcuts';
import type { ViewRange, ViewRangeTimeUpdate } from './types';
import type { FetchedTrace, ReduxState } from '../../types';
import type { KeyValuePair, Span } from '../../types/trace';
import type { TraceArchive } from '../../types/archive';

import './index.css';
Expand Down Expand Up @@ -213,15 +213,58 @@ export class TracePageImpl extends React.PureComponent<TracePageProps, TracePage
}
};

filterSpans: (string => ?Set<string>) = (textFilter: string) => {
const spans = this.props.trace && this.props.trace.data && this.props.trace.data.spans;
if (!spans) return null;

// if a span field includes at least one filter in includeFilters, the span is a match
const includeFilters = [];

// values with keys that include text in any one of the excludeKeys will be ignored
const excludeKeys = [];

// split textFilter by whitespace, remove empty strings, and extract includeFilters and excludeKeys
textFilter
.split(' ')
.map(s => s.trim())
.filter(s => s)
.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));

const isTextInKeyValues = (kvs: Array<KeyValuePair>) =>
kvs
? kvs.some(kv => {
// ignore checking key and value for a match if key is in excludeKeys
if (isTextInFilters(excludeKeys, kv.key)) return false;
// match if key or value matches an item in includeFilters
return (
isTextInFilters(includeFilters, kv.key) || isTextInFilters(includeFilters, kv.value.toString())
);
})
: false;

const isSpanAMatch = (span: Span) =>
isTextInFilters(includeFilters, span.operationName) ||
isTextInFilters(includeFilters, span.process.serviceName) ||
isTextInKeyValues(span.tags) ||
span.logs.some(log => isTextInKeyValues(log.fields)) ||
isTextInKeyValues(span.process.tags);

return new Set(spans.filter(isSpanAMatch).map((span: Span) => span.spanID));
};

updateTextFilter = (textFilter: string) => {
let findMatchesIDs;
if (textFilter.trim()) {
const { trace } = this.props;
const matches = filterSpansForText({
text: textFilter.trim(),
spans: trace && trace.data && trace.data.spans,
});
findMatchesIDs = new Set(matches.map(span => span.spanID));
findMatchesIDs = this.filterSpans(textFilter);
} else {
findMatchesIDs = null;
}
Expand Down

0 comments on commit 01f182f

Please sign in to comment.