diff --git a/packages/jaeger-ui-components/src/model/ddg/PathElem.test.js b/packages/jaeger-ui-components/src/model/ddg/PathElem.test.ts similarity index 96% rename from packages/jaeger-ui-components/src/model/ddg/PathElem.test.js rename to packages/jaeger-ui-components/src/model/ddg/PathElem.test.ts index e7eba0d49e3..2e835d09bc7 100644 --- a/packages/jaeger-ui-components/src/model/ddg/PathElem.test.js +++ b/packages/jaeger-ui-components/src/model/ddg/PathElem.test.ts @@ -14,12 +14,13 @@ import PathElem from './PathElem'; import { simplePath } from './sample-paths.test.resources'; +import { TDdgOperation, TDdgPath, TDdgService } from './types'; describe('PathElem', () => { const getPath = () => { const path = { focalIdx: 2, - }; + } as TDdgPath; const members = simplePath.map( ({ operation, service }, i) => new PathElem({ @@ -28,8 +29,8 @@ describe('PathElem', () => { name: operation, service: { name: service, - }, - }, + } as TDdgService, + } as TDdgOperation, path, }) ); @@ -42,13 +43,13 @@ describe('PathElem', () => { return path; }; const testMemberIdx = 3; - const testOperation = {}; + const testOperation = {} as TDdgOperation; const testPath = { focalIdx: 4, members: ['member0', 'member1', 'member2', 'member3', 'member4', 'member5'], - }; + } as unknown as TDdgPath; const testVisibilityIdx = 105; - let pathElem; + let pathElem: PathElem; beforeEach(() => { pathElem = new PathElem({ path: testPath, operation: testOperation, memberIdx: testMemberIdx }); diff --git a/packages/jaeger-ui-components/src/model/ddg/__snapshots__/PathElem.test.js.snap b/packages/jaeger-ui-components/src/model/ddg/__snapshots__/PathElem.test.ts.snap similarity index 100% rename from packages/jaeger-ui-components/src/model/ddg/__snapshots__/PathElem.test.js.snap rename to packages/jaeger-ui-components/src/model/ddg/__snapshots__/PathElem.test.ts.snap diff --git a/packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.js b/packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.ts similarity index 93% rename from packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.js rename to packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.ts index b9dadfcaf1b..7bcd7a0f040 100644 --- a/packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.js +++ b/packages/jaeger-ui-components/src/model/ddg/sample-paths.test.resources.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -export const simplePayloadElemMaker = (label) => ({ +export const simplePayloadElemMaker = (label: string) => ({ operation: `${label}Operation`, service: `${label}Service`, }); @@ -24,9 +24,9 @@ const sameFocalServicePayloadElem = { service: focalPayloadElem.service, }; -const pathLengthener = (path) => { - const prequels = []; - const sequels = []; +const pathLengthener = (path: Array<{ operation: string; service: string }>) => { + const prequels: Array<{ operation: string; service: string }> = []; + const sequels: Array<{ operation: string; service: string }> = []; path.forEach(({ operation, service }) => { if (operation !== focalPayloadElem.operation && service !== focalPayloadElem.service) { prequels.push({ @@ -115,7 +115,3 @@ export const generationPaths = [ ], [generationPayloadElems.target, generationPayloadElems.beforeFocalMid, focalPayloadElem], ]; - -export const wrap = (paths) => ({ - dependencies: paths.map((path) => ({ path, attributes: [] })), -}); diff --git a/packages/jaeger-ui-components/src/model/find-trace-name.test.js b/packages/jaeger-ui-components/src/model/find-trace-name.test.ts similarity index 93% rename from packages/jaeger-ui-components/src/model/find-trace-name.test.js rename to packages/jaeger-ui-components/src/model/find-trace-name.test.ts index 39c9653a528..bec8fefd8c3 100644 --- a/packages/jaeger-ui-components/src/model/find-trace-name.test.js +++ b/packages/jaeger-ui-components/src/model/find-trace-name.test.ts @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { TraceSpan } from '../types/trace'; + import { _getTraceNameImpl as getTraceName } from './trace-viewer'; describe('getTraceName', () => { @@ -223,22 +225,22 @@ describe('getTraceName', () => { const fullTraceName = `${serviceName}: ${operationName}`; it('returns an empty string if given spans with no root among them', () => { - expect(getTraceName(spansWithNoRoots)).toEqual(''); + expect(getTraceName(spansWithNoRoots as TraceSpan[])).toEqual(''); }); it('returns an id of root span with the earliest startTime', () => { - expect(getTraceName(spansWithMultipleRootsDifferentByStartTime)).toEqual(fullTraceName); + expect(getTraceName(spansWithMultipleRootsDifferentByStartTime as TraceSpan[])).toEqual(fullTraceName); }); it('returns an id of root span without any refs', () => { - expect(getTraceName(spansWithMultipleRootsWithOneWithoutRefs)).toEqual(fullTraceName); + expect(getTraceName(spansWithMultipleRootsWithOneWithoutRefs as unknown as TraceSpan[])).toEqual(fullTraceName); }); it('returns an id of root span with remote ref', () => { - expect(getTraceName(spansWithOneRootWithRemoteRef)).toEqual(fullTraceName); + expect(getTraceName(spansWithOneRootWithRemoteRef as TraceSpan[])).toEqual(fullTraceName); }); it('returns an id of root span with no refs', () => { - expect(getTraceName(spansWithOneRootWithNoRefs)).toEqual(fullTraceName); + expect(getTraceName(spansWithOneRootWithNoRefs as unknown as TraceSpan[])).toEqual(fullTraceName); }); }); diff --git a/packages/jaeger-ui-components/src/model/link-patterns.test.js b/packages/jaeger-ui-components/src/model/link-patterns.test.ts similarity index 93% rename from packages/jaeger-ui-components/src/model/link-patterns.test.js rename to packages/jaeger-ui-components/src/model/link-patterns.test.ts index 22f5c13a047..0a6768febd9 100644 --- a/packages/jaeger-ui-components/src/model/link-patterns.test.js +++ b/packages/jaeger-ui-components/src/model/link-patterns.test.ts @@ -12,12 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { Trace, TraceLink, TraceSpan } from '../types/trace'; + import { processTemplate, createTestFunction, getParameterInArray, getParameterInAncestor, processLinkPattern, + ProcessedLinkPattern, computeLinks, createGetLinks, computeTraceLink, @@ -64,7 +67,8 @@ describe('processTemplate()', () => { expect(() => processTemplate( { - template: (data) => `a${data.b}c`, + /* eslint-disable @typescript-eslint/no-explicit-any */ + template: (data: { [key: string]: any }) => `a${data.b}c`, }, (a) => a ) @@ -243,21 +247,28 @@ describe('getParameterInAncestor()', () => { }, tags: [{ key: 'a', value: 'a0' }], }, - ]; + ] as TraceSpan[]; + spans[1].references = [ { + spanID: 's1', + traceID: 't2', refType: 'CHILD_OF', span: spans[0], }, ]; spans[2].references = [ { + spanID: 's1', + traceID: 't2', refType: 'CHILD_OF', span: spans[0], }, ]; spans[3].references = [ { + spanID: 's1', + traceID: 't2', refType: 'CHILD_OF', span: spans[2], }, @@ -311,7 +322,7 @@ describe('getParameterInAncestor()', () => { depth: 0, process: {}, }, - ]; + ] as TraceSpan[]; expect(getParameterInAncestor('a', spansWithUndefinedTags[0])).toBeUndefined(); }); }); @@ -328,7 +339,7 @@ describe('computeTraceLink()', () => { url: 'http://example.com/?myKey=#{traceID}&myKey=#{myKey}', text: 'second link (#{myKey})', }, - ].map(processLinkPattern); + ].map(processLinkPattern) as ProcessedLinkPattern[]; const trace = { processes: [], @@ -338,7 +349,7 @@ describe('computeTraceLink()', () => { endTime: 2000, duration: 1000, services: [], - }; + } as unknown as Trace; it('correctly computes links', () => { expect(computeTraceLink(linkPatterns, trace)).toEqual([ @@ -363,14 +374,16 @@ describe('computeLinks()', () => { url: 'http://example.com/?myKey=#{myOtherKey}&myKey=#{myKey}', text: 'second link (#{myOtherKey})', }, - ].map(processLinkPattern); + ].map(processLinkPattern) as ProcessedLinkPattern[]; const spans = [ { depth: 0, process: {}, tags: [{ key: 'myKey', value: 'valueOfMyKey' }] }, { depth: 1, process: {}, logs: [{ fields: [{ key: 'myOtherKey', value: 'valueOfMy+Other+Key' }] }] }, - ]; + ] as unknown as TraceSpan[]; spans[1].references = [ { + spanID: 's1', + traceID: 't2', refType: 'CHILD_OF', span: spans[0], }, @@ -399,12 +412,13 @@ describe('getLinks()', () => { url: 'http://example.com/?mySpecialKey=#{mySpecialKey}', text: 'special key link (#{mySpecialKey})', }, - ].map(processLinkPattern); - const template = jest.spyOn(linkPatterns[0].url, 'template'); + ].map(processLinkPattern) as ProcessedLinkPattern[]; + const template = jest.spyOn(linkPatterns[0]!.url, 'template'); - const span = { depth: 0, process: {}, tags: [{ key: 'mySpecialKey', value: 'valueOfMyKey' }] }; + const span = { depth: 0, process: {}, tags: [{ key: 'mySpecialKey', value: 'valueOfMyKey' }] } as TraceSpan; - let cache; + /* eslint-disable @typescript-eslint/no-explicit-any */ + let cache: WeakMap; beforeEach(() => { cache = new WeakMap(); @@ -419,7 +433,7 @@ describe('getLinks()', () => { }); it('returns the result from the cache', () => { - const result = []; + const result: TraceLink[] = []; cache.set(span.tags[0], result); const getLinks = createGetLinks(linkPatterns, cache); expect(getLinks(span, span.tags, 0)).toBe(result); diff --git a/packages/jaeger-ui-components/src/model/link-patterns.tsx b/packages/jaeger-ui-components/src/model/link-patterns.tsx index d0d47a676a1..9f74ccb532f 100644 --- a/packages/jaeger-ui-components/src/model/link-patterns.tsx +++ b/packages/jaeger-ui-components/src/model/link-patterns.tsx @@ -28,7 +28,7 @@ type ProcessedTemplate = { template: (template: { [key: string]: any }) => string; }; -type ProcessedLinkPattern = { +export type ProcessedLinkPattern = { object: any; type: (link: string) => boolean; key: (link: string) => boolean; @@ -74,7 +74,7 @@ export function processTemplate(template: unknown, encodeFn: (unencoded: any) => }; } -export function createTestFunction(entry: any) { +export function createTestFunction(entry?: any) { if (typeof entry === 'string') { return (arg: unknown) => arg === entry; } @@ -100,7 +100,7 @@ export function createTestFunction(entry: any) { const identity = (a: any): typeof a => a; -export function processLinkPattern(pattern: any): ProcessedLinkPattern | TNil { +export function processLinkPattern(pattern: any): ProcessedLinkPattern | null { try { const url = processTemplate(pattern.url, encodeURIComponent); const text = processTemplate(pattern.text, identity); @@ -120,7 +120,7 @@ export function processLinkPattern(pattern: any): ProcessedLinkPattern | TNil { } } -export function getParameterInArray(name: string, array: TraceKeyValuePair[]) { +export function getParameterInArray(name: string, array?: TraceKeyValuePair[] | TNil) { if (array) { return array.find((entry) => entry.key === name); } @@ -150,10 +150,10 @@ export function computeTraceLink(linkPatterns: ProcessedLinkPattern[], trace: Tr ); linkPatterns - .filter((pattern) => pattern.type('traces')) + ?.filter((pattern) => pattern?.type('traces')) .forEach((pattern) => { const parameterValues: Record = {}; - const allParameters = pattern.parameters.every((parameter) => { + const allParameters = pattern?.parameters.every((parameter) => { const key = parameter as keyof Trace; if (validKeys.includes(key)) { // At this point is safe to access to trace object using parameter variable because diff --git a/packages/jaeger-ui-components/src/model/transform-trace-data.test.js b/packages/jaeger-ui-components/src/model/transform-trace-data.test.ts similarity index 91% rename from packages/jaeger-ui-components/src/model/transform-trace-data.test.js rename to packages/jaeger-ui-components/src/model/transform-trace-data.test.ts index 8dfa857fdcf..0a73c00d943 100644 --- a/packages/jaeger-ui-components/src/model/transform-trace-data.test.js +++ b/packages/jaeger-ui-components/src/model/transform-trace-data.test.ts @@ -11,6 +11,7 @@ // 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 { TraceResponse } from '../types/trace'; import transformTraceData, { orderTags, deduplicateTags } from './transform-trace-data'; @@ -136,7 +137,7 @@ describe('transformTraceData()', () => { traceID: undefined, processes, spans, - }; + } as unknown as TraceResponse; expect(transformTraceData(traceData)).toEqual(null); }); @@ -146,9 +147,9 @@ describe('transformTraceData()', () => { traceID, processes, spans: [...spans, rootSpanWithMissingRef], - }; + } as unknown as TraceResponse; - expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`); + expect(transformTraceData(traceData)!.traceName).toEqual(`${serviceName}: ${rootOperationName}`); }); it('should return trace data with correct traceName based on root span without any refs', () => { @@ -156,8 +157,8 @@ describe('transformTraceData()', () => { traceID, processes, spans: [...spans, rootSpanWithoutRefs], - }; + } as unknown as TraceResponse; - expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`); + expect(transformTraceData(traceData)!.traceName).toEqual(`${serviceName}: ${rootOperationName}`); }); });