Skip to content

Commit

Permalink
Alerting stack-monitoring PoC (#135365)
Browse files Browse the repository at this point in the history
* Rate to counts

* Adjusting titles

* /s/units/unit

* Uncommenting completely unrelated commented out code

* More titles thrashing

* wip

* fix  tests

* fix api integration test to not take in consideration the formating

* Adding technical preview badge

* Renaming "Overdue Rules" to "Queued Rules" on the Kibana overview page

* Updating tests, adding missed technicalPreview to metric

* More snapshots being updated

Co-authored-by: Xavier Mouligneau <[email protected]>
  • Loading branch information
kobelb and XavierM authored Jul 22, 2022
1 parent 5e391dc commit c0ad0f9
Show file tree
Hide file tree
Showing 15 changed files with 1,932 additions and 384 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { chain } from 'lodash';

/*
* Chart titles are taken from `metric.title` or `metric.label` fields in the series data.
* Use title if found, otherwise use label
*/
export function getTechnicalPreview(series = []) {
return chain(
series.map((s) => {
return Boolean(s.metric.technicalPreview);
})
)
.first()
.value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { getTechnicalPreview } from './get_technical_preview';

describe('getTechnicalPreview', function () {
it('with metric.technicalPreview undefined', () => {
const series = [{ metric: {} }, { metric: { technicalPreview: true } }];
expect(getTechnicalPreview(series)).to.be(false);
});

it('with metric.technicalPreview false', () => {
const series = [
{ metric: { technicalPreview: false } },
{ metric: { technicalPreview: true } },
];
expect(getTechnicalPreview(series)).to.be(false);
});

it('with metric.technicalPreview true', () => {
const series = [
{ metric: { technicalPreview: true } },
{ metric: { technicalPreview: false } },
];
expect(getTechnicalPreview(series)).to.be(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

import React, { Fragment } from 'react';
import { get, first } from 'lodash';
import { getTechnicalPreview } from './get_technical_preview';
import { getTitle } from './get_title';
import { getUnits } from './get_units';
import { MonitoringTimeseries } from './monitoring_timeseries';
import { InfoTooltip } from './info_tooltip';
import './monitoring_timeseries_container.scss';

import {
EuiBadge,
EuiIconTip,
EuiFlexGroup,
EuiFlexItem,
Expand Down Expand Up @@ -50,12 +52,30 @@ const zoomOutBtn = (zoomInfo) => {
);
};

const technicalPreviewBadge = (technicalPreview) => {
if (!technicalPreview) {
return null;
}

return (
<EuiFlexItem>
<EuiBadge color="hollow" iconType="cheer">
<FormattedMessage
id="xpack.monitoring.chart.timeSeries.technicalPreview"
defaultMessage="Technical Preview"
/>
</EuiBadge>
</EuiFlexItem>
);
};

export function MonitoringTimeseriesContainer({ series, onBrush, zoomInfo }) {
if (series === undefined) {
return null; // still loading
}

const title = getTitle(series);
const technicalPreview = getTechnicalPreview(series);
const titleForAriaIds = title.replace(/\s+/, '--');
const units = getUnits(series);
const bucketSize = get(first(series), 'bucket_size'); // bucket size will be the same for all metrics in all series
Expand Down Expand Up @@ -115,6 +135,7 @@ export function MonitoringTimeseriesContainer({ series, onBrush, zoomInfo }) {
</EuiScreenReaderOnly>
</Fragment>
</EuiFlexItem>
{technicalPreviewBadge(technicalPreview)}
{zoomOutBtn(zoomInfo)}
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ export function KibanaPanel(props) {
</EuiDescriptionListDescription>
<EuiDescriptionListTitle className="eui-textBreakWord">
<FormattedMessage
id="xpack.monitoring.cluster.overview.kibanaPanel.overdueTaskCountLabel"
defaultMessage="Overdue Rules"
id="xpack.monitoring.cluster.overview.kibanaPanel.queuedRulesCountLabel"
defaultMessage="Queued Rules"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="kbnOverdueRules">
<EuiDescriptionListDescription data-test-subj="kbnQueuedRules">
{props.rules.cluster.overdue.count}
</EuiDescriptionListDescription>
</>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions x-pack/plugins/monitoring/server/lib/details/get_series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function createMetricAggs(metric: Metric) {
derivative: {
buckets_path: 'metric_mb',
gap_policy: 'skip',
unit: NORMALIZED_DERIVATIVE_UNIT,
...(metric.derivativeNormalizedUnits ? { unit: NORMALIZED_DERIVATIVE_UNIT } : {}),
},
},
}
Expand All @@ -97,7 +97,7 @@ function createMetricAggs(metric: Metric) {
derivative: {
buckets_path: 'metric',
gap_policy: 'skip',
unit: NORMALIZED_DERIVATIVE_UNIT,
...(metric.derivativeNormalizedUnits ? { unit: NORMALIZED_DERIVATIVE_UNIT } : {}),
},
},
...mbDerivative,
Expand Down Expand Up @@ -275,7 +275,12 @@ function handleSeries(
timezone: string,
response: ElasticsearchResponse
) {
const { derivative, calculation: customCalculation, isNotSupportedInInternalCollection } = metric;
const {
derivative,
derivativeNormalizedUnits,
calculation: customCalculation,
isNotSupportedInInternalCollection,
} = metric;

function getAggregatedData(buckets: SeriesBucket[]) {
const firstUsableBucketIndex = findFirstUsableBucketIndex(buckets, min);
Expand All @@ -291,7 +296,11 @@ function handleSeries(

if (firstUsableBucketIndex <= lastUsableBucketIndex) {
// map buckets to values for charts
const key = derivative ? 'metric_deriv.normalized_value' : 'metric.value';
const key = derivative
? derivativeNormalizedUnits
? 'metric_deriv.normalized_value'
: 'metric_deriv.value'
: 'metric.value';
const calculation = customCalculation !== undefined ? customCalculation : defaultCalculation;
const usableBuckets = buckets.slice(firstUsableBucketIndex, lastUsableBucketIndex + 1); // take only the buckets we know are usable

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0ad0f9

Please sign in to comment.