From 280f259f730c9a141c99cc5c75e081c5e5cb7945 Mon Sep 17 00:00:00 2001 From: Joey <90795735+joey-grafana@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:42:12 +0100 Subject: [PATCH] Tracing: Remove unused selectors (#71038) Remove unused selectors --- .../components/selectors/process.test.ts | 29 ---- .../TraceView/components/selectors/process.ts | 18 --- .../components/selectors/span.test.ts | 146 ------------------ .../TraceView/components/selectors/span.ts | 39 +---- 4 files changed, 1 insertion(+), 231 deletions(-) delete mode 100644 public/app/features/explore/TraceView/components/selectors/process.test.ts delete mode 100644 public/app/features/explore/TraceView/components/selectors/process.ts diff --git a/public/app/features/explore/TraceView/components/selectors/process.test.ts b/public/app/features/explore/TraceView/components/selectors/process.test.ts deleted file mode 100644 index cf6ad8caa7f..00000000000 --- a/public/app/features/explore/TraceView/components/selectors/process.test.ts +++ /dev/null @@ -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); -}); diff --git a/public/app/features/explore/TraceView/components/selectors/process.ts b/public/app/features/explore/TraceView/components/selectors/process.ts deleted file mode 100644 index 91c2bcaa605..00000000000 --- a/public/app/features/explore/TraceView/components/selectors/process.ts +++ /dev/null @@ -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; diff --git a/public/app/features/explore/TraceView/components/selectors/span.test.ts b/public/app/features/explore/TraceView/components/selectors/span.test.ts index 9186366a0f1..89ebd46732c 100644 --- a/public/app/features/explore/TraceView/components/selectors/span.test.ts +++ b/public/app/features/explore/TraceView/components/selectors/span.test.ts @@ -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]]); -}); diff --git a/public/app/features/explore/TraceView/components/selectors/span.ts b/public/app/features/explore/TraceView/components/selectors/span.ts index 9f7d10eeb26..d7b093e1fc9 100644 --- a/public/app/features/explore/TraceView/components/selectors/span.ts +++ b/public/app/features/explore/TraceView/components/selectors/span.ts @@ -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)) -);