Skip to content

Commit

Permalink
[Metrics UI] Add docs link to redundant groupBy detection (#116822)
Browse files Browse the repository at this point in the history
* [Metrics UI] Fix OR logic on redundant groupBy detection

* Switch regex change to doc change

* Fix core docs links

* Update x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx

Co-authored-by: Sandra G <[email protected]>

Co-authored-by: Sandra G <[email protected]>
  • Loading branch information
Zacqary and neptunian authored Nov 4, 2021
1 parent b0110d8 commit e4982fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ export class DocLinksService {
},
observability: {
guide: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/index.html`,
infrastructureThreshold: `{ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/infrastructure-threshold-alert.html`,
logsThreshold: `{ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/logs-threshold-alert.html`,
metricsThreshold: `{ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/metrics-threshold-alert.html`,
infrastructureThreshold: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/infrastructure-threshold-alert.html`,
logsThreshold: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/logs-threshold-alert.html`,
metricsThreshold: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/metrics-threshold-alert.html`,
monitorStatus: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/monitor-status-alert.html`,
monitorUptime: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/monitor-uptime.html`,
tlsCertificate: `${ELASTIC_WEBSITE_URL}guide/en/observability/${DOC_LINK_VERSION}/tls-certificate-alert.html`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EuiFieldSearch,
EuiAccordion,
EuiPanel,
EuiLink,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -58,7 +59,7 @@ export { defaultExpression };

export const Expressions: React.FC<Props> = (props) => {
const { setAlertParams, alertParams, errors, metadata } = props;
const { http, notifications } = useKibanaContextForPlugin().services;
const { http, notifications, docLinks } = useKibanaContextForPlugin().services;
const { source, createDerivedIndexPattern } = useSourceViaHttp({
sourceId: 'default',
fetch: http.fetch,
Expand Down Expand Up @@ -260,6 +261,9 @@ export const Expressions: React.FC<Props> = (props) => {
[alertParams.groupBy]
);

// Test to see if any of the group fields in groupBy are already filtered down to a single
// group by the filterQuery. If this is the case, then a groupBy is unnecessary, as it would only
// ever produce one group instance
const groupByFilterTestPatterns = useMemo(() => {
if (!alertParams.groupBy) return null;
const groups = !Array.isArray(alertParams.groupBy)
Expand Down Expand Up @@ -456,10 +460,20 @@ export const Expressions: React.FC<Props> = (props) => {
<EuiText size="xs" color="danger">
<FormattedMessage
id="xpack.infra.metrics.alertFlyout.alertPerRedundantFilterError"
defaultMessage="This rule will only alert per one {matchedGroups} because the filter query contains an exact match for {groupCount, plural, one {this field} other {these fields}}."
defaultMessage="This rule may alert on {matchedGroups} less than expected, because the filter query contains a match for {groupCount, plural, one {this field} other {these fields}}. For more information, refer to {filteringAndGroupingLink}."
values={{
matchedGroups: <strong>{redundantFilterGroupBy.join(', ')}</strong>,
groupCount: redundantFilterGroupBy.length,
filteringAndGroupingLink: (
<EuiLink
href={`${docLinks.links.observability.metricsThreshold}#filtering-and-grouping`}
>
{i18n.translate(
'xpack.infra.metrics.alertFlyout.alertPerRedundantFilterError.docsLink',
{ defaultMessage: 'the docs' }
)}
</EuiLink>
),
}}
/>
</EuiText>
Expand Down

0 comments on commit e4982fe

Please sign in to comment.