mirror of
https://github.com/prometheus/prometheus.git
synced 2026-02-18 18:25:24 -05:00
Merge pull request #18025 from prometheus/codesome/3-10-npm-deps
Update npm dependencies for v3.10
This commit is contained in:
commit
43eaaf55a4
10 changed files with 773 additions and 664 deletions
|
|
@ -12,57 +12,57 @@
|
|||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/autocomplete": "^6.19.1",
|
||||
"@codemirror/language": "^6.11.3",
|
||||
"@codemirror/lint": "^6.9.2",
|
||||
"@codemirror/state": "^6.5.2",
|
||||
"@codemirror/view": "^6.38.6",
|
||||
"@floating-ui/dom": "^1.7.4",
|
||||
"@lezer/common": "^1.3.0",
|
||||
"@codemirror/autocomplete": "^6.20.0",
|
||||
"@codemirror/language": "^6.12.1",
|
||||
"@codemirror/lint": "^6.9.3",
|
||||
"@codemirror/state": "^6.5.4",
|
||||
"@codemirror/view": "^6.39.12",
|
||||
"@floating-ui/dom": "^1.7.5",
|
||||
"@lezer/common": "^1.5.1",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@mantine/code-highlight": "^8.3.6",
|
||||
"@mantine/core": "^8.3.6",
|
||||
"@mantine/dates": "^8.3.6",
|
||||
"@mantine/hooks": "^8.3.6",
|
||||
"@mantine/notifications": "^8.3.6",
|
||||
"@mantine/code-highlight": "^8.3.14",
|
||||
"@mantine/core": "^8.3.14",
|
||||
"@mantine/dates": "^8.3.14",
|
||||
"@mantine/hooks": "^8.3.14",
|
||||
"@mantine/notifications": "^8.3.14",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@nexucis/fuzzy": "^0.5.1",
|
||||
"@nexucis/kvsearch": "^0.9.1",
|
||||
"@prometheus-io/codemirror-promql": "0.309.1",
|
||||
"@reduxjs/toolkit": "^2.10.1",
|
||||
"@tabler/icons-react": "^3.35.0",
|
||||
"@tanstack/react-query": "^5.90.7",
|
||||
"@reduxjs/toolkit": "^2.11.2",
|
||||
"@tabler/icons-react": "^3.36.1",
|
||||
"@tanstack/react-query": "^5.90.20",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"@types/lodash": "^4.17.20",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@types/lodash": "^4.17.23",
|
||||
"@types/sanitize-html": "^2.16.0",
|
||||
"@uiw/react-codemirror": "^4.25.3",
|
||||
"@uiw/react-codemirror": "^4.25.4",
|
||||
"clsx": "^2.1.1",
|
||||
"dayjs": "^1.11.19",
|
||||
"highlight.js": "^11.11.1",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-infinite-scroll-component": "^6.1.0",
|
||||
"lodash": "^4.17.23",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-infinite-scroll-component": "^6.1.1",
|
||||
"react-redux": "^9.2.0",
|
||||
"react-router-dom": "^7.9.5",
|
||||
"react-router-dom": "^7.13.0",
|
||||
"sanitize-html": "^2.17.0",
|
||||
"uplot": "^1.6.32",
|
||||
"uplot-react": "^1.2.4",
|
||||
"use-query-params": "^2.2.1"
|
||||
"use-query-params": "^2.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.4.1",
|
||||
"@eslint/eslintrc": "^3.3.1",
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/react": "^19.2.2",
|
||||
"@types/react-dom": "^19.2.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.3",
|
||||
"@typescript-eslint/parser": "^8.46.3",
|
||||
"@eslint/eslintrc": "^3.3.3",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@types/react": "^19.2.13",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
||||
"@typescript-eslint/parser": "^8.54.0",
|
||||
"@vitejs/plugin-react": "^4.7.0",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"eslint-plugin-react-refresh": "^0.5.0",
|
||||
"globals": "^16.5.0",
|
||||
"jsdom": "^25.0.1",
|
||||
"postcss": "^8.5.6",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import {
|
|||
useComputedColorScheme,
|
||||
} from "@mantine/core";
|
||||
import {
|
||||
CompleteStrategy,
|
||||
PromQLExtension,
|
||||
newCompleteStrategy,
|
||||
} from "@prometheus-io/codemirror-promql";
|
||||
|
|
@ -36,12 +35,9 @@ import {
|
|||
bracketMatching,
|
||||
indentOnInput,
|
||||
syntaxHighlighting,
|
||||
syntaxTree,
|
||||
} from "@codemirror/language";
|
||||
import classes from "./ExpressionInput.module.css";
|
||||
import {
|
||||
CompletionContext,
|
||||
CompletionResult,
|
||||
autocompletion,
|
||||
closeBrackets,
|
||||
closeBracketsKeymap,
|
||||
|
|
@ -71,50 +67,10 @@ import MetricsExplorer from "./MetricsExplorer/MetricsExplorer";
|
|||
import ErrorBoundary from "../../components/ErrorBoundary";
|
||||
import { useAppSelector } from "../../state/hooks";
|
||||
import { inputIconStyle, menuIconStyle } from "../../styles";
|
||||
import { HistoryCompleteStrategy } from "./HistoryCompleteStrategy";
|
||||
|
||||
const promqlExtension = new PromQLExtension();
|
||||
|
||||
// Autocompletion strategy that wraps the main one and enriches
|
||||
// it with past query items.
|
||||
export class HistoryCompleteStrategy implements CompleteStrategy {
|
||||
private complete: CompleteStrategy;
|
||||
private queryHistory: string[];
|
||||
constructor(complete: CompleteStrategy, queryHistory: string[]) {
|
||||
this.complete = complete;
|
||||
this.queryHistory = queryHistory;
|
||||
}
|
||||
|
||||
promQL(
|
||||
context: CompletionContext
|
||||
): Promise<CompletionResult | null> | CompletionResult | null {
|
||||
return Promise.resolve(this.complete.promQL(context)).then((res) => {
|
||||
const { state, pos } = context;
|
||||
const tree = syntaxTree(state).resolve(pos, -1);
|
||||
const start = res != null ? res.from : tree.from;
|
||||
|
||||
if (start !== 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
const historyItems: CompletionResult = {
|
||||
from: start,
|
||||
to: pos,
|
||||
options: this.queryHistory.map((q) => ({
|
||||
label: q.length < 80 ? q : q.slice(0, 76).concat("..."),
|
||||
detail: "past query",
|
||||
apply: q,
|
||||
info: q.length < 80 ? undefined : q,
|
||||
})),
|
||||
validFor: /^[a-zA-Z0-9_:]+$/,
|
||||
};
|
||||
|
||||
if (res !== null) {
|
||||
historyItems.options = historyItems.options.concat(res.options);
|
||||
}
|
||||
return historyItems;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
interface ExpressionInputProps {
|
||||
initialExpr: string;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
// Autocompletion strategy that wraps the main one and enriches
|
||||
// it with past query items.
|
||||
import {CompleteStrategy} from "@prometheus-io/codemirror-promql";
|
||||
import {CompletionContext, CompletionResult} from "@codemirror/autocomplete";
|
||||
import {syntaxTree} from "@codemirror/language";
|
||||
|
||||
export class HistoryCompleteStrategy implements CompleteStrategy {
|
||||
private complete: CompleteStrategy;
|
||||
private queryHistory: string[];
|
||||
constructor(complete: CompleteStrategy, queryHistory: string[]) {
|
||||
this.complete = complete;
|
||||
this.queryHistory = queryHistory;
|
||||
}
|
||||
|
||||
promQL(
|
||||
context: CompletionContext
|
||||
): Promise<CompletionResult | null> | CompletionResult | null {
|
||||
return Promise.resolve(this.complete.promQL(context)).then((res) => {
|
||||
const { state, pos } = context;
|
||||
const tree = syntaxTree(state).resolve(pos, -1);
|
||||
const start = res != null ? res.from : tree.from;
|
||||
|
||||
if (start !== 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
const historyItems: CompletionResult = {
|
||||
from: start,
|
||||
to: pos,
|
||||
options: this.queryHistory.map((q) => ({
|
||||
label: q.length < 80 ? q : q.slice(0, 76).concat("..."),
|
||||
detail: "past query",
|
||||
apply: q,
|
||||
info: q.length < 80 ? undefined : q,
|
||||
})),
|
||||
validFor: /^[a-zA-Z0-9_:]+$/,
|
||||
};
|
||||
|
||||
if (res !== null) {
|
||||
historyItems.options = historyItems.options.concat(res.options);
|
||||
}
|
||||
return historyItems;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -30,18 +30,18 @@
|
|||
"homepage": "https://github.com/prometheus/prometheus/blob/main/web/ui/module/codemirror-promql/README.md",
|
||||
"dependencies": {
|
||||
"@prometheus-io/lezer-promql": "0.309.1",
|
||||
"lru-cache": "^11.2.2"
|
||||
"lru-cache": "^11.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@codemirror/autocomplete": "^6.19.1",
|
||||
"@codemirror/language": "^6.11.3",
|
||||
"@codemirror/lint": "^6.9.2",
|
||||
"@codemirror/state": "^6.5.2",
|
||||
"@codemirror/view": "^6.38.6",
|
||||
"@lezer/common": "^1.3.0",
|
||||
"@codemirror/autocomplete": "^6.20.0",
|
||||
"@codemirror/language": "^6.12.1",
|
||||
"@codemirror/lint": "^6.9.3",
|
||||
"@codemirror/state": "^6.5.4",
|
||||
"@codemirror/view": "^6.39.12",
|
||||
"@lezer/common": "^1.5.1",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.3",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"@lezer/lr": "^1.4.8",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"nock": "^14.0.10"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
"devDependencies": {
|
||||
"@lezer/generator": "^1.8.0",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.3",
|
||||
"@lezer/lr": "^1.4.8",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
|||
1051
web/ui/package-lock.json
generated
1051
web/ui/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -16,11 +16,11 @@
|
|||
],
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.14",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.3",
|
||||
"@typescript-eslint/parser": "^8.46.3",
|
||||
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
||||
"@typescript-eslint/parser": "^8.54.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.5",
|
||||
"prettier": "^3.8.1",
|
||||
"ts-jest": "^29.4.6",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^6.4.1"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ describe('HistogramChart', () => {
|
|||
scale: 'linear' as 'linear' | 'exponential',
|
||||
};
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
mockFormat.mockClear();
|
||||
mockResolvedOptions.mockClear();
|
||||
|
|
@ -163,7 +162,9 @@ describe('HistogramChart', () => {
|
|||
|
||||
describe('Exponential Scale', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = mount(<HistogramChart {...defaultProps} index={1} histogram={histogramDataExponential} scale="exponential" />);
|
||||
wrapper = mount(
|
||||
<HistogramChart {...defaultProps} index={1} histogram={histogramDataExponential} scale="exponential" />
|
||||
);
|
||||
});
|
||||
|
||||
it('renders the correct number of buckets', () => {
|
||||
|
|
@ -225,17 +226,24 @@ describe('HistogramChart', () => {
|
|||
expect(b4.find('.histogram-bucket').prop('style')).toHaveProperty('height', `${b4Height}%`);
|
||||
expect(parseFloat(b4.prop('style')?.left as string)).toBeGreaterThan(0);
|
||||
expect(parseFloat(b4.prop('style')?.width as string)).toBeGreaterThan(0);
|
||||
expect(parseFloat(b4.prop('style')?.left as string) + parseFloat(b4.prop('style')?.width as string)).toBeLessThanOrEqual(100.01);
|
||||
expect(
|
||||
parseFloat(b4.prop('style')?.left as string) + parseFloat(b4.prop('style')?.width as string)
|
||||
).toBeLessThanOrEqual(100.01);
|
||||
});
|
||||
|
||||
it('handles zero-crossing bucket correctly in exponential scale', () => {
|
||||
wrapper = mount(<HistogramChart {...defaultProps} index={2} histogram={histogramDataZeroCrossing} scale="exponential" />);
|
||||
wrapper = mount(
|
||||
<HistogramChart {...defaultProps} index={2} histogram={histogramDataZeroCrossing} scale="exponential" />
|
||||
);
|
||||
const buckets = wrapper.find('.histogram-bucket-slot');
|
||||
const countMax = 15;
|
||||
|
||||
const b2 = buckets.at(1);
|
||||
const b2Height = (5 / countMax) * 100;
|
||||
expect(b2.find('.histogram-bucket').prop('style')).toHaveProperty('height', expect.stringContaining(b2Height.toFixed(1)));
|
||||
expect(b2.find('.histogram-bucket').prop('style')).toHaveProperty(
|
||||
'height',
|
||||
expect.stringContaining(b2Height.toFixed(1))
|
||||
);
|
||||
expect(parseFloat(b2.prop('style')?.left as string)).toBeGreaterThanOrEqual(0);
|
||||
expect(parseFloat(b2.prop('style')?.width as string)).toBeGreaterThan(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,34 +37,31 @@ describe('HistogramHelpers', () => {
|
|||
];
|
||||
|
||||
const bucketsStartingWithZeroCross: Bucket[] = [
|
||||
[0, '-1', '1', '5'],
|
||||
[0, '1', '10', '20'],
|
||||
[0, '10', '100', '8'],
|
||||
[0, '-1', '1', '5'],
|
||||
[0, '1', '10', '20'],
|
||||
[0, '10', '100', '8'],
|
||||
];
|
||||
|
||||
const bucketsEndingWithZeroCross: Bucket[] = [
|
||||
[0, '-100', '-10', '10'],
|
||||
[0, '-10', '-1', '15'],
|
||||
[0, '-1', '1', '5'],
|
||||
const bucketsEndingWithZeroCross: Bucket[] = [
|
||||
[0, '-100', '-10', '10'],
|
||||
[0, '-10', '-1', '15'],
|
||||
[0, '-1', '1', '5'],
|
||||
];
|
||||
|
||||
const singleZeroBucket: Bucket[] = [
|
||||
[0, '0', '0', '10'],
|
||||
];
|
||||
const singleZeroBucket: Bucket[] = [[0, '0', '0', '10']];
|
||||
|
||||
const emptyBuckets: Bucket[] = [];
|
||||
const emptyBuckets: Bucket[] = [];
|
||||
|
||||
const bucketsWithZeroFallback: Bucket[] = [
|
||||
[0, '1', '10', '5'],
|
||||
[0, '10', '100', '15'],
|
||||
[0, '0', '0', '2']
|
||||
];
|
||||
|
||||
const bucketsNegThenPosNoCross: Bucket[] = [
|
||||
[0, '-10', '-1', '15'],
|
||||
[0, '5', '10', '20'],
|
||||
];
|
||||
const bucketsWithZeroFallback: Bucket[] = [
|
||||
[0, '1', '10', '5'],
|
||||
[0, '10', '100', '15'],
|
||||
[0, '0', '0', '2'],
|
||||
];
|
||||
|
||||
const bucketsNegThenPosNoCross: Bucket[] = [
|
||||
[0, '-10', '-1', '15'],
|
||||
[0, '5', '10', '20'],
|
||||
];
|
||||
|
||||
describe('calculateDefaultExpBucketWidth', () => {
|
||||
it('calculates width for a standard positive bucket', () => {
|
||||
|
|
@ -75,29 +72,30 @@ describe('HistogramHelpers', () => {
|
|||
|
||||
it('calculates width for a standard negative bucket', () => {
|
||||
const lastBucket = bucketsAllNegative[bucketsAllNegative.length - 1];
|
||||
const expectedAbs = Math.abs(Math.log(Math.abs(parseFloat(lastBucket[2]))) - Math.log(Math.abs(parseFloat(lastBucket[1]))));
|
||||
const expectedAbs = Math.abs(
|
||||
Math.log(Math.abs(parseFloat(lastBucket[2]))) - Math.log(Math.abs(parseFloat(lastBucket[1])))
|
||||
);
|
||||
expect(calculateDefaultExpBucketWidth(lastBucket, bucketsAllNegative)).toBeCloseTo(expectedAbs);
|
||||
});
|
||||
|
||||
it('uses the previous bucket if the last bucket is [0, 0]', () => {
|
||||
const lastBucket = bucketsWithZeroFallback[bucketsWithZeroFallback.length - 1];
|
||||
const expected = Math.log(100) - Math.log(10);
|
||||
expect(calculateDefaultExpBucketWidth(lastBucket, bucketsWithZeroFallback)).toBeCloseTo(expected);
|
||||
const lastBucket = bucketsWithZeroFallback[bucketsWithZeroFallback.length - 1];
|
||||
const expected = Math.log(100) - Math.log(10);
|
||||
expect(calculateDefaultExpBucketWidth(lastBucket, bucketsWithZeroFallback)).toBeCloseTo(expected);
|
||||
});
|
||||
|
||||
it('throws an error if only a single [0, 0] bucket exists', () => {
|
||||
const lastBucket = singleZeroBucket[0];
|
||||
expect(() => calculateDefaultExpBucketWidth(lastBucket, singleZeroBucket)).toThrow(
|
||||
'Only one bucket in histogram ([-0, 0]). Cannot calculate defaultExpBucketWidth.'
|
||||
);
|
||||
const lastBucket = singleZeroBucket[0];
|
||||
expect(() => calculateDefaultExpBucketWidth(lastBucket, singleZeroBucket)).toThrow(
|
||||
'Only one bucket in histogram ([-0, 0]). Cannot calculate defaultExpBucketWidth.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('findMinPositive', () => {
|
||||
it('returns the first positive left bound when all are positive', () => {
|
||||
expect(findMinPositive(bucketsAllPositive)).toEqual(1);
|
||||
});
|
||||
it('returns the first positive left bound when all are positive', () => {
|
||||
expect(findMinPositive(bucketsAllPositive)).toEqual(1);
|
||||
});
|
||||
|
||||
it('returns the left bound when it is the first positive value', () => {
|
||||
expect(findMinPositive(bucketsNegThenPosNoCross)).toBe(5);
|
||||
|
|
@ -108,43 +106,42 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
|
||||
it('returns the right bound when the first bucket crosses zero', () => {
|
||||
expect(findMinPositive(bucketsStartingWithZeroCross)).toBe(1);
|
||||
expect(findMinPositive(bucketsStartingWithZeroCross)).toBe(1);
|
||||
});
|
||||
|
||||
it('returns the right bound when the last bucket crosses zero', () => {
|
||||
expect(findMinPositive(bucketsEndingWithZeroCross)).toBe(1);
|
||||
});
|
||||
|
||||
it('returns 0 when all buckets are negative', () => {
|
||||
expect(findMinPositive(bucketsAllNegative)).toBe(0);
|
||||
});
|
||||
it('returns 0 when all buckets are negative', () => {
|
||||
expect(findMinPositive(bucketsAllNegative)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns 0 for empty buckets', () => {
|
||||
expect(findMinPositive(emptyBuckets)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns 0 for only zero bucket', () => {
|
||||
expect(findMinPositive(singleZeroBucket)).toBe(0);
|
||||
});
|
||||
it('returns 0 for only zero bucket', () => {
|
||||
expect(findMinPositive(singleZeroBucket)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns 0 when buckets is undefined', () => {
|
||||
expect(findMinPositive(undefined as any)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns the correct positive bound with exact zero bucket present', () => {
|
||||
expect(findMinPositive(bucketsWithExactZeroBucket)).toBe(1);
|
||||
});
|
||||
it('returns the correct positive bound with exact zero bucket present', () => {
|
||||
expect(findMinPositive(bucketsWithExactZeroBucket)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('findMaxNegative', () => {
|
||||
it('returns 0 when all buckets are positive', () => {
|
||||
expect(findMaxNegative(bucketsAllPositive)).toBe(0);
|
||||
});
|
||||
it('returns 0 when all buckets are positive', () => {
|
||||
expect(findMaxNegative(bucketsAllPositive)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns the right bound of the last negative bucket when all are negative', () => {
|
||||
expect(findMaxNegative(bucketsAllNegative)).toEqual(-1);
|
||||
});
|
||||
it('returns the right bound of the last negative bucket when all are negative', () => {
|
||||
expect(findMaxNegative(bucketsAllNegative)).toEqual(-1);
|
||||
});
|
||||
|
||||
it('returns the right bound of the bucket before the middle zero-crossing bucket', () => {
|
||||
expect(findMaxNegative(bucketsCrossingZeroMid)).toEqual(-1);
|
||||
|
|
@ -155,7 +152,7 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
|
||||
it('returns the right bound of the bucket before the last zero-crossing bucket', () => {
|
||||
expect(findMaxNegative(bucketsEndingWithZeroCross)).toEqual(-1);
|
||||
expect(findMaxNegative(bucketsEndingWithZeroCross)).toEqual(-1);
|
||||
});
|
||||
|
||||
it('returns 0 for empty buckets', () => {
|
||||
|
|
@ -171,23 +168,28 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
|
||||
it('returns the right bound of the bucket before an exact zero bucket', () => {
|
||||
expect(findMaxNegative(bucketsWithExactZeroBucket)).toEqual(-1);
|
||||
expect(findMaxNegative(bucketsWithExactZeroBucket)).toEqual(-1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('findZeroBucket', () => {
|
||||
it('returns the index of bucket strictly containing zero', () => {
|
||||
expect(findZeroBucket(bucketsCrossingZeroMid)).toBe(2);
|
||||
});
|
||||
|
||||
it('returns the index of bucket with zero as left boundary', () => {
|
||||
const buckets: Bucket[] = [[0, '-5','-1', '10'], [0, '0', '5', '15']];
|
||||
const buckets: Bucket[] = [
|
||||
[0, '-5', '-1', '10'],
|
||||
[0, '0', '5', '15'],
|
||||
];
|
||||
expect(findZeroBucket(buckets)).toBe(1);
|
||||
});
|
||||
|
||||
it('returns the index of bucket with zero as right boundary', () => {
|
||||
const buckets: Bucket[] = [[0, '-5', '0', '10'], [0, '1', '5', '15']];
|
||||
const buckets: Bucket[] = [
|
||||
[0, '-5', '0', '10'],
|
||||
[0, '1', '5', '15'],
|
||||
];
|
||||
expect(findZeroBucket(buckets)).toBe(0);
|
||||
});
|
||||
|
||||
|
|
@ -208,49 +210,51 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
|
||||
it('returns 0 if the first bucket crosses zero', () => {
|
||||
expect(findZeroBucket(bucketsStartingWithZeroCross)).toBe(0);
|
||||
expect(findZeroBucket(bucketsStartingWithZeroCross)).toBe(0);
|
||||
});
|
||||
|
||||
it('returns the last index if the last bucket crosses zero', () => {
|
||||
expect(findZeroBucket(bucketsEndingWithZeroCross)).toBe(2);
|
||||
});
|
||||
it('returns the last index if the last bucket crosses zero', () => {
|
||||
expect(findZeroBucket(bucketsEndingWithZeroCross)).toBe(2);
|
||||
});
|
||||
|
||||
it('returns -1 when buckets array is empty', () => {
|
||||
expect(findZeroBucket(emptyBuckets)).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('findZeroAxisLeft', () => {
|
||||
it('calculates correctly for linear scale crossing zero', () => {
|
||||
const rangeMin = -100; const rangeMax = 100;
|
||||
const rangeMin = -100;
|
||||
const rangeMax = 100;
|
||||
const expected = '50%';
|
||||
const result = findZeroAxisLeft('linear', rangeMin, rangeMax, 1, -1, 2, 0, 0, 0);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('calculates correctly for asymmetric linear scale crossing zero', () => {
|
||||
const rangeMin = -10; const rangeMax = 90;
|
||||
const expectedNumber = ((0 - rangeMin) / (rangeMax - rangeMin)) * 100;
|
||||
const resultString = findZeroAxisLeft('linear', rangeMin, rangeMax, 1, -1, 0, 0, 0, 0);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
it('calculates correctly for asymmetric linear scale crossing zero', () => {
|
||||
const rangeMin = -10;
|
||||
const rangeMax = 90;
|
||||
const expectedNumber = ((0 - rangeMin) / (rangeMax - rangeMin)) * 100;
|
||||
const resultString = findZeroAxisLeft('linear', rangeMin, rangeMax, 1, -1, 0, 0, 0, 0);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
|
||||
it('calculates correctly for linear scale all positive (off-scale left)', () => {
|
||||
const rangeMin = 10; const rangeMax = 100;
|
||||
const rangeMin = 10;
|
||||
const rangeMax = 100;
|
||||
const expectedNumber = ((0 - rangeMin) / (rangeMax - rangeMin)) * 100;
|
||||
const resultString = findZeroAxisLeft('linear', rangeMin, rangeMax, 10, 0, -1, 0, 0, 0);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
|
||||
it('calculates correctly for linear scale all negative (off-scale right)', () => {
|
||||
const rangeMin = -100; const rangeMax = -10;
|
||||
const rangeMin = -100;
|
||||
const rangeMax = -10;
|
||||
const expectedNumber = ((0 - rangeMin) / (rangeMax - rangeMin)) * 100;
|
||||
const resultString = findZeroAxisLeft('linear', rangeMin, rangeMax, 0, -10, -1, 0, 0, 0);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
|
||||
|
||||
const expMinPos = 1;
|
||||
const expMaxNeg = -1;
|
||||
const expZeroIdx = 2;
|
||||
|
|
@ -264,22 +268,46 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
|
||||
it('returns 100% for exponential scale when minPositive is 0', () => {
|
||||
expect(findZeroAxisLeft('exponential', -100, -1, 0, -1, -1, expNegWidth, expNegWidth + defaultExpBW, defaultExpBW)).toEqual('100%');
|
||||
expect(
|
||||
findZeroAxisLeft('exponential', -100, -1, 0, -1, -1, expNegWidth, expNegWidth + defaultExpBW, defaultExpBW)
|
||||
).toEqual('100%');
|
||||
});
|
||||
|
||||
it('calculates position between buckets when zeroBucketIdx is -1 (exponential)', () => {
|
||||
const minPos = 5; const maxNeg = -1; const zeroIdx = -1;
|
||||
const minPos = 5;
|
||||
const maxNeg = -1;
|
||||
const zeroIdx = -1;
|
||||
const negW = Math.log(Math.abs(-1)) - Math.log(Math.abs(-10));
|
||||
const posW = Math.log(10) - Math.log(5);
|
||||
const totalW = Math.abs(negW) + posW + defaultExpBW;
|
||||
const expectedNumber = (Math.abs(negW) / totalW) * 100;
|
||||
const resultString = findZeroAxisLeft('exponential', -10, 10, minPos, maxNeg, zeroIdx, Math.abs(negW), totalW, defaultExpBW);
|
||||
const resultString = findZeroAxisLeft(
|
||||
'exponential',
|
||||
-10,
|
||||
10,
|
||||
minPos,
|
||||
maxNeg,
|
||||
zeroIdx,
|
||||
Math.abs(negW),
|
||||
totalW,
|
||||
defaultExpBW
|
||||
);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
|
||||
it('calculates position using bucket width when zeroBucketIdx exists (exponential)', () => {
|
||||
const expectedNumber = ((expNegWidth + 0.5 * defaultExpBW) / expTotalWidth) * 100;
|
||||
const resultString = findZeroAxisLeft('exponential', -100, 100, expMinPos, expMaxNeg, expZeroIdx, expNegWidth, expTotalWidth, defaultExpBW);
|
||||
const resultString = findZeroAxisLeft(
|
||||
'exponential',
|
||||
-100,
|
||||
100,
|
||||
expMinPos,
|
||||
expMaxNeg,
|
||||
expZeroIdx,
|
||||
expNegWidth,
|
||||
expTotalWidth,
|
||||
defaultExpBW
|
||||
);
|
||||
expect(parseFloat(resultString)).toBeCloseTo(expectedNumber, 1);
|
||||
});
|
||||
|
||||
|
|
@ -288,7 +316,6 @@ describe('HistogramHelpers', () => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe('showZeroAxis', () => {
|
||||
it('returns true when axis is between 5% and 95%', () => {
|
||||
expect(showZeroAxis('5.01%')).toBe(true);
|
||||
|
|
@ -308,4 +335,4 @@ describe('HistogramHelpers', () => {
|
|||
expect(showZeroAxis('120%')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -333,13 +333,13 @@ describe('Utils', () => {
|
|||
expect(parsePrometheusFloat('-1.7e+01')).toEqual(-17);
|
||||
});
|
||||
});
|
||||
describe('createExpressionLink',()=>{
|
||||
it('<....>builds link',()=>{
|
||||
describe('createExpressionLink', () => {
|
||||
it('<....>builds link', () => {
|
||||
expect(createExpressionLink('up')).toEqual(
|
||||
`../graph?g0.expr=up&g0.tab=1&g0.display_mode=${GraphDisplayMode.Lines}&g0.show_exemplars=0&g0.range_input=1h`
|
||||
);
|
||||
});
|
||||
it('url-encodes PromQL',() =>{
|
||||
it('url-encodes PromQL', () => {
|
||||
expect(createExpressionLink('ALERTS{alertname="HighCPU"}')).toEqual(
|
||||
`../graph?g0.expr=ALERTS%7Balertname%3D%22High%20CPU%22%7D&g0.tab=1&g0.display_mode=${GraphDisplayMode.Lines}&g0.show_exemplars=0&g0.range_input=1h`
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue