mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) 2017 Uber Technologies, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
import traceGenerator from '../demo/trace-generators';
|
||||
import { TraceProcess } from '../types';
|
||||
|
||||
import * as processSelectors from './process';
|
||||
|
||||
const generatedTrace = traceGenerator.trace({ numberOfSpans: 45 });
|
||||
|
||||
it('getProcessServiceName() should return the serviceName of the process', () => {
|
||||
const proc: TraceProcess = generatedTrace.processes[Object.keys(generatedTrace.processes)[0]];
|
||||
expect(processSelectors.getProcessServiceName(proc)).toBe(proc.serviceName);
|
||||
});
|
||||
|
||||
it('getProcessTags() should return the tags on the process', () => {
|
||||
const proc: TraceProcess = generatedTrace.processes[Object.keys(generatedTrace.processes)[0]];
|
||||
expect(processSelectors.getProcessTags(proc)).toBe(proc.tags);
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2017 Uber Technologies, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { TraceProcess } from '../types';
|
||||
|
||||
export const getProcessServiceName = (proc: TraceProcess) => proc.serviceName;
|
||||
export const getProcessTags = (proc: TraceProcess) => proc.tags;
|
||||
@@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { TraceResponse } from 'app/features/explore/TraceView/components/types';
|
||||
import { TraceSpan, TraceSpanData } from 'app/features/explore/TraceView/components/types/trace';
|
||||
|
||||
import traceGenerator from '../demo/trace-generators';
|
||||
|
||||
@@ -27,24 +26,6 @@ it('getSpanId() should return the name of the span', () => {
|
||||
expect(spanSelectors.getSpanId(span)).toBe(span.spanID);
|
||||
});
|
||||
|
||||
it('getSpanName() should return the name of the span', () => {
|
||||
const span = generatedTrace.spans[0];
|
||||
|
||||
expect(spanSelectors.getSpanName(span)).toBe(span.operationName);
|
||||
});
|
||||
|
||||
it('getSpanDuration() should return the duration of the span', () => {
|
||||
const span = generatedTrace.spans[0];
|
||||
|
||||
expect(spanSelectors.getSpanDuration(span)).toBe(span.duration);
|
||||
});
|
||||
|
||||
it('getSpanTimestamp() should return the timestamp of the span', () => {
|
||||
const span = generatedTrace.spans[0];
|
||||
|
||||
expect(spanSelectors.getSpanTimestamp(span)).toBe(span.startTime);
|
||||
});
|
||||
|
||||
it('getSpanReferences() should return the span reference array', () => {
|
||||
expect(spanSelectors.getSpanReferences(generatedTrace.spans[0])).toEqual(generatedTrace.spans[0].references);
|
||||
});
|
||||
@@ -82,130 +63,3 @@ it('getSpanParentId() should return the spanID of the parent span', () => {
|
||||
it('getSpanParentId() should return null if no CHILD_OF reference exists', () => {
|
||||
expect(spanSelectors.getSpanParentId(generatedTrace.spans[0])).toBe(null);
|
||||
});
|
||||
|
||||
it('getSpanProcessId() should return the processID of the span', () => {
|
||||
const span = generatedTrace.spans[0];
|
||||
|
||||
expect(spanSelectors.getSpanProcessId(span)).toBe(span.processID);
|
||||
});
|
||||
|
||||
it('getSpanProcess() should return the process of the span', () => {
|
||||
const serviceName = 'bagel';
|
||||
const span = {
|
||||
...generatedTrace.spans[0],
|
||||
process: { serviceName },
|
||||
} as TraceSpan;
|
||||
|
||||
expect(spanSelectors.getSpanProcess(span)).toBe(span.process);
|
||||
});
|
||||
|
||||
it('getSpanProcess() should throw if no process exists', () => {
|
||||
expect(() => spanSelectors.getSpanProcess(generatedTrace.spans[0] as TraceSpan)).toThrow();
|
||||
});
|
||||
|
||||
it('getSpanServiceName() should return the service name of the span', () => {
|
||||
const serviceName = 'bagel';
|
||||
const span = {
|
||||
...generatedTrace.spans[0],
|
||||
process: { serviceName },
|
||||
} as TraceSpan;
|
||||
|
||||
expect(spanSelectors.getSpanServiceName(span)).toBe(serviceName);
|
||||
});
|
||||
|
||||
it('filterSpansForTimestamps() should return a filtered list of spans between the times', () => {
|
||||
const now = new Date().getTime() * 1000;
|
||||
const spans = [
|
||||
{
|
||||
startTime: now - 1000,
|
||||
spanID: 'start-time-1',
|
||||
},
|
||||
{
|
||||
startTime: now,
|
||||
spanID: 'start-time-2',
|
||||
},
|
||||
{
|
||||
startTime: now + 1000,
|
||||
spanID: 'start-time-3',
|
||||
},
|
||||
] as TraceSpanData[];
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForTimestamps({
|
||||
spans,
|
||||
leftBound: now - 500,
|
||||
rightBound: now + 500,
|
||||
})
|
||||
).toEqual([spans[1]]);
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForTimestamps({
|
||||
spans,
|
||||
leftBound: now - 2000,
|
||||
rightBound: now + 2000,
|
||||
})
|
||||
).toEqual([...spans]);
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForTimestamps({
|
||||
spans,
|
||||
leftBound: now - 1000,
|
||||
rightBound: now,
|
||||
})
|
||||
).toEqual([spans[0], spans[1]]);
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForTimestamps({
|
||||
spans,
|
||||
leftBound: now,
|
||||
rightBound: now + 1000,
|
||||
})
|
||||
).toEqual([spans[1], spans[2]]);
|
||||
});
|
||||
|
||||
it('filterSpansForText() should return a filtered list of spans between the times', () => {
|
||||
const spans = [
|
||||
{
|
||||
operationName: 'GET /mything',
|
||||
process: {
|
||||
serviceName: 'alpha',
|
||||
},
|
||||
spanID: 'start-time-1',
|
||||
},
|
||||
{
|
||||
operationName: 'GET /another',
|
||||
process: {
|
||||
serviceName: 'beta',
|
||||
},
|
||||
spanID: 'start-time-1',
|
||||
},
|
||||
{
|
||||
operationName: 'POST /mything',
|
||||
process: {
|
||||
serviceName: 'alpha',
|
||||
},
|
||||
spanID: 'start-time-1',
|
||||
},
|
||||
] as TraceSpan[];
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForText({
|
||||
spans,
|
||||
text: '/mything',
|
||||
})
|
||||
).toEqual([spans[0], spans[2]]);
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForText({
|
||||
spans,
|
||||
text: 'GET',
|
||||
})
|
||||
).toEqual([spans[0], spans[1]]);
|
||||
|
||||
expect(
|
||||
spanSelectors.filterSpansForText({
|
||||
spans,
|
||||
text: 'alpha',
|
||||
})
|
||||
).toEqual([spans[0], spans[2]]);
|
||||
});
|
||||
|
||||
@@ -14,17 +14,9 @@
|
||||
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
import { fuzzyMatch } from '@grafana/ui';
|
||||
|
||||
import { TraceSpan, TraceSpanData, TraceSpanReference } from '../types/trace';
|
||||
|
||||
import { getProcessServiceName } from './process';
|
||||
import { TraceSpanData, TraceSpanReference } from '../types/trace';
|
||||
|
||||
export const getSpanId = (span: TraceSpanData) => span.spanID;
|
||||
export const getSpanName = (span: TraceSpanData) => span.operationName;
|
||||
export const getSpanDuration = (span: TraceSpanData) => span.duration;
|
||||
export const getSpanTimestamp = (span: TraceSpanData) => span.startTime;
|
||||
export const getSpanProcessId = (span: TraceSpanData) => span.processID;
|
||||
export const getSpanReferences = (span: TraceSpanData) => span.references || [];
|
||||
export const getSpanReferenceByType = createSelector(
|
||||
createSelector(({ span }: { span: TraceSpanData }) => span, getSpanReferences),
|
||||
@@ -35,32 +27,3 @@ export const getSpanParentId = createSelector(
|
||||
(span: TraceSpanData) => getSpanReferenceByType({ span, type: 'CHILD_OF' }),
|
||||
(childOfRef) => (childOfRef ? childOfRef.spanID : null)
|
||||
);
|
||||
|
||||
export const getSpanProcess = (span: TraceSpan) => {
|
||||
if (!span.process) {
|
||||
throw new Error(
|
||||
`
|
||||
you must hydrate the spans with the processes, perhaps
|
||||
using hydrateSpansWithProcesses(), before accessing a span's process
|
||||
`
|
||||
);
|
||||
}
|
||||
return span.process;
|
||||
};
|
||||
|
||||
export const getSpanServiceName = createSelector(getSpanProcess, getProcessServiceName);
|
||||
|
||||
export const filterSpansForTimestamps = createSelector(
|
||||
({ spans }: { spans: TraceSpanData[] }) => spans,
|
||||
({ leftBound }: { leftBound: number }) => leftBound,
|
||||
({ rightBound }: { rightBound: number }) => rightBound,
|
||||
(spans, leftBound, rightBound) =>
|
||||
spans.filter((span) => getSpanTimestamp(span) >= leftBound && getSpanTimestamp(span) <= rightBound)
|
||||
);
|
||||
|
||||
export const filterSpansForText = createSelector(
|
||||
({ spans }: { spans: TraceSpan[] }) => spans,
|
||||
({ text }: { text: string }) => text,
|
||||
(spans, text) =>
|
||||
spans.filter((span) => (span ? fuzzyMatch(`${getSpanServiceName(span)} ${getSpanName(span)}`, text).found : false))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user