@oneuptime/common 14.1.0 → 14.2.0
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/Models/DatabaseModels/Alert.d.mts +1 -0
- package/Models/DatabaseModels/Alert.d.ts +1 -0
- package/Models/DatabaseModels/Alert.js +34 -0
- package/Models/DatabaseModels/AutoRemediationSuggestion.d.mts +2 -0
- package/Models/DatabaseModels/AutoRemediationSuggestion.d.ts +2 -0
- package/Models/DatabaseModels/AutoRemediationSuggestion.js +62 -0
- package/Models/DatabaseModels/Incident.d.mts +1 -0
- package/Models/DatabaseModels/Incident.d.ts +1 -0
- package/Models/DatabaseModels/Incident.js +35 -0
- package/Models/DatabaseModels/IncidentPostmortemActionItem.d.mts +31 -0
- package/Models/DatabaseModels/IncidentPostmortemActionItem.d.ts +31 -0
- package/Models/DatabaseModels/IncidentPostmortemActionItem.js +591 -0
- package/Models/DatabaseModels/IncidentPostmortemActionItem.mjs +3 -0
- package/Models/DatabaseModels/Index.js +2 -0
- package/Models/DatabaseModels/TelemetryIngestionKey.js +1 -1
- package/Types/AI/AIActionWords.d.mts +3 -1
- package/Types/AI/AIActionWords.d.ts +3 -1
- package/Types/AI/AIActionWords.js +70 -1
- package/Types/AI/AIActionWords.mjs +2 -0
- package/Types/AI/AIChatTypes.d.mts +2 -1
- package/Types/AI/AIChatTypes.d.ts +2 -1
- package/Types/AI/AIReadTableWords.d.mts +192 -0
- package/Types/AI/AIReadTableWords.d.ts +192 -0
- package/Types/AI/AIReadTableWords.js +368 -0
- package/Types/AI/AIReadTableWords.mjs +18 -0
- package/Types/AI/AiRunRefusal.d.mts +3 -0
- package/Types/AI/AiRunRefusal.d.ts +3 -0
- package/Types/AI/AiRunRefusal.js +22 -1
- package/Types/AI/ResourceAiAccessPermissions.js +7 -18
- package/Types/AuditLog/AuditLogActionLabel.js +19 -9
- package/Types/BaseDatabase/AggregationIntervalUtil.d.mts +16 -0
- package/Types/BaseDatabase/AggregationIntervalUtil.d.ts +16 -0
- package/Types/BaseDatabase/AggregationIntervalUtil.js +123 -16
- package/Types/Cloud/CloudResourceHealth.d.mts +30 -1
- package/Types/Cloud/CloudResourceHealth.d.ts +30 -1
- package/Types/Cloud/CloudResourceHealth.js +405 -13
- package/Types/Cloud/CloudResourceHealth.mjs +28 -0
- package/Types/DataObservability/DataCheckRefusals.d.mts +32 -0
- package/Types/DataObservability/DataCheckRefusals.d.ts +32 -0
- package/Types/DataObservability/DataCheckRefusals.js +77 -0
- package/Types/DataObservability/DataCheckRefusals.mjs +8 -0
- package/Types/Database/AccessControl/PermissionScopeNarrowing.js +4 -0
- package/Types/Date.d.mts +2 -0
- package/Types/Date.d.ts +2 -0
- package/Types/Date.js +22 -0
- package/Types/DateLanguage.d.mts +2 -0
- package/Types/DateLanguage.d.ts +2 -0
- package/Types/DateLanguage.js +8 -5
- package/Types/Email/EmailTemplateType.d.mts +1 -0
- package/Types/Email/EmailTemplateType.d.ts +1 -0
- package/Types/Email/EmailTemplateType.js +2 -0
- package/Types/Exception/EgressGuardException.js +1 -1
- package/Types/Exception/ErrorMessageRule.d.mts +1 -0
- package/Types/Exception/ErrorMessageRule.d.ts +1 -0
- package/Types/Exception/ErrorMessageRule.js +67 -13
- package/Types/Exception/ErrorMessageRule.mjs +1 -0
- package/Types/Exception/ExceptionMessages.d.mts +2 -0
- package/Types/Exception/ExceptionMessages.d.ts +2 -0
- package/Types/Exception/ExceptionMessages.js +2 -0
- package/Types/Incident/PostmortemActionItemStatus.d.mts +17 -0
- package/Types/Incident/PostmortemActionItemStatus.d.ts +17 -0
- package/Types/Incident/PostmortemActionItemStatus.js +74 -0
- package/Types/Incident/PostmortemActionItemStatus.mjs +5 -0
- package/Types/JSONFunctions.js +10 -3
- package/Types/Link.d.mts +1 -0
- package/Types/Link.d.ts +1 -0
- package/Types/MeaningKeys.d.mts +4 -0
- package/Types/MeaningKeys.d.ts +4 -0
- package/Types/MeaningKeys.js +74 -0
- package/Types/MeaningKeys.mjs +5 -0
- package/Types/Monitor/WhoIsTold.d.mts +3 -0
- package/Types/Monitor/WhoIsTold.d.ts +3 -0
- package/Types/Monitor/WhoIsTold.js +63 -13
- package/Types/NoBreakSpaces.d.mts +16 -0
- package/Types/NoBreakSpaces.d.ts +16 -0
- package/Types/NoBreakSpaces.js +419 -0
- package/Types/NoBreakSpaces.mjs +9 -0
- package/Types/NotificationRule/PagingLadder.d.mts +12 -0
- package/Types/NotificationRule/PagingLadder.d.ts +12 -0
- package/Types/NotificationRule/PagingLadder.js +159 -11
- package/Types/NotificationRule/PagingLadder.mjs +3 -0
- package/Types/OnCallDutyPolicy/OnCallPageRecordGone.d.mts +3 -0
- package/Types/OnCallDutyPolicy/OnCallPageRecordGone.d.ts +3 -0
- package/Types/OnCallDutyPolicy/OnCallPageRecordGone.js +42 -0
- package/Types/OnCallDutyPolicy/OnCallPageRecordGone.mjs +4 -0
- package/Types/OnCallDutyPolicy/OnCallPageWords.d.mts +6 -2
- package/Types/OnCallDutyPolicy/OnCallPageWords.d.ts +6 -2
- package/Types/OnCallDutyPolicy/OnCallPageWords.js +21 -20
- package/Types/OnCallDutyPolicy/OnCallPersonPage.d.mts +4 -0
- package/Types/OnCallDutyPolicy/OnCallPersonPage.d.ts +4 -0
- package/Types/OnCallDutyPolicy/OnCallPersonPage.js +125 -1
- package/Types/OnCallDutyPolicy/OnCallPersonPage.mjs +1 -0
- package/Types/OnCallDutyPolicy/OnCallTestPage.d.mts +2 -0
- package/Types/OnCallDutyPolicy/OnCallTestPage.d.ts +2 -0
- package/Types/OnCallDutyPolicy/OnCallTestPage.js +12 -0
- package/Types/OnCallDutyPolicy/OnCallTestPage.mjs +1 -0
- package/Types/OpenStack/OpenStackCapacity.js +12 -5
- package/Types/Permission.d.mts +4 -0
- package/Types/Permission.d.ts +4 -0
- package/Types/Permission.js +64 -8
- package/Types/Product/ProductUsage.js +2 -1
- package/Types/Product/ProjectProductsAnswer.js +2 -1
- package/Types/ResourceAiAgent/AiResourceType.d.mts +1 -0
- package/Types/ResourceAiAgent/AiResourceType.d.ts +1 -0
- package/Types/ResourceAiAgent/AiResourceType.js +12 -0
- package/Types/Rum/ProductAnalyticsEventReads.js +10 -1
- package/Types/Rum/ProductAnalyticsEvents.js +13 -1
- package/Types/Rum/SessionReplayCustomEvents.d.mts +4 -1
- package/Types/Rum/SessionReplayCustomEvents.d.ts +4 -1
- package/Types/Rum/SessionReplayCustomEvents.js +12 -0
- package/Types/Rum/SessionReplayCustomEvents.mjs +1 -0
- package/Types/SetupHealth/SetupHealth.d.mts +1 -0
- package/Types/SetupHealth/SetupHealth.d.ts +1 -0
- package/Types/SetupHealth/SetupHealth.js +13 -5
- package/Types/StatusPage/DefaultStatusNames.d.mts +11 -3
- package/Types/StatusPage/DefaultStatusNames.d.ts +11 -3
- package/Types/StatusPage/DefaultStatusNames.js +74 -28
- package/Types/StatusPage/DefaultStatusNames.mjs +9 -2
- package/Types/StatusPage/StateChangeNoteMessage.d.mts +3 -2
- package/Types/StatusPage/StateChangeNoteMessage.d.ts +3 -2
- package/Types/StatusPage/StateChangeNoteMessage.js +16 -13
- package/Types/Telemetry/TelemetryIngestionKeyType.js +7 -6
- package/Types/Translator.d.mts +1 -0
- package/Types/Translator.d.ts +1 -0
- package/Types/Translator.js +100 -19
- package/Types/Translator.mjs +1 -0
- package/Types/UserSession/SessionLength.d.mts +33 -0
- package/Types/UserSession/SessionLength.d.ts +33 -0
- package/Types/UserSession/SessionLength.js +134 -5
- package/Types/UserSession/SessionLength.mjs +5 -0
- package/Types/Workflow/WorkflowStatus.js +21 -10
- package/Utils/AI/InvestigationReport.js +2 -2
- package/Utils/API.d.mts +0 -11
- package/Utils/API.d.ts +0 -11
- package/Utils/API.js +0 -432
- package/Utils/AiRemediation/Resource/ResourceCommandPolicy.js +2 -2
- package/Utils/AiRemediation/VerifiedFixRunbook.d.mts +39 -0
- package/Utils/AiRemediation/VerifiedFixRunbook.d.ts +39 -0
- package/Utils/AiRemediation/VerifiedFixRunbook.js +231 -0
- package/Utils/AiRemediation/VerifiedFixRunbook.mjs +10 -0
- package/Utils/Dashboard/DashboardWidgetSorts.js +11 -2
- package/Utils/Dashboard/MonitorListWidgetFormat.d.mts +2 -1
- package/Utils/Dashboard/MonitorListWidgetFormat.d.ts +2 -1
- package/Utils/Dashboard/MonitorListWidgetFormat.js +5 -3
- package/Utils/DefaultRecordNames.d.mts +6 -0
- package/Utils/DefaultRecordNames.d.ts +6 -0
- package/Utils/DefaultRecordNames.js +122 -0
- package/Utils/DefaultRecordNames.mjs +6 -0
- package/Utils/Grok/Grok.js +7 -4
- package/Utils/Incident/PostmortemActionItemCodeTask.d.mts +20 -0
- package/Utils/Incident/PostmortemActionItemCodeTask.d.ts +20 -0
- package/Utils/Incident/PostmortemActionItemCodeTask.js +107 -0
- package/Utils/Incident/PostmortemActionItemCodeTask.mjs +10 -0
- package/Utils/Incident/PostmortemActionItemMarkdown.d.mts +39 -0
- package/Utils/Incident/PostmortemActionItemMarkdown.d.ts +39 -0
- package/Utils/Incident/PostmortemActionItemMarkdown.js +118 -0
- package/Utils/Incident/PostmortemActionItemMarkdown.mjs +12 -0
- package/Utils/Incident/PostmortemNoteActionItems.d.mts +29 -0
- package/Utils/Incident/PostmortemNoteActionItems.d.ts +29 -0
- package/Utils/Incident/PostmortemNoteActionItems.js +544 -0
- package/Utils/Incident/PostmortemNoteActionItems.mjs +7 -0
- package/Utils/LookupTable.d.mts +3 -0
- package/Utils/LookupTable.d.ts +3 -0
- package/Utils/LookupTable.js +61 -0
- package/Utils/LookupTable.mjs +3 -0
- package/Utils/Markdown/LinkReferenceDefinitions.d.mts +2 -0
- package/Utils/Markdown/LinkReferenceDefinitions.d.ts +2 -0
- package/Utils/Markdown/LinkReferenceDefinitions.js +101 -1
- package/Utils/Markdown/LinkReferenceDefinitions.mjs +2 -0
- package/Utils/Markdown/OverLongText.js +296 -2
- package/Utils/Markdown/SlowMarkdown.d.mts +1 -0
- package/Utils/Markdown/SlowMarkdown.d.ts +1 -0
- package/Utils/Markdown/SlowMarkdown.js +354 -4
- package/Utils/Markdown/SlowMarkdown.mjs +1 -0
- package/Utils/Metrics/MetricFormulaEvaluator.js +10 -4
- package/Utils/Metrics/MetricSeriesFingerprint.js +13 -4
- package/Utils/Metrics/MetricSeriesScope.d.mts +5 -0
- package/Utils/Metrics/MetricSeriesScope.d.ts +5 -0
- package/Utils/Metrics/MetricSeriesScope.js +5 -1
- package/Utils/Monitor/MonitorRootCauseWording.d.mts +3 -0
- package/Utils/Monitor/MonitorRootCauseWording.d.ts +3 -0
- package/Utils/Monitor/MonitorRootCauseWording.js +100 -11
- package/Utils/Monitor/ProbeAgreementRule.d.mts +10 -0
- package/Utils/Monitor/ProbeAgreementRule.d.ts +10 -0
- package/Utils/Monitor/ProbeAgreementRule.js +58 -0
- package/Utils/Monitor/ProbeAgreementRule.mjs +3 -0
- package/Utils/Monitor/ProbeFailureReading.d.mts +4 -0
- package/Utils/Monitor/ProbeFailureReading.d.ts +4 -0
- package/Utils/Monitor/ProbeFailureReading.js +30 -1
- package/Utils/Monitor/ProbeFailureReading.mjs +1 -0
- package/Utils/Monitor/RequestFailureDescriptions.d.mts +61 -0
- package/Utils/Monitor/RequestFailureDescriptions.d.ts +61 -0
- package/Utils/Monitor/RequestFailureDescriptions.js +252 -0
- package/Utils/Monitor/RequestFailureDescriptions.mjs +6 -0
- package/Utils/PromQL/PromQLEngine.js +18 -9
- package/Utils/PromQL/PromQLFunctionEvaluators.js +114 -58
- package/Utils/PromQL/PromQLLabelOrder.d.mts +8 -0
- package/Utils/PromQL/PromQLLabelOrder.d.ts +8 -0
- package/Utils/PromQL/PromQLLabelOrder.js +212 -0
- package/Utils/PromQL/PromQLLabelOrder.mjs +6 -0
- package/Utils/PromQL/PromQLLabels.js +4 -3
- package/Utils/PromQL/PromQLMetricNames.js +8 -2
- package/Utils/PromQL/PromQLParser.js +11 -6
- package/Utils/PromQL/PromQLRegex.d.mts +11 -0
- package/Utils/PromQL/PromQLRegex.d.ts +11 -0
- package/Utils/PromQL/PromQLRegex.js +990 -50
- package/Utils/PromQL/PromQLRegex.mjs +3 -0
- package/Utils/PromQL/PrometheusResponse.js +3 -1
- package/Utils/PromQL/RE2CharacterClass.d.mts +24 -0
- package/Utils/PromQL/RE2CharacterClass.d.ts +24 -0
- package/Utils/PromQL/RE2CharacterClass.js +532 -0
- package/Utils/PromQL/RE2CharacterClass.mjs +16 -0
- package/Utils/RequestFailedDetailsUtil.d.mts +15 -0
- package/Utils/RequestFailedDetailsUtil.d.ts +15 -0
- package/Utils/RequestFailedDetailsUtil.js +452 -0
- package/Utils/RequestFailedDetailsUtil.mjs +2 -0
- package/Utils/Rum/UrlScrubber.d.mts +1 -1
- package/Utils/Rum/UrlScrubber.d.ts +1 -1
- package/Utils/Rum/UrlScrubber.js +10 -4
- package/Utils/Rum/UserFlow.js +22 -4
- package/Utils/SecurityCase/SecurityOverviewMetrics.d.mts +11 -1
- package/Utils/SecurityCase/SecurityOverviewMetrics.d.ts +11 -1
- package/Utils/SecurityCase/SecurityOverviewMetrics.js +99 -17
- package/Utils/SecurityCase/SecurityOverviewMetrics.mjs +3 -0
- package/Utils/Sms/OnCallPageSms.d.mts +2 -0
- package/Utils/Sms/OnCallPageSms.d.ts +2 -0
- package/Utils/Sms/OnCallPageSms.js +3 -1
- package/Utils/StateListType.d.mts +11 -0
- package/Utils/StateListType.d.ts +11 -0
- package/Utils/StateListType.js +21 -0
- package/Utils/StateListType.mjs +2 -0
- package/Utils/StateOrder.d.mts +8 -11
- package/Utils/StateOrder.d.ts +8 -11
- package/Utils/StateOrder.js +49 -84
- package/Utils/StateOrder.mjs +2 -0
- package/Utils/Suggestions/ActionItemCodeTaskSuggestion.d.mts +9 -0
- package/Utils/Suggestions/ActionItemCodeTaskSuggestion.d.ts +9 -0
- package/Utils/Suggestions/ActionItemCodeTaskSuggestion.js +25 -0
- package/Utils/Suggestions/ActionItemCodeTaskSuggestion.mjs +2 -0
- package/Utils/Suggestions/VerifiedFixRunbookSuggestion.d.mts +5 -0
- package/Utils/Suggestions/VerifiedFixRunbookSuggestion.d.ts +5 -0
- package/Utils/Suggestions/VerifiedFixRunbookSuggestion.js +39 -0
- package/Utils/Suggestions/VerifiedFixRunbookSuggestion.mjs +2 -0
- package/Utils/Syslog/SyslogMessageParser.js +16 -6
- package/Utils/Telemetry/HeartbeatAvailability.js +16 -21
- package/Utils/ValueFormatter.d.mts +1 -0
- package/Utils/ValueFormatter.d.ts +1 -0
- package/Utils/ValueFormatter.js +258 -18
- package/package.json +1 -1
|
@@ -38,9 +38,11 @@ const PromQLAst_1 = require("./PromQLAst");
|
|
|
38
38
|
const PromQLError_1 = __importStar(require("./PromQLError"));
|
|
39
39
|
const PromQLLabels_1 = require("./PromQLLabels");
|
|
40
40
|
const PromQLMath_1 = require("./PromQLMath");
|
|
41
|
+
const PromQLLabelOrder_1 = require("./PromQLLabelOrder");
|
|
42
|
+
const PromQLParser_1 = require("./PromQLParser");
|
|
41
43
|
const PromQLRegex_1 = require("./PromQLRegex");
|
|
42
|
-
const PatternCache_1 = require("../LinearRegExp/PatternCache");
|
|
43
44
|
const PatternProblem_1 = require("../LinearRegExp/PatternProblem");
|
|
45
|
+
const LookupTable_1 = __importStar(require("../LookupTable"));
|
|
44
46
|
const vectorValue = (samples) => {
|
|
45
47
|
return { type: PromQLAst_1.PromQLValueType.InstantVector, samples };
|
|
46
48
|
};
|
|
@@ -81,7 +83,12 @@ const mapValues = (samples, timestampMs, transform) => {
|
|
|
81
83
|
};
|
|
82
84
|
});
|
|
83
85
|
};
|
|
84
|
-
|
|
86
|
+
/*
|
|
87
|
+
* This table, OVER_TIME and DATE_FUNCTIONS are read by the name a query
|
|
88
|
+
* calls, so they are Maps: each answers only for the functions it lists,
|
|
89
|
+
* never with what every object inherits.
|
|
90
|
+
*/
|
|
91
|
+
const SIMPLE_FUNCTIONS = (0, LookupTable_1.default)({
|
|
85
92
|
abs: Math.abs,
|
|
86
93
|
acos: Math.acos,
|
|
87
94
|
acosh: Math.acosh,
|
|
@@ -114,7 +121,7 @@ const SIMPLE_FUNCTIONS = {
|
|
|
114
121
|
sqrt: Math.sqrt,
|
|
115
122
|
tan: Math.tan,
|
|
116
123
|
tanh: Math.tanh,
|
|
117
|
-
};
|
|
124
|
+
});
|
|
118
125
|
/*
|
|
119
126
|
* rate(), increase() and delta(): the change across the range, extrapolated
|
|
120
127
|
* to the range's edges the way Prometheus extrapolates it, with counter
|
|
@@ -206,7 +213,7 @@ const average = (values) => {
|
|
|
206
213
|
* The functions that read a range vector and answer with one value per
|
|
207
214
|
* series. Undefined means "no value for this series at this step".
|
|
208
215
|
*/
|
|
209
|
-
const OVER_TIME = {
|
|
216
|
+
const OVER_TIME = (0, LookupTable_1.default)({
|
|
210
217
|
avg_over_time: (series) => {
|
|
211
218
|
return average(series.values);
|
|
212
219
|
},
|
|
@@ -301,12 +308,12 @@ const OVER_TIME = {
|
|
|
301
308
|
irate: (series) => {
|
|
302
309
|
return instantValue(series, true);
|
|
303
310
|
},
|
|
304
|
-
};
|
|
311
|
+
});
|
|
305
312
|
// The functions whose answer keeps the input's metric name.
|
|
306
313
|
const KEEPS_METRIC_NAME = new Set([
|
|
307
314
|
"last_over_time",
|
|
308
315
|
]);
|
|
309
|
-
const DATE_FUNCTIONS = {
|
|
316
|
+
const DATE_FUNCTIONS = (0, LookupTable_1.default)({
|
|
310
317
|
day_of_month: (date) => {
|
|
311
318
|
return date.getUTCDate();
|
|
312
319
|
},
|
|
@@ -332,40 +339,94 @@ const DATE_FUNCTIONS = {
|
|
|
332
339
|
year: (date) => {
|
|
333
340
|
return date.getUTCFullYear();
|
|
334
341
|
},
|
|
342
|
+
});
|
|
343
|
+
/*
|
|
344
|
+
* Labels Prometheus never writes into absent()'s answer (schema.IsMetadataLabel):
|
|
345
|
+
* the metric name, and the type and unit of its type-and-unit labels.
|
|
346
|
+
*/
|
|
347
|
+
const ABSENT_METADATA_LABELS = new Set([
|
|
348
|
+
PromQLAst_1.PROMQL_METRIC_NAME_LABEL,
|
|
349
|
+
"__type__",
|
|
350
|
+
"__unit__",
|
|
351
|
+
]);
|
|
352
|
+
/*
|
|
353
|
+
* A selector's matchers in the order Prometheus' storage leaves them in.
|
|
354
|
+
* Reading a selector, the TSDB sorts its matchers in place, the syntax
|
|
355
|
+
* tree's own (tsdb.PostingsForMatchers): those that pick series out first,
|
|
356
|
+
* those that take series away after, each kind in the order it was written.
|
|
357
|
+
* A matcher takes away when it is != or !~ and an empty value passes it, or
|
|
358
|
+
* when no matcher on its label needs the label set. absent() reads the
|
|
359
|
+
* matchers after that, so `x{job!="b", job="a"}` is read as
|
|
360
|
+
* `x{job="a", job!="b"}`.
|
|
361
|
+
*
|
|
362
|
+
* (A Prometheus that stores no data in the query's time range reads no
|
|
363
|
+
* index, so nothing sorts the matchers, and it answers in the written order:
|
|
364
|
+
* there, x{job!="b", job="a"} answers {job="a"}. A server that scrapes
|
|
365
|
+
* anything stores its latest data, so the sorted order is the one absent()
|
|
366
|
+
* alerts see.)
|
|
367
|
+
*/
|
|
368
|
+
const matchersInStorageOrder = (matchers) => {
|
|
369
|
+
const labelMustBeSet = new Set();
|
|
370
|
+
for (const matcher of matchers) {
|
|
371
|
+
if (!(0, PromQLParser_1.matchesEmptyValue)(matcher)) {
|
|
372
|
+
labelMustBeSet.add(matcher.name);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const takesAway = (matcher) => {
|
|
376
|
+
if (!labelMustBeSet.has(matcher.name)) {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
return ((matcher.type === PromQLAst_1.PromQLMatchType.NotEqual ||
|
|
380
|
+
matcher.type === PromQLAst_1.PromQLMatchType.RegexNoMatch) &&
|
|
381
|
+
(0, PromQLParser_1.matchesEmptyValue)(matcher));
|
|
382
|
+
};
|
|
383
|
+
return [
|
|
384
|
+
...matchers.filter((matcher) => {
|
|
385
|
+
return !takesAway(matcher);
|
|
386
|
+
}),
|
|
387
|
+
...matchers.filter(takesAway),
|
|
388
|
+
];
|
|
335
389
|
};
|
|
336
390
|
/*
|
|
337
|
-
* The labels absent() and absent_over_time() give their 1
|
|
338
|
-
*
|
|
339
|
-
*
|
|
391
|
+
* The labels absent() and absent_over_time() give their 1, as Prometheus
|
|
392
|
+
* derives them (createLabelsForAbsentFunction, promql/functions.go): the
|
|
393
|
+
* selector's matchers in the order its storage leaves them in
|
|
394
|
+
* (matchersInStorageOrder), the first = on a label setting it, and any other
|
|
395
|
+
* matcher on it, a second = among them, deleting it. A label deleted before
|
|
396
|
+
* it is set is set. So x{job="a", job!="b"} answers {}, x{job=~"a",
|
|
397
|
+
* job="a"} answers {job="a"}, and x{job="a", job="b"} answers {}, since no
|
|
398
|
+
* one value is right. An empty value is no label. Anything but a selector,
|
|
399
|
+
* once its parentheses are read through as Prometheus reads them, names no
|
|
400
|
+
* labels.
|
|
340
401
|
*/
|
|
341
402
|
const absentLabels = (expression) => {
|
|
403
|
+
let argument = expression;
|
|
404
|
+
while (argument.kind === PromQLAst_1.PromQLNodeKind.Paren) {
|
|
405
|
+
argument = argument.expression;
|
|
406
|
+
}
|
|
342
407
|
let selectorMatchers = [];
|
|
343
|
-
if (
|
|
344
|
-
selectorMatchers =
|
|
408
|
+
if (argument.kind === PromQLAst_1.PromQLNodeKind.VectorSelector) {
|
|
409
|
+
selectorMatchers = argument.matchers;
|
|
345
410
|
}
|
|
346
|
-
else if (
|
|
347
|
-
selectorMatchers =
|
|
411
|
+
else if (argument.kind === PromQLAst_1.PromQLNodeKind.MatrixSelector) {
|
|
412
|
+
selectorMatchers = argument.vectorSelector
|
|
348
413
|
.matchers;
|
|
349
414
|
}
|
|
350
415
|
const labels = {};
|
|
351
|
-
const
|
|
352
|
-
for (const matcher of selectorMatchers) {
|
|
353
|
-
if (matcher.
|
|
354
|
-
matcher.name === PromQLAst_1.PROMQL_METRIC_NAME_LABEL) {
|
|
416
|
+
const set = new Set();
|
|
417
|
+
for (const matcher of matchersInStorageOrder(selectorMatchers)) {
|
|
418
|
+
if (ABSENT_METADATA_LABELS.has(matcher.name)) {
|
|
355
419
|
continue;
|
|
356
420
|
}
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
for (const name of Object.keys(labels)) {
|
|
366
|
-
if (labels[name] === "") {
|
|
367
|
-
delete labels[name];
|
|
421
|
+
if (matcher.type === PromQLAst_1.PromQLMatchType.Equal && !set.has(matcher.name)) {
|
|
422
|
+
set.add(matcher.name);
|
|
423
|
+
if (matcher.value !== "") {
|
|
424
|
+
// As an own key: a selector may pin a label named __proto__.
|
|
425
|
+
(0, LookupTable_1.writeOwnValue)(labels, matcher.name, matcher.value);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
368
428
|
}
|
|
429
|
+
delete labels[matcher.name];
|
|
369
430
|
}
|
|
370
431
|
return labels;
|
|
371
432
|
};
|
|
@@ -376,7 +437,7 @@ const DIGITS_ONLY_REGEX = /^\d+$/;
|
|
|
376
437
|
* text, `$$` a dollar sign. As in Go, `$1x` names the group "1x", which does
|
|
377
438
|
* not exist, so write `${1}x`.
|
|
378
439
|
*/
|
|
379
|
-
const expandTemplate = (template, match) => {
|
|
440
|
+
const expandTemplate = (template, match, groupNames) => {
|
|
380
441
|
let result = "";
|
|
381
442
|
let index = 0;
|
|
382
443
|
while (index < template.length) {
|
|
@@ -422,7 +483,12 @@ const expandTemplate = (template, match) => {
|
|
|
422
483
|
result += (group === 0 ? match.value : match.captures[group - 1]) || "";
|
|
423
484
|
}
|
|
424
485
|
else {
|
|
425
|
-
result +=
|
|
486
|
+
result +=
|
|
487
|
+
(0, PromQLRegex_1.readNamedCapture)({
|
|
488
|
+
captures: match.captures,
|
|
489
|
+
groupNames: groupNames,
|
|
490
|
+
name: name,
|
|
491
|
+
}) || "";
|
|
426
492
|
}
|
|
427
493
|
index = end;
|
|
428
494
|
}
|
|
@@ -440,20 +506,17 @@ const sortSamples = (samples, descending) => {
|
|
|
440
506
|
return descending ? b.value - a.value : a.value - b.value;
|
|
441
507
|
});
|
|
442
508
|
};
|
|
443
|
-
const naturalCompare = (a, b) => {
|
|
444
|
-
return a.localeCompare(b, "en", { numeric: true });
|
|
445
|
-
};
|
|
446
509
|
const evaluatePromQLFunction = (call, context) => {
|
|
447
510
|
const name = call.functionName;
|
|
448
511
|
const now = context.timestampMs;
|
|
449
512
|
const arg = (index) => {
|
|
450
513
|
return context.evaluate(call.args[index]);
|
|
451
514
|
};
|
|
452
|
-
const simple = SIMPLE_FUNCTIONS
|
|
515
|
+
const simple = SIMPLE_FUNCTIONS.get(name);
|
|
453
516
|
if (simple) {
|
|
454
517
|
return vectorValue(mapValues(readSamples(arg(0)), now, simple));
|
|
455
518
|
}
|
|
456
|
-
const overTime = OVER_TIME
|
|
519
|
+
const overTime = OVER_TIME.get(name);
|
|
457
520
|
if (overTime) {
|
|
458
521
|
const range = readRange(arg(0));
|
|
459
522
|
const samples = [];
|
|
@@ -474,7 +537,7 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
474
537
|
}
|
|
475
538
|
return vectorValue(samples);
|
|
476
539
|
}
|
|
477
|
-
const dateFunction = DATE_FUNCTIONS
|
|
540
|
+
const dateFunction = DATE_FUNCTIONS.get(name);
|
|
478
541
|
if (dateFunction) {
|
|
479
542
|
const samples = call.args.length === 0
|
|
480
543
|
? [{ labels: {}, value: now / 1000, timestampMs: now }]
|
|
@@ -641,7 +704,7 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
641
704
|
if (Number.isNaN(upperBound)) {
|
|
642
705
|
continue;
|
|
643
706
|
}
|
|
644
|
-
const groupLabels =
|
|
707
|
+
const groupLabels = (0, LookupTable_1.copyOwnValues)(sample.labels);
|
|
645
708
|
delete groupLabels["le"];
|
|
646
709
|
delete groupLabels[PromQLAst_1.PROMQL_METRIC_NAME_LABEL];
|
|
647
710
|
const key = (0, PromQLLabels_1.promQLLabelsKey)(groupLabels);
|
|
@@ -668,14 +731,14 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
668
731
|
const replacement = readString(arg(2));
|
|
669
732
|
const source = readString(arg(3));
|
|
670
733
|
const pattern = readString(arg(4));
|
|
671
|
-
let
|
|
734
|
+
let compiled;
|
|
672
735
|
try {
|
|
673
736
|
// Compiled once for every series below, with what its groups capture.
|
|
674
|
-
|
|
737
|
+
compiled = (0, PromQLRegex_1.compilePromQLRegex)(pattern, { captures: true });
|
|
675
738
|
}
|
|
676
739
|
catch (error) {
|
|
677
|
-
// Why
|
|
678
|
-
const problem = (0,
|
|
740
|
+
// Why the pattern cannot be matched, or null.
|
|
741
|
+
const problem = (0, PromQLRegex_1.describePromQLPatternProblem)(error);
|
|
679
742
|
throw new PromQLError_1.default(problem === null
|
|
680
743
|
? `"${pattern}" in label_replace() is not a regular expression.`
|
|
681
744
|
: `The pattern "${pattern}" in label_replace() ${problem}`, PromQLError_1.PromQLErrorType.Execution, call.position);
|
|
@@ -686,7 +749,7 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
686
749
|
return vectorValue(samples.map((sample) => {
|
|
687
750
|
let match;
|
|
688
751
|
try {
|
|
689
|
-
match = regex.exec((0, PromQLLabels_1.promQLLabelValue)(sample.labels, source));
|
|
752
|
+
match = compiled.regex.exec((0, PromQLLabels_1.promQLLabelValue)(sample.labels, source));
|
|
690
753
|
}
|
|
691
754
|
catch (error) {
|
|
692
755
|
if (error instanceof PatternProblem_1.PatternWorkLimitError) {
|
|
@@ -697,13 +760,14 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
697
760
|
if (!match) {
|
|
698
761
|
return sample;
|
|
699
762
|
}
|
|
700
|
-
|
|
701
|
-
const
|
|
763
|
+
// Own keys, a destination named __proto__ included (PromQLLabels).
|
|
764
|
+
const labels = (0, LookupTable_1.copyOwnValues)(sample.labels);
|
|
765
|
+
const value = expandTemplate(replacement, match, compiled.groupNames);
|
|
702
766
|
if (value.length === 0) {
|
|
703
767
|
delete labels[destination];
|
|
704
768
|
}
|
|
705
769
|
else {
|
|
706
|
-
labels
|
|
770
|
+
(0, LookupTable_1.writeOwnValue)(labels, destination, value);
|
|
707
771
|
}
|
|
708
772
|
return Object.assign(Object.assign({}, sample), { labels });
|
|
709
773
|
}));
|
|
@@ -723,15 +787,16 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
723
787
|
return vectorValue(samples.map((sample) => {
|
|
724
788
|
const value = sources
|
|
725
789
|
.map((source) => {
|
|
726
|
-
return sample.labels
|
|
790
|
+
return (0, PromQLLabels_1.promQLLabelValue)(sample.labels, source);
|
|
727
791
|
})
|
|
728
792
|
.join(separator);
|
|
729
|
-
|
|
793
|
+
// Own keys, a destination named __proto__ included (PromQLLabels).
|
|
794
|
+
const labels = (0, LookupTable_1.copyOwnValues)(sample.labels);
|
|
730
795
|
if (value.length === 0) {
|
|
731
796
|
delete labels[destination];
|
|
732
797
|
}
|
|
733
798
|
else {
|
|
734
|
-
labels
|
|
799
|
+
(0, LookupTable_1.writeOwnValue)(labels, destination, value);
|
|
735
800
|
}
|
|
736
801
|
return Object.assign(Object.assign({}, sample), { labels });
|
|
737
802
|
}));
|
|
@@ -748,16 +813,7 @@ const evaluatePromQLFunction = (call, context) => {
|
|
|
748
813
|
.map((_expression, index) => {
|
|
749
814
|
return readString(arg(index + 1));
|
|
750
815
|
});
|
|
751
|
-
|
|
752
|
-
return vectorValue([...samples].sort((a, b) => {
|
|
753
|
-
for (const label of labels) {
|
|
754
|
-
const order = naturalCompare(a.labels[label] || "", b.labels[label] || "");
|
|
755
|
-
if (order !== 0) {
|
|
756
|
-
return order * direction;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
return 0;
|
|
760
|
-
}));
|
|
816
|
+
return vectorValue((0, PromQLLabelOrder_1.sortPromQLByLabels)(samples, labels, name === "sort_by_label_desc"));
|
|
761
817
|
}
|
|
762
818
|
default:
|
|
763
819
|
throw new PromQLError_1.default(`Unknown function "${name}".`, PromQLError_1.PromQLErrorType.BadData, call.position);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PromQLLabels } from "./PromQLLabels.mjs";
|
|
2
|
+
export declare const comparePromQLText: (a: string, b: string) => number;
|
|
3
|
+
export declare const promQLNaturalLess: (a: string, b: string) => boolean;
|
|
4
|
+
export declare const comparePromQLLabelValues: (a: string, b: string) => number;
|
|
5
|
+
export declare const comparePromQLLabelSets: (a: PromQLLabels, b: PromQLLabels) => number;
|
|
6
|
+
export declare const sortPromQLByLabels: <T extends {
|
|
7
|
+
labels: PromQLLabels;
|
|
8
|
+
}>(items: ReadonlyArray<T>, names: ReadonlyArray<string>, descending: boolean) => Array<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PromQLLabels } from "./PromQLLabels";
|
|
2
|
+
export declare const comparePromQLText: (a: string, b: string) => number;
|
|
3
|
+
export declare const promQLNaturalLess: (a: string, b: string) => boolean;
|
|
4
|
+
export declare const comparePromQLLabelValues: (a: string, b: string) => number;
|
|
5
|
+
export declare const comparePromQLLabelSets: (a: PromQLLabels, b: PromQLLabels) => number;
|
|
6
|
+
export declare const sortPromQLByLabels: <T extends {
|
|
7
|
+
labels: PromQLLabels;
|
|
8
|
+
}>(items: ReadonlyArray<T>, names: ReadonlyArray<string>, descending: boolean) => Array<T>;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortPromQLByLabels = exports.comparePromQLLabelSets = exports.comparePromQLLabelValues = exports.promQLNaturalLess = exports.comparePromQLText = void 0;
|
|
4
|
+
const PromQLLabels_1 = require("./PromQLLabels");
|
|
5
|
+
/*
|
|
6
|
+
* The orders Prometheus puts label values and label sets in, for
|
|
7
|
+
* sort_by_label() and sort_by_label_desc() (funcSortByLabel and
|
|
8
|
+
* funcSortByLabelDesc in promql/functions.go): label values in natural order
|
|
9
|
+
* (github.com/facette/natsort), and samples whose named labels are all equal
|
|
10
|
+
* by their whole label sets (labels.Compare).
|
|
11
|
+
*
|
|
12
|
+
* Go compares strings byte by byte in UTF-8, which is code point order.
|
|
13
|
+
* JavaScript's < compares UTF-16 code units, which puts U+10000 and above
|
|
14
|
+
* (written as surrogates, D800-DFFF) before U+E000-U+FFFF, so "😀" < "�"
|
|
15
|
+
* in JavaScript and the other way round in Go. Every comparison of text here
|
|
16
|
+
* is in code point order, as Go's.
|
|
17
|
+
*/
|
|
18
|
+
const SURROGATE_START = 0xd800;
|
|
19
|
+
const PRIVATE_USE_START = 0xe000;
|
|
20
|
+
/*
|
|
21
|
+
* Where a UTF-16 code unit sits in code point order: surrogates, which
|
|
22
|
+
* write U+10000 and above, after every other code unit.
|
|
23
|
+
*/
|
|
24
|
+
const codeUnitRank = (unit) => {
|
|
25
|
+
if (unit < SURROGATE_START) {
|
|
26
|
+
return unit;
|
|
27
|
+
}
|
|
28
|
+
return unit >= PRIVATE_USE_START ? unit - 0x800 : unit + 0x2000;
|
|
29
|
+
};
|
|
30
|
+
// Go's strings.Compare: -1, 0 or 1, in code point order.
|
|
31
|
+
const comparePromQLText = (a, b) => {
|
|
32
|
+
const shared = Math.min(a.length, b.length);
|
|
33
|
+
for (let index = 0; index < shared; index++) {
|
|
34
|
+
const unitA = a.charCodeAt(index);
|
|
35
|
+
const unitB = b.charCodeAt(index);
|
|
36
|
+
if (unitA !== unitB) {
|
|
37
|
+
return codeUnitRank(unitA) < codeUnitRank(unitB) ? -1 : 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Math.sign(a.length - b.length);
|
|
41
|
+
};
|
|
42
|
+
exports.comparePromQLText = comparePromQLText;
|
|
43
|
+
// natsort's chunkify, `(\d+|\D+)`: runs of ASCII digits and runs of the rest.
|
|
44
|
+
const CHUNK_REGEX = /\d+|\D+/g;
|
|
45
|
+
const DIGITS_REGEX = /^\d+$/;
|
|
46
|
+
const LEADING_ZEROS_REGEX = /^0+(?=\d)/;
|
|
47
|
+
// The largest int, on the 64-bit machines Prometheus runs on.
|
|
48
|
+
const INT64_MAX = "9223372036854775807";
|
|
49
|
+
const chunksOf = (text) => {
|
|
50
|
+
return text.match(CHUNK_REGEX) || [];
|
|
51
|
+
};
|
|
52
|
+
/*
|
|
53
|
+
* strconv.Atoi of a chunk, as the digits of its value without leading zeros:
|
|
54
|
+
* undefined for a chunk that is not a number, and for one past int64, which
|
|
55
|
+
* Atoi refuses as out of range.
|
|
56
|
+
*/
|
|
57
|
+
const intOf = (chunk) => {
|
|
58
|
+
if (!DIGITS_REGEX.test(chunk)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const digits = chunk.replace(LEADING_ZEROS_REGEX, "");
|
|
62
|
+
if (digits.length > INT64_MAX.length ||
|
|
63
|
+
(digits.length === INT64_MAX.length && digits > INT64_MAX)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return digits;
|
|
67
|
+
};
|
|
68
|
+
// Two numbers' digits, leading zeros dropped, compared as the numbers.
|
|
69
|
+
const compareInts = (a, b) => {
|
|
70
|
+
if (a.length !== b.length) {
|
|
71
|
+
return a.length < b.length ? -1 : 1;
|
|
72
|
+
}
|
|
73
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
74
|
+
};
|
|
75
|
+
/*
|
|
76
|
+
* natsort.Compare: whether a comes before b in natural order. The two are
|
|
77
|
+
* read chunk by chunk; two numbers compare as numbers, anything else as
|
|
78
|
+
* text, and when every chunk so far is equal the string that runs out of
|
|
79
|
+
* chunks first comes first.
|
|
80
|
+
*
|
|
81
|
+
* A port, quirks and all. A number past int64 compares as text, so
|
|
82
|
+
* "10000000000000000000000" comes before "5". And it answers false both ways
|
|
83
|
+
* round for "" and any other value, and true both ways round for values that
|
|
84
|
+
* differ only in leading zeros ("01" and "1"): comparePromQLLabelValues says
|
|
85
|
+
* what OneUptime does then.
|
|
86
|
+
*/
|
|
87
|
+
const promQLNaturalLess = (a, b) => {
|
|
88
|
+
const chunksA = chunksOf(a);
|
|
89
|
+
const chunksB = chunksOf(b);
|
|
90
|
+
for (let index = 0; index < chunksA.length; index++) {
|
|
91
|
+
if (index >= chunksB.length) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const chunkA = chunksA[index];
|
|
95
|
+
const chunkB = chunksB[index];
|
|
96
|
+
const intA = intOf(chunkA);
|
|
97
|
+
const intB = intOf(chunkB);
|
|
98
|
+
const order = intA !== undefined && intB !== undefined
|
|
99
|
+
? compareInts(intA, intB)
|
|
100
|
+
: (0, exports.comparePromQLText)(chunkA, chunkB);
|
|
101
|
+
if (order !== 0) {
|
|
102
|
+
return order < 0;
|
|
103
|
+
}
|
|
104
|
+
if (index === chunksA.length - 1) {
|
|
105
|
+
// a has run out: b is after it.
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (index === chunksB.length - 1) {
|
|
109
|
+
// b has run out: a is after it.
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
exports.promQLNaturalLess = promQLNaturalLess;
|
|
116
|
+
/*
|
|
117
|
+
* How sort_by_label() orders two values of a label it sorts by: -1, 0 or 1.
|
|
118
|
+
* Equal values tie, and the next label decides. Otherwise natural order, as
|
|
119
|
+
* Prometheus sorts, wherever natsort answers one way round: "a9" before
|
|
120
|
+
* "a10", "B" before "a" (an upper-case letter is a smaller byte), "1.9"
|
|
121
|
+
* before "1.10".
|
|
122
|
+
*
|
|
123
|
+
* Where natsort gives the same answer both ways round, an empty value (a
|
|
124
|
+
* missing label) against any other and "01" against "1", Prometheus' own
|
|
125
|
+
* order is the order the series happened to come in, which no query can
|
|
126
|
+
* know. There, OneUptime compares the values as text, as Go would: a
|
|
127
|
+
* missing label first ("" before anything), "001" before "01" before "1".
|
|
128
|
+
* So a query gives the same order every time.
|
|
129
|
+
*/
|
|
130
|
+
const comparePromQLLabelValues = (a, b) => {
|
|
131
|
+
if (a === b) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
const aFirst = (0, exports.promQLNaturalLess)(a, b);
|
|
135
|
+
const bFirst = (0, exports.promQLNaturalLess)(b, a);
|
|
136
|
+
if (aFirst !== bFirst) {
|
|
137
|
+
return aFirst ? -1 : 1;
|
|
138
|
+
}
|
|
139
|
+
return (0, exports.comparePromQLText)(a, b);
|
|
140
|
+
};
|
|
141
|
+
exports.comparePromQLLabelValues = comparePromQLLabelValues;
|
|
142
|
+
/*
|
|
143
|
+
* A label set's names in the order Prometheus keeps them, by code point.
|
|
144
|
+
* A label with an empty value is not a label (PromQLLabels).
|
|
145
|
+
*/
|
|
146
|
+
const namesInOrder = (labels) => {
|
|
147
|
+
return Object.keys(labels)
|
|
148
|
+
.filter((name) => {
|
|
149
|
+
return (0, PromQLLabels_1.promQLLabelValue)(labels, name) !== "";
|
|
150
|
+
})
|
|
151
|
+
.sort(exports.comparePromQLText);
|
|
152
|
+
};
|
|
153
|
+
const compareNamedLabelSets = (a, namesA, b, namesB) => {
|
|
154
|
+
const shared = Math.min(namesA.length, namesB.length);
|
|
155
|
+
for (let index = 0; index < shared; index++) {
|
|
156
|
+
const nameA = namesA[index];
|
|
157
|
+
const nameB = namesB[index];
|
|
158
|
+
const nameOrder = (0, exports.comparePromQLText)(nameA, nameB);
|
|
159
|
+
if (nameOrder !== 0) {
|
|
160
|
+
return nameOrder;
|
|
161
|
+
}
|
|
162
|
+
const valueOrder = (0, exports.comparePromQLText)((0, PromQLLabels_1.promQLLabelValue)(a, nameA), (0, PromQLLabels_1.promQLLabelValue)(b, nameB));
|
|
163
|
+
if (valueOrder !== 0) {
|
|
164
|
+
return valueOrder;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return Math.sign(namesA.length - namesB.length);
|
|
168
|
+
};
|
|
169
|
+
/*
|
|
170
|
+
* Prometheus' labels.Compare: -1, 0 or 1. Label by label in name order, the
|
|
171
|
+
* metric name among them: a smaller name first, then a smaller value; when
|
|
172
|
+
* one set runs out with every label so far the same, the shorter set first.
|
|
173
|
+
* So {a="z", g="1"} comes before {b="a", g="1"}: the names differ before the
|
|
174
|
+
* values are read.
|
|
175
|
+
*/
|
|
176
|
+
const comparePromQLLabelSets = (a, b) => {
|
|
177
|
+
return compareNamedLabelSets(a, namesInOrder(a), b, namesInOrder(b));
|
|
178
|
+
};
|
|
179
|
+
exports.comparePromQLLabelSets = comparePromQLLabelSets;
|
|
180
|
+
/*
|
|
181
|
+
* sort_by_label(): the items by the values of the named labels, the first
|
|
182
|
+
* label first, and items equal on all of them by their whole label sets.
|
|
183
|
+
* sort_by_label_desc() is the same order backwards, its ties included, as
|
|
184
|
+
* Prometheus sorts them (-labels.Compare).
|
|
185
|
+
*/
|
|
186
|
+
const sortPromQLByLabels = (items, names, descending) => {
|
|
187
|
+
const direction = descending ? -1 : 1;
|
|
188
|
+
return items
|
|
189
|
+
.map((item) => {
|
|
190
|
+
return {
|
|
191
|
+
item,
|
|
192
|
+
values: names.map((name) => {
|
|
193
|
+
return (0, PromQLLabels_1.promQLLabelValue)(item.labels, name);
|
|
194
|
+
}),
|
|
195
|
+
names: namesInOrder(item.labels),
|
|
196
|
+
};
|
|
197
|
+
})
|
|
198
|
+
.sort((a, b) => {
|
|
199
|
+
for (let index = 0; index < a.values.length; index++) {
|
|
200
|
+
const order = (0, exports.comparePromQLLabelValues)(a.values[index], b.values[index]);
|
|
201
|
+
if (order !== 0) {
|
|
202
|
+
return order * direction;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return (compareNamedLabelSets(a.item.labels, a.names, b.item.labels, b.names) *
|
|
206
|
+
direction);
|
|
207
|
+
})
|
|
208
|
+
.map((entry) => {
|
|
209
|
+
return entry.item;
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
exports.sortPromQLByLabels = sortPromQLByLabels;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import commonJsModule from "./PromQLLabelOrder.js";
|
|
2
|
+
export const comparePromQLLabelSets = commonJsModule.comparePromQLLabelSets;
|
|
3
|
+
export const comparePromQLLabelValues = commonJsModule.comparePromQLLabelValues;
|
|
4
|
+
export const comparePromQLText = commonJsModule.comparePromQLText;
|
|
5
|
+
export const promQLNaturalLess = commonJsModule.promQLNaturalLess;
|
|
6
|
+
export const sortPromQLByLabels = commonJsModule.sortPromQLByLabels;
|
|
@@ -38,6 +38,7 @@ const PromQLAst_1 = require("./PromQLAst");
|
|
|
38
38
|
const PromQLError_1 = __importStar(require("./PromQLError"));
|
|
39
39
|
const PromQLRegex_1 = require("./PromQLRegex");
|
|
40
40
|
const PatternProblem_1 = require("../LinearRegExp/PatternProblem");
|
|
41
|
+
const LookupTable_1 = require("../LookupTable");
|
|
41
42
|
const SEPARATOR = "\xff";
|
|
42
43
|
/*
|
|
43
44
|
* A label's value, "" for a label the series does not have: never what
|
|
@@ -63,7 +64,7 @@ const dropMetricName = (labels) => {
|
|
|
63
64
|
if (labels[PromQLAst_1.PROMQL_METRIC_NAME_LABEL] === undefined) {
|
|
64
65
|
return labels;
|
|
65
66
|
}
|
|
66
|
-
const copy =
|
|
67
|
+
const copy = (0, LookupTable_1.copyOwnValues)(labels);
|
|
67
68
|
delete copy[PromQLAst_1.PROMQL_METRIC_NAME_LABEL];
|
|
68
69
|
return copy;
|
|
69
70
|
};
|
|
@@ -76,7 +77,7 @@ const promQLMatchSignature = (labels, on, names) => {
|
|
|
76
77
|
if (on) {
|
|
77
78
|
let key = "";
|
|
78
79
|
for (const name of [...names].sort()) {
|
|
79
|
-
key += `${name}${SEPARATOR}${labels
|
|
80
|
+
key += `${name}${SEPARATOR}${(0, exports.promQLLabelValue)(labels, name)}${SEPARATOR}`;
|
|
80
81
|
}
|
|
81
82
|
return key;
|
|
82
83
|
}
|
|
@@ -85,7 +86,7 @@ const promQLMatchSignature = (labels, on, names) => {
|
|
|
85
86
|
const kept = {};
|
|
86
87
|
for (const name of Object.keys(labels)) {
|
|
87
88
|
if (!ignored.has(name)) {
|
|
88
|
-
kept
|
|
89
|
+
(0, LookupTable_1.writeOwnValue)(kept, name, labels[name]);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
return (0, exports.promQLLabelsKey)(kept);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.promQLSeriesNamesOf = exports.resolvePromQLMetricName = exports.PromQLSeriesKind = exports.attributesToPromQLLabels = exports.toPromQLLabelName = exports.toPromQLMetricName = exports.PROMQL_LABEL_NAME_SQL_PATTERN = void 0;
|
|
4
4
|
const PromQLAst_1 = require("./PromQLAst");
|
|
5
|
+
const PromQLLabels_1 = require("./PromQLLabels");
|
|
6
|
+
const LookupTable_1 = require("../LookupTable");
|
|
5
7
|
/*
|
|
6
8
|
* How OneUptime's OpenTelemetry metrics are named in PromQL (issue #6796).
|
|
7
9
|
*
|
|
@@ -79,8 +81,12 @@ const attributesToPromQLLabels = (attributes) => {
|
|
|
79
81
|
if (RESERVED_LABELS.has(label)) {
|
|
80
82
|
continue;
|
|
81
83
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
/*
|
|
85
|
+
* The series' own labels, read and written: an attribute may be named
|
|
86
|
+
* constructor, or __proto__.
|
|
87
|
+
*/
|
|
88
|
+
const existing = (0, PromQLLabels_1.promQLLabelValue)(labels, label);
|
|
89
|
+
(0, LookupTable_1.writeOwnValue)(labels, label, existing.length === 0 ? value : `${existing};${value}`);
|
|
84
90
|
}
|
|
85
91
|
// job and instance, the way Prometheus derives them from the resource.
|
|
86
92
|
const serviceName = stringAttribute(attributes, "resource.service.name");
|
|
@@ -10,7 +10,7 @@ const PromQLError_1 = __importDefault(require("./PromQLError"));
|
|
|
10
10
|
const PromQLFunctions_1 = require("./PromQLFunctions");
|
|
11
11
|
const PromQLLexer_1 = require("./PromQLLexer");
|
|
12
12
|
const PromQLRegex_1 = require("./PromQLRegex");
|
|
13
|
-
const
|
|
13
|
+
const LookupTable_1 = __importDefault(require("../LookupTable"));
|
|
14
14
|
/*
|
|
15
15
|
* Parses a PromQL query into a checked syntax tree (promql/parser).
|
|
16
16
|
*
|
|
@@ -29,12 +29,17 @@ const AGGREGATES_WITH_PARAMETER = new Set([
|
|
|
29
29
|
PromQLAst_1.PromQLAggregateOperator.Quantile,
|
|
30
30
|
PromQLAst_1.PromQLAggregateOperator.CountValues,
|
|
31
31
|
]);
|
|
32
|
-
|
|
32
|
+
/*
|
|
33
|
+
* Read by the word a query writes after an expression, so a Map: a plain
|
|
34
|
+
* object would read `up constructor up` as an operation whose operator is
|
|
35
|
+
* the function every object inherits, not as the word no operator is.
|
|
36
|
+
*/
|
|
37
|
+
const KEYWORD_BINARY_OPERATORS = (0, LookupTable_1.default)({
|
|
33
38
|
and: PromQLAst_1.PromQLBinaryOperator.And,
|
|
34
39
|
or: PromQLAst_1.PromQLBinaryOperator.Or,
|
|
35
40
|
unless: PromQLAst_1.PromQLBinaryOperator.Unless,
|
|
36
41
|
atan2: PromQLAst_1.PromQLBinaryOperator.Atan2,
|
|
37
|
-
};
|
|
42
|
+
});
|
|
38
43
|
const SYMBOL_BINARY_OPERATORS = new Map([
|
|
39
44
|
[PromQLLexer_1.PromQLTokenType.Add, PromQLAst_1.PromQLBinaryOperator.Add],
|
|
40
45
|
[PromQLLexer_1.PromQLTokenType.Sub, PromQLAst_1.PromQLBinaryOperator.Sub],
|
|
@@ -174,7 +179,7 @@ class PromQLParser {
|
|
|
174
179
|
peekBinaryOperator() {
|
|
175
180
|
const token = this.peek();
|
|
176
181
|
if (token.type === PromQLLexer_1.PromQLTokenType.Identifier) {
|
|
177
|
-
return KEYWORD_BINARY_OPERATORS
|
|
182
|
+
return KEYWORD_BINARY_OPERATORS.get(token.text.toLowerCase());
|
|
178
183
|
}
|
|
179
184
|
return SYMBOL_BINARY_OPERATORS.get(token.type);
|
|
180
185
|
}
|
|
@@ -435,8 +440,8 @@ class PromQLParser {
|
|
|
435
440
|
(0, PromQLRegex_1.compilePromQLRegex)(valueToken.text);
|
|
436
441
|
}
|
|
437
442
|
catch (error) {
|
|
438
|
-
// Why
|
|
439
|
-
const problem = (0,
|
|
443
|
+
// Why the pattern cannot be matched, or null.
|
|
444
|
+
const problem = (0, PromQLRegex_1.describePromQLPatternProblem)(error);
|
|
440
445
|
throw new PromQLError_1.default(problem === null
|
|
441
446
|
? `"${valueToken.text}" is not a regular expression the label "${labelName}" can be matched with.`
|
|
442
447
|
: `The pattern "${valueToken.text}" for the label "${labelName}" ${problem}`, undefined, { start: valueToken.start, end: valueToken.end });
|