@perses-dev/components 0.54.0-beta.2 → 0.54.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/mathjs.js +14 -3
- package/dist/cjs/utils/regexp.js +54 -0
- package/dist/cjs/utils/request-interpolation.js +33 -1
- package/dist/cjs/utils/text.js +52 -0
- package/dist/cjs/utils/time-series-data.js +141 -0
- package/dist/cjs/utils/trace-data.js +25 -0
- package/dist/cjs/utils/transform-data.js +157 -0
- package/dist/cjs/utils/types.js +16 -0
- package/dist/cjs/utils/value-mapping.js +105 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mathjs.d.ts +8 -1
- package/dist/utils/mathjs.d.ts.map +1 -1
- package/dist/utils/mathjs.js +5 -2
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/regexp.d.ts +11 -0
- package/dist/utils/regexp.d.ts.map +1 -0
- package/dist/utils/regexp.js +42 -0
- package/dist/utils/regexp.js.map +1 -0
- package/dist/utils/request-interpolation.d.ts.map +1 -1
- package/dist/utils/request-interpolation.js +34 -2
- package/dist/utils/request-interpolation.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +39 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/time-series-data.d.ts +15 -0
- package/dist/utils/time-series-data.d.ts.map +1 -0
- package/dist/utils/time-series-data.js +130 -0
- package/dist/utils/time-series-data.js.map +1 -0
- package/dist/utils/trace-data.d.ts +37 -0
- package/dist/utils/trace-data.d.ts.map +1 -0
- package/dist/utils/trace-data.js +17 -0
- package/dist/utils/trace-data.js.map +1 -0
- package/dist/utils/transform-data.d.ts +7 -0
- package/dist/utils/transform-data.d.ts.map +1 -0
- package/dist/utils/transform-data.js +214 -0
- package/dist/utils/transform-data.js.map +1 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +15 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/value-mapping.d.ts +3 -0
- package/dist/utils/value-mapping.d.ts.map +1 -0
- package/dist/utils/value-mapping.js +97 -0
- package/dist/utils/value-mapping.js.map +1 -0
- package/package.json +2 -2
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './memo';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,0BAA0B;AACxC,cAAc,4BAA4B;AAC1C,cAAc,cAAc;AAC5B,cAAc,2BAA2B"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './memo';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\nexport * from './value-mapping';\nexport * from './regexp';\nexport * from './transform-data';\nexport * from './time-series-data';\nexport * from './trace-data';\nexport * from './types';\nexport * from './text';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,0BAA0B;AACxC,cAAc,4BAA4B;AAC1C,cAAc,cAAc;AAC5B,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,WAAW;AACzB,cAAc,mBAAmB;AACjC,cAAc,qBAAqB;AACnC,cAAc,eAAe;AAC7B,cAAc,UAAU;AACxB,cAAc,SAAS"}
|
package/dist/utils/mathjs.d.ts
CHANGED
|
@@ -2,5 +2,12 @@ declare const round: {
|
|
|
2
2
|
<T extends import("mathjs").MathNumericType | import("mathjs").MathCollection>(x: T, n?: number | import("mathjs").BigNumber | undefined): T extends number ? number : T extends string ? string : T extends boolean ? boolean : T;
|
|
3
3
|
<U extends import("mathjs").MathCollection>(x: import("mathjs").MathNumericType, n: U): U;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
declare const gcd: {
|
|
6
|
+
(...args: number[]): number;
|
|
7
|
+
(...args: import("mathjs").BigNumber[]): import("mathjs").BigNumber;
|
|
8
|
+
(...args: import("mathjs").Fraction[]): import("mathjs").Fraction;
|
|
9
|
+
(...args: import("mathjs").MathArray[]): import("mathjs").MathArray;
|
|
10
|
+
(...args: import("mathjs").Matrix[]): import("mathjs").Matrix;
|
|
11
|
+
};
|
|
12
|
+
export { round, gcd };
|
|
6
13
|
//# sourceMappingURL=mathjs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mathjs.d.ts","sourceRoot":"","sources":["../../src/utils/mathjs.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAQ,KAAK;;;CAAkC,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"mathjs.d.ts","sourceRoot":"","sources":["../../src/utils/mathjs.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAQ,KAAK;;;CAAkC,CAAC;AAChD,QAAA,MAAQ,GAAG;;;;;;CAAgC,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/utils/mathjs.js
CHANGED
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { roundDependencies, create } from 'mathjs';
|
|
13
|
+
import { roundDependencies, gcdDependencies, create } from 'mathjs';
|
|
14
14
|
// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)
|
|
15
15
|
const { round } = create({
|
|
16
16
|
roundDependencies
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
const { gcd } = create({
|
|
19
|
+
gcdDependencies
|
|
20
|
+
});
|
|
21
|
+
export { round, gcd };
|
|
19
22
|
|
|
20
23
|
//# sourceMappingURL=mathjs.js.map
|
package/dist/utils/mathjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/mathjs.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { roundDependencies, create } from 'mathjs';\n\n// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)\nconst { round } = create({ roundDependencies });\nexport { round };\n"],"names":["roundDependencies","create","round"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,MAAM,QAAQ,SAAS;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/mathjs.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { roundDependencies, gcdDependencies, create } from 'mathjs';\n\n// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)\nconst { round } = create({ roundDependencies });\nconst { gcd } = create({ gcdDependencies });\nexport { round, gcd };\n"],"names":["roundDependencies","gcdDependencies","create","round","gcd"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,MAAM,QAAQ,SAAS;AAEpE,uHAAuH;AACvH,MAAM,EAAEC,KAAK,EAAE,GAAGD,OAAO;IAAEF;AAAkB;AAC7C,MAAM,EAAEI,GAAG,EAAE,GAAGF,OAAO;IAAED;AAAgB;AACzC,SAASE,KAAK,EAAEC,GAAG,GAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a string is a regex pattern.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isRegexPattern(input: string | null | undefined): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Converts a string to RegExp. Handles both regular strings and regex patterns.
|
|
7
|
+
* For regular strings, creates exact match regex.
|
|
8
|
+
* For patterns like "/pattern/flags", creates corresponding RegExp.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createRegexFromString(input: string): RegExp;
|
|
11
|
+
//# sourceMappingURL=regexp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/utils/regexp.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAExE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAuB3D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a string is a regex pattern.
|
|
15
|
+
*/ export function isRegexPattern(input) {
|
|
16
|
+
return Boolean(input?.startsWith('/'));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts a string to RegExp. Handles both regular strings and regex patterns.
|
|
20
|
+
* For regular strings, creates exact match regex.
|
|
21
|
+
* For patterns like "/pattern/flags", creates corresponding RegExp.
|
|
22
|
+
*/ export function createRegexFromString(input) {
|
|
23
|
+
if (!input) {
|
|
24
|
+
throw new Error('Input string cannot be empty');
|
|
25
|
+
}
|
|
26
|
+
if (!isRegexPattern(input)) {
|
|
27
|
+
return new RegExp(`^${input}$`);
|
|
28
|
+
}
|
|
29
|
+
const regexPattern = /^\/(.+)\/([gimy]*)$/;
|
|
30
|
+
const matches = input.match(regexPattern);
|
|
31
|
+
if (!matches) {
|
|
32
|
+
throw new Error(`Invalid regular expression format: ${input}`);
|
|
33
|
+
}
|
|
34
|
+
const [, pattern = '', flags = ''] = matches;
|
|
35
|
+
try {
|
|
36
|
+
return new RegExp(pattern, flags);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Failed to create RegExp ${error}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=regexp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/regexp.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Checks if a string is a regex pattern.\n */\nexport function isRegexPattern(input: string | null | undefined): boolean {\n return Boolean(input?.startsWith('/'));\n}\n\n/**\n * Converts a string to RegExp. Handles both regular strings and regex patterns.\n * For regular strings, creates exact match regex.\n * For patterns like \"/pattern/flags\", creates corresponding RegExp.\n */\nexport function createRegexFromString(input: string): RegExp {\n if (!input) {\n throw new Error('Input string cannot be empty');\n }\n\n if (!isRegexPattern(input)) {\n return new RegExp(`^${input}$`);\n }\n\n const regexPattern = /^\\/(.+)\\/([gimy]*)$/;\n const matches = input.match(regexPattern);\n\n if (!matches) {\n throw new Error(`Invalid regular expression format: ${input}`);\n }\n\n const [, pattern = '', flags = ''] = matches;\n\n try {\n return new RegExp(pattern, flags);\n } catch (error) {\n throw new Error(`Failed to create RegExp ${error}`);\n }\n}\n"],"names":["isRegexPattern","input","Boolean","startsWith","createRegexFromString","Error","RegExp","regexPattern","matches","match","pattern","flags","error"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,SAASA,eAAeC,KAAgC;IAC7D,OAAOC,QAAQD,OAAOE,WAAW;AACnC;AAEA;;;;CAIC,GACD,OAAO,SAASC,sBAAsBH,KAAa;IACjD,IAAI,CAACA,OAAO;QACV,MAAM,IAAII,MAAM;IAClB;IAEA,IAAI,CAACL,eAAeC,QAAQ;QAC1B,OAAO,IAAIK,OAAO,CAAC,CAAC,EAAEL,MAAM,CAAC,CAAC;IAChC;IAEA,MAAMM,eAAe;IACrB,MAAMC,UAAUP,MAAMQ,KAAK,CAACF;IAE5B,IAAI,CAACC,SAAS;QACZ,MAAM,IAAIH,MAAM,CAAC,mCAAmC,EAAEJ,OAAO;IAC/D;IAEA,MAAM,GAAGS,UAAU,EAAE,EAAEC,QAAQ,EAAE,CAAC,GAAGH;IAErC,IAAI;QACF,OAAO,IAAIF,OAAOI,SAASC;IAC7B,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIP,MAAM,CAAC,wBAAwB,EAAEO,OAAO;IACpD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-interpolation.d.ts","sourceRoot":"","sources":["../../src/utils/request-interpolation.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"request-interpolation.d.ts","sourceRoot":"","sources":["../../src/utils/request-interpolation.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAEL,gBAAgB,EAGjB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAwCjE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,gBAAgB,GAAG,cAAc,CAMnH;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,gBAAgB,EAC7B,aAAa,EAAE,gBAAgB,GAC9B,gBAAgB,CAUlB"}
|
|
@@ -10,7 +10,39 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { replaceVariables } from './variable-interpolation';
|
|
13
|
+
import { replaceVariables, parseVariablesAndFormat, InterpolationFormat } from './variable-interpolation';
|
|
14
|
+
function expandQueryParamValue(value, variableState) {
|
|
15
|
+
// If value is an array, process each element
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map((v)=>expandQueryParamValue(v, variableState));
|
|
18
|
+
}
|
|
19
|
+
// Now we know value is a string, so we can safely use string methods
|
|
20
|
+
const valueString = value;
|
|
21
|
+
const variablesMap = parseVariablesAndFormat(valueString);
|
|
22
|
+
// Find the first multi-value variable that should expand to repeated keys
|
|
23
|
+
for (const [varName, format] of variablesMap){
|
|
24
|
+
const varState = variableState[varName];
|
|
25
|
+
if (!varState || !Array.isArray(varState.value)) continue;
|
|
26
|
+
// If format is queryparam or not specified (default for query params), expand to array
|
|
27
|
+
if (!format || format === InterpolationFormat.QUERYPARAM) {
|
|
28
|
+
// Build syntax patterns for this variable reference
|
|
29
|
+
const simpleSyntax = '$' + varName;
|
|
30
|
+
const bracketSyntax = format ? '${' + varName + ':' + format + '}' : '${' + varName + '}';
|
|
31
|
+
return varState.value.map((singleValue)=>{
|
|
32
|
+
let text = valueString;
|
|
33
|
+
// Replace the variable reference with the raw value directly.
|
|
34
|
+
// We cannot use replaceVariables here because it would apply QUERYPARAM format
|
|
35
|
+
// to the single value, producing "varName=val" instead of just "val".
|
|
36
|
+
text = text.replaceAll(bracketSyntax, singleValue);
|
|
37
|
+
text = text.replaceAll(simpleSyntax, singleValue);
|
|
38
|
+
// Replace any remaining variables (other than the expanded one) using standard interpolation
|
|
39
|
+
return replaceVariables(text, variableState);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// No multi-value expansion needed — use standard interpolation
|
|
44
|
+
return replaceVariables(valueString, variableState);
|
|
45
|
+
}
|
|
14
46
|
export function interpolateHeaders(headers, variableState) {
|
|
15
47
|
const result = {};
|
|
16
48
|
for (const [key, value] of Object.entries(headers)){
|
|
@@ -24,7 +56,7 @@ export function interpolateQueryParams(queryParams, variableState) {
|
|
|
24
56
|
if (Array.isArray(value)) {
|
|
25
57
|
result[key] = value.map((v)=>replaceVariables(v, variableState));
|
|
26
58
|
} else {
|
|
27
|
-
result[key] =
|
|
59
|
+
result[key] = expandQueryParamValue(value, variableState);
|
|
28
60
|
}
|
|
29
61
|
}
|
|
30
62
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/request-interpolation.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { RequestHeaders } from '@perses-dev/client';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/request-interpolation.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { RequestHeaders } from '@perses-dev/client';\nimport {\n replaceVariables,\n VariableStateMap,\n parseVariablesAndFormat,\n InterpolationFormat,\n} from './variable-interpolation';\n\nexport type QueryParamValues = Record<string, string | string[]>;\n\nfunction expandQueryParamValue(value: string | string[], variableState: VariableStateMap): string | string[] {\n // If value is an array, process each element\n if (Array.isArray(value)) {\n return value.map((v) => expandQueryParamValue(v, variableState) as string);\n }\n\n // Now we know value is a string, so we can safely use string methods\n const valueString = value as string;\n const variablesMap = parseVariablesAndFormat(valueString);\n\n // Find the first multi-value variable that should expand to repeated keys\n for (const [varName, format] of variablesMap) {\n const varState = variableState[varName];\n if (!varState || !Array.isArray(varState.value)) continue;\n\n // If format is queryparam or not specified (default for query params), expand to array\n if (!format || format === InterpolationFormat.QUERYPARAM) {\n // Build syntax patterns for this variable reference\n const simpleSyntax = '$' + varName;\n const bracketSyntax = format ? '${' + varName + ':' + format + '}' : '${' + varName + '}';\n\n return varState.value.map((singleValue) => {\n let text = valueString;\n // Replace the variable reference with the raw value directly.\n // We cannot use replaceVariables here because it would apply QUERYPARAM format\n // to the single value, producing \"varName=val\" instead of just \"val\".\n text = text.replaceAll(bracketSyntax, singleValue);\n text = text.replaceAll(simpleSyntax, singleValue);\n // Replace any remaining variables (other than the expanded one) using standard interpolation\n return replaceVariables(text, variableState);\n });\n }\n }\n\n // No multi-value expansion needed — use standard interpolation\n return replaceVariables(valueString, variableState);\n}\n\nexport function interpolateHeaders(headers: Record<string, string>, variableState: VariableStateMap): RequestHeaders {\n const result: RequestHeaders = {};\n for (const [key, value] of Object.entries(headers)) {\n result[key] = replaceVariables(value, variableState);\n }\n return result;\n}\n\nexport function interpolateQueryParams(\n queryParams: QueryParamValues,\n variableState: VariableStateMap\n): QueryParamValues {\n const result: QueryParamValues = {};\n for (const [key, value] of Object.entries(queryParams)) {\n if (Array.isArray(value)) {\n result[key] = value.map((v) => replaceVariables(v, variableState));\n } else {\n result[key] = expandQueryParamValue(value, variableState);\n }\n }\n return result;\n}\n"],"names":["replaceVariables","parseVariablesAndFormat","InterpolationFormat","expandQueryParamValue","value","variableState","Array","isArray","map","v","valueString","variablesMap","varName","format","varState","QUERYPARAM","simpleSyntax","bracketSyntax","singleValue","text","replaceAll","interpolateHeaders","headers","result","key","Object","entries","interpolateQueryParams","queryParams"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SACEA,gBAAgB,EAEhBC,uBAAuB,EACvBC,mBAAmB,QACd,2BAA2B;AAIlC,SAASC,sBAAsBC,KAAwB,EAAEC,aAA+B;IACtF,6CAA6C;IAC7C,IAAIC,MAAMC,OAAO,CAACH,QAAQ;QACxB,OAAOA,MAAMI,GAAG,CAAC,CAACC,IAAMN,sBAAsBM,GAAGJ;IACnD;IAEA,qEAAqE;IACrE,MAAMK,cAAcN;IACpB,MAAMO,eAAeV,wBAAwBS;IAE7C,0EAA0E;IAC1E,KAAK,MAAM,CAACE,SAASC,OAAO,IAAIF,aAAc;QAC5C,MAAMG,WAAWT,aAAa,CAACO,QAAQ;QACvC,IAAI,CAACE,YAAY,CAACR,MAAMC,OAAO,CAACO,SAASV,KAAK,GAAG;QAEjD,uFAAuF;QACvF,IAAI,CAACS,UAAUA,WAAWX,oBAAoBa,UAAU,EAAE;YACxD,oDAAoD;YACpD,MAAMC,eAAe,MAAMJ;YAC3B,MAAMK,gBAAgBJ,SAAS,OAAOD,UAAU,MAAMC,SAAS,MAAM,OAAOD,UAAU;YAEtF,OAAOE,SAASV,KAAK,CAACI,GAAG,CAAC,CAACU;gBACzB,IAAIC,OAAOT;gBACX,8DAA8D;gBAC9D,+EAA+E;gBAC/E,sEAAsE;gBACtES,OAAOA,KAAKC,UAAU,CAACH,eAAeC;gBACtCC,OAAOA,KAAKC,UAAU,CAACJ,cAAcE;gBACrC,6FAA6F;gBAC7F,OAAOlB,iBAAiBmB,MAAMd;YAChC;QACF;IACF;IAEA,+DAA+D;IAC/D,OAAOL,iBAAiBU,aAAaL;AACvC;AAEA,OAAO,SAASgB,mBAAmBC,OAA+B,EAAEjB,aAA+B;IACjG,MAAMkB,SAAyB,CAAC;IAChC,KAAK,MAAM,CAACC,KAAKpB,MAAM,IAAIqB,OAAOC,OAAO,CAACJ,SAAU;QAClDC,MAAM,CAACC,IAAI,GAAGxB,iBAAiBI,OAAOC;IACxC;IACA,OAAOkB;AACT;AAEA,OAAO,SAASI,uBACdC,WAA6B,EAC7BvB,aAA+B;IAE/B,MAAMkB,SAA2B,CAAC;IAClC,KAAK,MAAM,CAACC,KAAKpB,MAAM,IAAIqB,OAAOC,OAAO,CAACE,aAAc;QACtD,IAAItB,MAAMC,OAAO,CAACH,QAAQ;YACxBmB,MAAM,CAACC,IAAI,GAAGpB,MAAMI,GAAG,CAAC,CAACC,IAAMT,iBAAiBS,GAAGJ;QACrD,OAAO;YACLkB,MAAM,CAACC,IAAI,GAAGrB,sBAAsBC,OAAOC;QAC7C;IACF;IACA,OAAOkB;AACT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Resource } from '@perses-dev/client';
|
|
2
|
+
export declare function getResourceDisplayName<T extends Resource>(resource: T): string;
|
|
3
|
+
/**
|
|
4
|
+
* If the resource has a display name, return the resource display name with the resource name too
|
|
5
|
+
* Else, only return the resource name
|
|
6
|
+
*/
|
|
7
|
+
export declare function getResourceExtendedDisplayName<T extends Resource>(resource: T): string;
|
|
8
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAY9E;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAYtF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export function getResourceDisplayName(resource) {
|
|
14
|
+
// Variables
|
|
15
|
+
if (resource.spec?.spec?.display?.name) {
|
|
16
|
+
return resource.spec.spec.display.name;
|
|
17
|
+
}
|
|
18
|
+
// Other resources with display
|
|
19
|
+
if (resource.spec?.display?.name) {
|
|
20
|
+
return resource.spec.display.name;
|
|
21
|
+
}
|
|
22
|
+
return resource.metadata.name;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* If the resource has a display name, return the resource display name with the resource name too
|
|
26
|
+
* Else, only return the resource name
|
|
27
|
+
*/ export function getResourceExtendedDisplayName(resource) {
|
|
28
|
+
// Variables
|
|
29
|
+
if (resource.spec?.spec?.display?.name) {
|
|
30
|
+
return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
31
|
+
}
|
|
32
|
+
// Other resources with display
|
|
33
|
+
if (resource.spec?.display?.name) {
|
|
34
|
+
return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
35
|
+
}
|
|
36
|
+
return resource.metadata.name;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Resource } from '@perses-dev/client';\n\nexport function getResourceDisplayName<T extends Resource>(resource: T): string {\n // Variables\n if (resource.spec?.spec?.display?.name) {\n return resource.spec.spec.display.name;\n }\n\n // Other resources with display\n if (resource.spec?.display?.name) {\n return resource.spec.display.name;\n }\n\n return resource.metadata.name;\n}\n\n/**\n * If the resource has a display name, return the resource display name with the resource name too\n * Else, only return the resource name\n */\nexport function getResourceExtendedDisplayName<T extends Resource>(resource: T): string {\n // Variables\n if (resource.spec?.spec?.display?.name) {\n return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;\n }\n\n // Other resources with display\n if (resource.spec?.display?.name) {\n return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;\n }\n\n return resource.metadata.name;\n}\n"],"names":["getResourceDisplayName","resource","spec","display","name","metadata","getResourceExtendedDisplayName"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,SAASA,uBAA2CC,QAAW;IACpE,YAAY;IACZ,IAAIA,SAASC,IAAI,EAAEA,MAAMC,SAASC,MAAM;QACtC,OAAOH,SAASC,IAAI,CAACA,IAAI,CAACC,OAAO,CAACC,IAAI;IACxC;IAEA,+BAA+B;IAC/B,IAAIH,SAASC,IAAI,EAAEC,SAASC,MAAM;QAChC,OAAOH,SAASC,IAAI,CAACC,OAAO,CAACC,IAAI;IACnC;IAEA,OAAOH,SAASI,QAAQ,CAACD,IAAI;AAC/B;AAEA;;;CAGC,GACD,OAAO,SAASE,+BAAmDL,QAAW;IAC5E,YAAY;IACZ,IAAIA,SAASC,IAAI,EAAEA,MAAMC,SAASC,MAAM;QACtC,OAAO,GAAGH,SAASC,IAAI,CAACA,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,MAAM,EAAEH,SAASI,QAAQ,CAACD,IAAI,CAAC,CAAC,CAAC;IAC7E;IAEA,+BAA+B;IAC/B,IAAIH,SAASC,IAAI,EAAEC,SAASC,MAAM;QAChC,OAAO,GAAGH,SAASC,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,MAAM,EAAEH,SAASI,QAAQ,CAACD,IAAI,CAAC,CAAC,CAAC;IACxE;IAEA,OAAOH,SAASI,QAAQ,CAACD,IAAI;AAC/B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '@perses-dev/spec';
|
|
2
|
+
export declare const MIN_STEP_INTERVAL_MS = 10;
|
|
3
|
+
/**
|
|
4
|
+
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
5
|
+
* processes the time series values, filling in any timestamps that are missing
|
|
6
|
+
* from the time series data with `null` values.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale): TimeSeriesValueTuple[];
|
|
9
|
+
/**
|
|
10
|
+
* Given a list of running queries, calculates a common time scale for use on
|
|
11
|
+
* the x axis (i.e. start/end dates and a step that is divisible into all of
|
|
12
|
+
* the queries' steps).
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCommonTimeScale(seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>): TimeScale | undefined;
|
|
15
|
+
//# sourceMappingURL=time-series-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGlH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,oBAAoB,EAAE,CAyBpG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,GACzE,SAAS,GAAG,SAAS,CAgFvB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { gcd } from './mathjs';
|
|
14
|
+
export const MIN_STEP_INTERVAL_MS = 10;
|
|
15
|
+
/**
|
|
16
|
+
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
17
|
+
* processes the time series values, filling in any timestamps that are missing
|
|
18
|
+
* from the time series data with `null` values.
|
|
19
|
+
*/ export function getTimeSeriesValues(series, timeScale) {
|
|
20
|
+
let timestamp = timeScale.startMs;
|
|
21
|
+
const values = series.values;
|
|
22
|
+
const processedValues = [];
|
|
23
|
+
for (const valueTuple of values){
|
|
24
|
+
// Fill in values up to the current series value timestamp with nulls
|
|
25
|
+
while(timestamp < valueTuple[0]){
|
|
26
|
+
processedValues.push([
|
|
27
|
+
timestamp,
|
|
28
|
+
null
|
|
29
|
+
]);
|
|
30
|
+
timestamp += timeScale.stepMs;
|
|
31
|
+
}
|
|
32
|
+
// Now add the current value since timestamp should match
|
|
33
|
+
processedValues.push([
|
|
34
|
+
timestamp,
|
|
35
|
+
valueTuple[1]
|
|
36
|
+
]);
|
|
37
|
+
timestamp += timeScale.stepMs;
|
|
38
|
+
}
|
|
39
|
+
// Add null values at the end of the series if necessary
|
|
40
|
+
while(timestamp <= timeScale.endMs){
|
|
41
|
+
processedValues.push([
|
|
42
|
+
timestamp,
|
|
43
|
+
null
|
|
44
|
+
]);
|
|
45
|
+
timestamp += timeScale.stepMs;
|
|
46
|
+
}
|
|
47
|
+
return processedValues;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Given a list of running queries, calculates a common time scale for use on
|
|
51
|
+
* the x axis (i.e. start/end dates and a step that is divisible into all of
|
|
52
|
+
* the queries' steps).
|
|
53
|
+
*/ export function getCommonTimeScale(seriesData) {
|
|
54
|
+
let timeRange = undefined;
|
|
55
|
+
const steps = [];
|
|
56
|
+
for (const data of seriesData){
|
|
57
|
+
if (data && 'timeRange' in data) {
|
|
58
|
+
if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
|
|
59
|
+
// Keep track of query steps so we can calculate a common one for the graph
|
|
60
|
+
steps.push(data.stepMs);
|
|
61
|
+
// If we don't have an overall time range yet, just start with this one
|
|
62
|
+
if (timeRange === undefined) {
|
|
63
|
+
timeRange = data.timeRange;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Otherwise, see if this query has a start or end outside of the current
|
|
67
|
+
// time range
|
|
68
|
+
if (data.timeRange.start < timeRange.start) {
|
|
69
|
+
timeRange.start = data.timeRange.start;
|
|
70
|
+
}
|
|
71
|
+
if (data.timeRange.end > timeRange.end) {
|
|
72
|
+
timeRange.end = data.timeRange.end;
|
|
73
|
+
}
|
|
74
|
+
} else if (data && 'values' in data) {
|
|
75
|
+
for(let i = 0; i < data.values.length; i++){
|
|
76
|
+
const values = data.values[i];
|
|
77
|
+
if (values === undefined) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const [timestamp] = values;
|
|
81
|
+
const start = new Date(timestamp);
|
|
82
|
+
const end = new Date(timestamp);
|
|
83
|
+
if (timeRange === undefined) {
|
|
84
|
+
timeRange = {
|
|
85
|
+
start,
|
|
86
|
+
end
|
|
87
|
+
};
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (start < timeRange.start) {
|
|
91
|
+
timeRange.start = start;
|
|
92
|
+
}
|
|
93
|
+
if (end > timeRange.end) {
|
|
94
|
+
timeRange.end = end;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (timeRange === undefined) return undefined;
|
|
98
|
+
const startMs = timeRange.start.valueOf();
|
|
99
|
+
const endMs = timeRange.end.valueOf();
|
|
100
|
+
const rangeMs = endMs - startMs;
|
|
101
|
+
return {
|
|
102
|
+
startMs,
|
|
103
|
+
endMs,
|
|
104
|
+
rangeMs,
|
|
105
|
+
stepMs: MIN_STEP_INTERVAL_MS
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (timeRange === undefined) return undefined;
|
|
110
|
+
// Use the greatest common divisor of all step values as the overall step
|
|
111
|
+
// for the x axis (or if only one query, just use that query's step value)
|
|
112
|
+
let stepMs;
|
|
113
|
+
if (steps.length === 1) {
|
|
114
|
+
stepMs = steps[0];
|
|
115
|
+
} else {
|
|
116
|
+
const calculatedStepMs = gcd(...steps);
|
|
117
|
+
stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
|
|
118
|
+
}
|
|
119
|
+
const startMs = timeRange.start.valueOf();
|
|
120
|
+
const endMs = timeRange.end.valueOf();
|
|
121
|
+
const rangeMs = endMs - startMs;
|
|
122
|
+
return {
|
|
123
|
+
startMs,
|
|
124
|
+
endMs,
|
|
125
|
+
stepMs,
|
|
126
|
+
rangeMs
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=time-series-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '@perses-dev/spec';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * processes the time series values, filling in any timestamps that are missing\n * from the time series data with `null` values.\n */\nexport function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale): TimeSeriesValueTuple[] {\n let timestamp = timeScale.startMs;\n\n const values = series.values;\n const processedValues: TimeSeriesValueTuple[] = [];\n\n for (const valueTuple of values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n processedValues.push([timestamp, valueTuple[1]]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n return processedValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(\n seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>\n): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n\n for (const data of seriesData) {\n if (data && 'timeRange' in data) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n } else if (data && 'values' in data) {\n for (let i = 0; i < data.values.length; i++) {\n const values = data.values[i];\n if (values === undefined) {\n continue;\n }\n\n const [timestamp] = values;\n const start = new Date(timestamp);\n const end = new Date(timestamp);\n\n if (timeRange === undefined) {\n timeRange = {\n start,\n end,\n };\n continue;\n }\n\n if (start < timeRange.start) {\n timeRange.start = start;\n }\n\n if (end > timeRange.end) {\n timeRange.end = end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, rangeMs, stepMs: MIN_STEP_INTERVAL_MS };\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, stepMs, rangeMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getTimeSeriesValues","series","timeScale","timestamp","startMs","values","processedValues","valueTuple","push","stepMs","endMs","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","i","length","Date","valueOf","rangeMs","calculatedStepMs"],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseMetadata } from '@perses-dev/spec';
|
|
2
|
+
import { TracesData } from '@perses-dev/spec/dist/dashboard/query-type/otlp/trace/v1/trace';
|
|
3
|
+
/**
|
|
4
|
+
* Partial trace information returned by search endpoint
|
|
5
|
+
*/
|
|
6
|
+
export interface TraceSearchResult {
|
|
7
|
+
traceId: string;
|
|
8
|
+
rootServiceName: string;
|
|
9
|
+
rootTraceName: string;
|
|
10
|
+
startTimeUnixMs: number;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
serviceStats: Record<string, ServiceStats>;
|
|
13
|
+
}
|
|
14
|
+
export interface ServiceStats {
|
|
15
|
+
spanCount: number;
|
|
16
|
+
/** number of spans with errors, unset if zero */
|
|
17
|
+
errorCount?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A generalized data-model that will be used by Panel components
|
|
21
|
+
* to display traces.
|
|
22
|
+
*
|
|
23
|
+
* If the query contains a valid trace ID, the 'trace' attribute will contain the entire trace.
|
|
24
|
+
* If the query contains a TraceQL query, the 'searchResult' attribute will contain the search results.
|
|
25
|
+
*/
|
|
26
|
+
export interface TraceData {
|
|
27
|
+
trace?: TracesData;
|
|
28
|
+
searchResult?: TraceSearchResult[];
|
|
29
|
+
metadata?: TraceMetaData;
|
|
30
|
+
}
|
|
31
|
+
export interface TraceMetaData extends BaseMetadata {
|
|
32
|
+
/** this field indicates if there are more traces matching the search query, however not all traces were returned */
|
|
33
|
+
hasMoreResults?: boolean;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
export declare function isValidTraceId(traceId: string): boolean;
|
|
37
|
+
//# sourceMappingURL=trace-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-data.d.ts","sourceRoot":"","sources":["../../src/utils/trace-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gEAAgE,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEnC,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,oHAAoH;IACpH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export function isValidTraceId(traceId) {
|
|
14
|
+
return /^[0-9a-fA-F]+$/.test(traceId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=trace-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/trace-data.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BaseMetadata } from '@perses-dev/spec';\nimport { TracesData } from '@perses-dev/spec/dist/dashboard/query-type/otlp/trace/v1/trace';\n\n/**\n * Partial trace information returned by search endpoint\n */\nexport interface TraceSearchResult {\n traceId: string;\n rootServiceName: string;\n rootTraceName: string;\n startTimeUnixMs: number;\n durationMs: number;\n serviceStats: Record<string, ServiceStats>;\n}\n\nexport interface ServiceStats {\n spanCount: number;\n /** number of spans with errors, unset if zero */\n errorCount?: number;\n}\n\n/**\n * A generalized data-model that will be used by Panel components\n * to display traces.\n *\n * If the query contains a valid trace ID, the 'trace' attribute will contain the entire trace.\n * If the query contains a TraceQL query, the 'searchResult' attribute will contain the search results.\n */\nexport interface TraceData {\n trace?: TracesData;\n searchResult?: TraceSearchResult[];\n\n metadata?: TraceMetaData;\n}\n\nexport interface TraceMetaData extends BaseMetadata {\n /** this field indicates if there are more traces matching the search query, however not all traces were returned */\n hasMoreResults?: boolean;\n [key: string]: unknown;\n}\n\nexport function isValidTraceId(traceId: string): boolean {\n return /^[0-9a-fA-F]+$/.test(traceId);\n}\n"],"names":["isValidTraceId","traceId","test"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA2CjC,OAAO,SAASA,eAAeC,OAAe;IAC5C,OAAO,iBAAiBC,IAAI,CAACD;AAC/B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transform } from '../model';
|
|
2
|
+
export declare function applyJoinTransform(data: Array<Record<string, unknown>>, columns: string[]): Array<Record<string, unknown>>;
|
|
3
|
+
export declare function applyMergeColumnsTransform(data: Array<Record<string, unknown>>, selectedColumns: string[], outputName: string): Array<Record<string, unknown>>;
|
|
4
|
+
export declare function applyMergeIndexedColumnsTransform(data: Array<Record<string, unknown>>, column: string): Array<Record<string, unknown>>;
|
|
5
|
+
export declare function applyMergeSeriesTransform(data: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
|
|
6
|
+
export declare function transformData(data: Array<Record<string, unknown>>, transforms: Transform[]): Array<Record<string, unknown>>;
|
|
7
|
+
//# sourceMappingURL=transform-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-data.d.ts","sourceRoot":"","sources":["../../src/utils/transform-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAqBrC,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,OAAO,EAAE,MAAM,EAAE,GAChB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBhC;AA0BD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,eAAe,EAAE,MAAM,EAAE,EACzB,UAAU,EAAE,MAAM,GACjB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuBhC;AA0BD,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,MAAM,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAwBhC;AAmBD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAmB9G;AAKD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,UAAU,EAAE,SAAS,EAAE,GACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA2ChC"}
|