Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics UI] Remove TSVB dependency from Metrics Explorer APIs #74804

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
series: MetricsExplorerSeries;
}

const ALL_TITLE = i18n.translate('xpack.infra.metricsExploer.everything', {
const ALL_TITLE = i18n.translate('xpack.infra.metricsExplorer.everything', {
defaultMessage: 'Everything',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const roundingRules = [
[Infinity, d(1, 'year')],
];

const revRoundingRules = roundingRules.slice(0).reverse();
const revRoundingRules = [...roundingRules].reverse();

type NumberOrDuration = number | Duration;

Expand All @@ -39,23 +39,22 @@ type CheckFunction = (
target: number
) => Duration | undefined;

function find(rules: Rule[], check: CheckFunction, last?: boolean) {
function pick(buckets: number, duration: Duration) {
function findRule(rules: Rule[], check: CheckFunction, last?: boolean) {
function pickInterval(buckets: number, duration: Duration) {
const target = duration.asMilliseconds() / buckets;
let lastResp = null;
let lastResult = null;

for (let i = 0; i < rules.length; i++) {
const rule = rules[i];
const resp = check(rule[0] as Duration, rule[1] as Duration, target);
for (const rule of rules) {
const result = check(rule[0] as Duration, rule[1] as Duration, target);

if (resp == null) {
if (result == null) {
if (!last) continue;
if (lastResp) return lastResp;
if (lastResult) return lastResult;
break;
}

if (!last) return resp;
lastResp = resp;
if (!last) return result;
lastResult = result;
}

// fallback to just a number of milliseconds, ensure ms is >= 1
Expand All @@ -64,13 +63,13 @@ function find(rules: Rule[], check: CheckFunction, last?: boolean) {
}

return (buckets: number, duration: Duration) => {
const interval = pick(buckets, duration);
const interval = pickInterval(buckets, duration);
if (isDuration(interval)) return interval;
};
}

export const calculateAuto = {
near: find(
near: findRule(
revRoundingRules,
function near(bound, interval, target) {
if (isDuration(bound) && bound.asMilliseconds() > target) return interval;
Expand All @@ -79,11 +78,11 @@ export const calculateAuto = {
true
),

lessThan: find(revRoundingRules, function lessThan(_bound, interval, target) {
lessThan: findRule(revRoundingRules, function lessThan(_bound, interval, target) {
if (interval.asMilliseconds() < target) return interval;
}),

atLeast: find(revRoundingRules, function atLeast(_bound, interval, target) {
atLeast: findRule(revRoundingRules, function atLeast(_bound, interval, target) {
if (interval.asMilliseconds() <= target) return interval;
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const units: Record<string, number> = {
m: 60,
h: 3600,
d: 86400,
w: 86400 * 7, // Hum... might be wrong
M: 86400 * 7 * 4, // this too... 29,30,31?
y: 86400 * 7 * 4 * 12, // Leap year?
w: 86400 * 7,
M: 86400 * 30,
y: 86400 * 356,
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
};

const sortedUnits = sortBy(Object.keys(units), (key) => units[key]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getValue = (valueObject: string | number | MetricValueType) => {
const percentileValues = values(valueObject.values);
if (percentileValues.length > 1) {
throw new Error(
'Metrics API only supports a single percentile, multiple percentiles should be sent seperatly'
'Metrics API only supports a single percentile, multiple percentiles should be sent separately'
);
}
return first(percentileValues) || null;
Expand All @@ -39,7 +39,7 @@ const getValue = (valueObject: string | number | MetricValueType) => {
if (PercentilesKeyedTypeRT.is(valueObject)) {
if (valueObject.values.length > 1) {
throw new Error(
'Metrics API only supports a single percentile, multiple percentiles should be sent seperatly'
'Metrics API only supports a single percentile, multiple percentiles should be sent separately'
);
}
const percentileValue = first(valueObject.values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const findIntervalForMetrics = async (
timestampField: options.timerange.field,
timerange: options.timerange,
},
modules.filter((m) => m) as string[]
modules.filter(Boolean) as string[]
);
cache.set(cacheKey, interval);
return interval;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -8892,7 +8892,7 @@
"xpack.infra.metrics.missingTSVBModelError": "{nodeType}では{metricId}のTSVBモデルが存在しません",
"xpack.infra.metrics.pluginTitle": "メトリック",
"xpack.infra.metrics.refetchButtonLabel": "新規データを確認",
"xpack.infra.metricsExploer.everything": "すべて",
"xpack.infra.metricsExplorer.everything": "すべて",
"xpack.infra.metricsExplorer.actionsLabel.aria": "{grouping} のアクション",
"xpack.infra.metricsExplorer.actionsLabel.button": "アクション",
"xpack.infra.metricsExplorer.aggregationLabel": "/",
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -8894,7 +8894,7 @@
"xpack.infra.metrics.missingTSVBModelError": "{nodeType} 的 {metricId} TSVB 模型不存在",
"xpack.infra.metrics.pluginTitle": "指标",
"xpack.infra.metrics.refetchButtonLabel": "检查新数据",
"xpack.infra.metricsExploer.everything": "所有内容",
"xpack.infra.metricsExplorer.everything": "所有内容",
"xpack.infra.metricsExplorer.actionsLabel.aria": "适用于 {grouping} 的操作",
"xpack.infra.metricsExplorer.actionsLabel.button": "操作",
"xpack.infra.metricsExplorer.aggregationLabel": "的",
Expand Down