-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Monitoring][Alerting] Large shard alert #89410
Merged
+931
−171
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d0d6da3
Shards alert draft
igoristic 14bbc8f
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic 1e9e71b
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic 7cc3768
Added index pattern validation
igoristic 191d7ca
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic ac5c1cf
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic d9883bd
Fixed ui/ux
igoristic a5da8d5
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic 655eb6e
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic 1c8b61d
Optimizing the response
igoristic ed01df4
CR feedback
igoristic 8c53965
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic afe09cc
import fix
igoristic fd33ae3
Merge branch 'master' of https://github.com/elastic/kibana into shard…
igoristic 2b450c6
Increased size limit
igoristic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface RegExPatterns { | ||
contains?: string | RegExp; | ||
negate?: string | RegExp; | ||
} | ||
|
||
const valid = /.*/; | ||
|
||
export class ESGlobPatterns { | ||
public static createRegExPatterns(globPattern: string) { | ||
if (globPattern === '*') { | ||
return { contains: valid, negate: valid }; | ||
} | ||
|
||
globPattern = globPattern.toLowerCase(); | ||
globPattern = globPattern.replace(/[ \\\/?"<>|#]/g, ''); | ||
const patternsArr = globPattern.split(','); | ||
const containPatterns: string[] = []; | ||
const negatePatterns: string[] = []; | ||
patternsArr.forEach((pattern) => { | ||
if (pattern.charAt(0) === '-') { | ||
negatePatterns.push(ESGlobPatterns.createESGlobRegExStr(pattern.slice(1))); | ||
} else { | ||
containPatterns.push(ESGlobPatterns.createESGlobRegExStr(pattern)); | ||
} | ||
}); | ||
const contains = containPatterns.length ? new RegExp(containPatterns.join('|'), 'gi') : valid; | ||
const negate = negatePatterns.length | ||
? new RegExp(`^((?!(${negatePatterns.join('|')})).)*$`, 'gi') | ||
: valid; | ||
return { contains, negate }; | ||
} | ||
|
||
public static isValid(value: string, patterns: RegExPatterns) { | ||
const { contains = valid, negate = valid } = patterns; | ||
return new RegExp(contains).test(value) && new RegExp(negate).test(value); | ||
} | ||
|
||
private static createESGlobRegExStr(pattern: string) { | ||
const patternsArr = pattern.split('*'); | ||
const firstItem = patternsArr.shift(); | ||
const lastItem = patternsArr.pop(); | ||
const start = firstItem?.length ? `(^${ESGlobPatterns.escapeStr(firstItem)})` : ''; | ||
const mid = patternsArr.map((group) => `(.*${ESGlobPatterns.escapeStr(group)})`); | ||
const end = lastItem?.length ? `(.*${ESGlobPatterns.escapeStr(lastItem)}$)` : ''; | ||
const regExArr = ['(^', start, ...mid, end, ')']; | ||
return regExArr.join(''); | ||
} | ||
|
||
private static escapeStr(str: string) { | ||
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/monitoring/public/alerts/flyout_expressions/alert_param_textfield.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { EuiFormRow, EuiFieldText } from '@elastic/eui'; | ||
|
||
interface Props { | ||
name: string; | ||
value: string; | ||
placeholder?: string; | ||
label: string; | ||
errors: string[]; | ||
setAlertParams: (property: string, value: string) => void; | ||
} | ||
export const AlertParamTextField: React.FC<Props> = (props: Props) => { | ||
const { name, label, setAlertParams, errors, placeholder } = props; | ||
const [value, setValue] = useState(props.value); | ||
return ( | ||
<EuiFormRow label={label} error={errors} isInvalid={errors?.length > 0}> | ||
<EuiFieldText | ||
compressed | ||
placeholder={placeholder} | ||
value={value} | ||
onChange={(e) => { | ||
const newValue = e.target.value; | ||
setValue(newValue); | ||
setAlertParams(name, newValue); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/monitoring/public/alerts/large_shard_size_alert/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { Expression, Props } from '../components/param_details_form/expression'; | ||
import { AlertTypeModel, ValidationResult } from '../../../../triggers_actions_ui/public'; | ||
import { ALERT_LARGE_SHARD_SIZE, ALERT_DETAILS } from '../../../common/constants'; | ||
import { AlertTypeParams } from '../../../../alerts/common'; | ||
|
||
interface ValidateOptions extends AlertTypeParams { | ||
indexPattern: string; | ||
} | ||
|
||
const validate = (inputValues: ValidateOptions): ValidationResult => { | ||
const validationResult = { errors: {} }; | ||
const errors: { [key: string]: string[] } = { | ||
indexPattern: [], | ||
}; | ||
if (!inputValues.indexPattern) { | ||
errors.indexPattern.push( | ||
i18n.translate('xpack.monitoring.alerts.validation.indexPattern', { | ||
defaultMessage: 'A valid index pattern/s is required.', | ||
}) | ||
); | ||
} | ||
validationResult.errors = errors; | ||
return validationResult; | ||
}; | ||
|
||
export function createLargeShardSizeAlertType(): AlertTypeModel<ValidateOptions> { | ||
return { | ||
id: ALERT_LARGE_SHARD_SIZE, | ||
description: ALERT_DETAILS[ALERT_LARGE_SHARD_SIZE].description, | ||
iconClass: 'bell', | ||
documentationUrl(docLinks) { | ||
return `${docLinks.links.monitoring.alertsKibana}`; | ||
}, | ||
alertParamsExpression: (props: Props) => ( | ||
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_LARGE_SHARD_SIZE].paramDetails} /> | ||
), | ||
validate, | ||
defaultActionMessage: '{{context.internalFullMessage}}', | ||
requiresAppContext: true, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to trigger right when I open the flyout. Should there be a default of
*
used?