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

[Stack Monitoring] compatibility for agent data streams #119112

Merged
merged 73 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
1a1e5fa
update queries for elasticsearch package
neptunian Nov 18, 2021
eeb2c60
fix unit test
neptunian Nov 19, 2021
9424af7
add gitCcs helper function
neptunian Nov 19, 2021
94e05b2
modify rest of es queries
neptunian Nov 19, 2021
effdbb7
update logstash and kibana queries to use new createQuery
neptunian Nov 19, 2021
ed4196a
change beats and apm to use new createQuery
neptunian Nov 19, 2021
2d03cb6
update changeQuery and remove old one
neptunian Nov 19, 2021
09b8407
make getIndexPattern take request to check for ccs
neptunian Nov 19, 2021
2b9c104
fix unit test
neptunian Nov 20, 2021
f07710e
fix unit tests
neptunian Nov 20, 2021
2038d27
update queries and createQuery
neptunian Nov 22, 2021
d35a61a
don't add metric constant without dataset in query
neptunian Nov 23, 2021
ee8aa93
fix types
neptunian Nov 23, 2021
d41ea30
fix type
neptunian Nov 23, 2021
ea13b9f
comment out mb tests
neptunian Nov 23, 2021
a909d83
fix unit test
neptunian Nov 23, 2021
ecfee7e
fix unit test
neptunian Nov 23, 2021
88f84ba
fix
neptunian Nov 23, 2021
8894e22
fix function param
neptunian Nov 23, 2021
7b5f8e5
change to getMetrics name
neptunian Nov 23, 2021
513007d
change to node_stats
neptunian Nov 24, 2021
bf67c72
comment out metricbeat tests
neptunian Nov 24, 2021
f686e94
fix types
neptunian Nov 24, 2021
6298e2d
improve types and readability for test
neptunian Nov 29, 2021
42dd489
remove passing of data stream type for now
neptunian Nov 29, 2021
2d7698e
add tests for createQuery changes
neptunian Nov 29, 2021
7e7c8ca
update getNewIndexPatterns to take one dataset
neptunian Nov 30, 2021
55ee366
add unit test for getNewIndexPatterns
neptunian Nov 30, 2021
d850af2
fix types
neptunian Nov 30, 2021
501ca58
remove metrics from filter, update tests
neptunian Dec 1, 2021
805a2cb
update createNewIndexPatterns to accept new config instead of legacy
neptunian Dec 2, 2021
4e74a18
update alert queries to include datas stream index patterns
neptunian Dec 3, 2021
820fe52
update comment
neptunian Dec 3, 2021
e35453b
fix merge conflicts
neptunian Dec 13, 2021
8eeda28
fix defaulting ccs to * for non cluster requests
neptunian Dec 13, 2021
1670e92
update elasticsearch enterprise module
neptunian Dec 14, 2021
7774f07
update unit test
neptunian Dec 14, 2021
0b92576
remove data_stream.type from queries
neptunian Dec 14, 2021
d6f18ec
change entsearch to metricbeat module name enterprisesearch
neptunian Dec 14, 2021
191b4b0
undo ccs cluster stats change
neptunian Dec 14, 2021
b500886
fix import
neptunian Dec 14, 2021
8ef66e5
update alert queries
neptunian Dec 14, 2021
2a34e48
fix unit test
neptunian Dec 14, 2021
f4c011a
update unit test
neptunian Dec 14, 2021
ace5003
change shard size query to use filter
neptunian Dec 15, 2021
a16f212
change must to filter fix
neptunian Dec 15, 2021
e6dab77
Merge branch 'main' into 119109-es-integration-queries
neptunian Dec 15, 2021
81acb8b
update findSupportedBasicLicenseCluster index pattern
neptunian Dec 15, 2021
d0c95bf
add ccs param to cluster request functions
neptunian Dec 15, 2021
ff01aa8
update queries for ccs in get_clusters_from_request
neptunian Dec 15, 2021
0e852de
update getBeatsForClusters query
neptunian Dec 15, 2021
6c07737
update clusters apm query
neptunian Dec 15, 2021
9992708
update enterprisesearch query
neptunian Dec 15, 2021
c49698b
move index pattern to query in fetch for alerts, fix ccs
neptunian Dec 17, 2021
e4deebf
remove metricbeat config from alert tests
neptunian Dec 17, 2021
0d19914
Merge branch 'main' into 119109-es-integration-queries
neptunian Dec 17, 2021
4d170f2
fix ts
neptunian Dec 17, 2021
755e3f0
Merge branch 'main' into 119109-es-integration-queries
neptunian Dec 20, 2021
7f4989b
fix conflicts and update tests, add ecsLegacyOnly param
neptunian Jan 4, 2022
5dc264b
add metricset.name back to queries
neptunian Jan 5, 2022
a88fd55
comment tests back in
neptunian Jan 5, 2022
596b4c0
fix conflicts from logstash changes
neptunian Jan 5, 2022
e5c539f
remove enterprise search checking for standalone cluster to fix test
neptunian Jan 6, 2022
3213b43
update es index metricset name from index_stats to index for mb data
neptunian Jan 6, 2022
0996399
fix type
neptunian Jan 6, 2022
2b841e4
Merge branch 'main' into 119109-es-integration-queries
neptunian Jan 18, 2022
6878713
fetchClusters creates index pattern
neptunian Jan 18, 2022
dee9ac0
fix type
neptunian Jan 18, 2022
dfe3dd6
Merge branch 'main' into 119109-es-integration-queries
kibanamachine Jan 20, 2022
17b6b2a
Merge branch 'main' into 119109-es-integration-queries
kibanamachine Jan 20, 2022
ca549e4
remove monitoring.ui.metricbeat.index from config and usage in getCol…
neptunian Jan 20, 2022
648d582
Merge branch '119109-es-integration-queries' of github.com:neptunian/…
neptunian Jan 20, 2022
2379e9e
fix type
neptunian Jan 20, 2022
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
59 changes: 10 additions & 49 deletions x-pack/plugins/monitoring/common/ccs_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,17 @@ type Config = Partial<MonitoringConfig> & {
get?: (key: string) => any;
};

export function appendMetricbeatIndex(
config: Config,
indexPattern: string,
ccs?: string,
bypass: boolean = false
) {
if (bypass) {
return indexPattern;
}
// Leverage this function to also append the dynamic metricbeat index too
let mbIndex = null;
export function getConfigCcs(config: Config): boolean | string {
let ccsEnabled = false;
// TODO: NP
// This function is called with both NP config and LP config
if (isFunction(config.get)) {
mbIndex = config.get('monitoring.ui.metricbeat.index');
ccsEnabled = config.get('monitoring.ui.ccs.enabled');
} else {
mbIndex = get(config, 'ui.metricbeat.index');
}

if (ccs) {
mbIndex = `${mbIndex},${ccs}:${mbIndex}`;
ccsEnabled = get(config, 'ui.ccs.enabled');
}

return `${indexPattern},${mbIndex}`;
return ccsEnabled;
}

/**
* Prefix all comma separated index patterns within the original {@code indexPattern}.
*
Expand All @@ -50,44 +35,20 @@ export function appendMetricbeatIndex(
* @param {String} ccs The optional cluster-prefix to prepend.
* @return {String} The index pattern with the {@code cluster} prefix appropriately prepended.
*/
export function prefixIndexPattern(
config: Config,
indexPattern: string,
ccs?: string,
monitoringIndicesOnly: boolean = false
) {
let ccsEnabled = false;
// TODO: NP
// This function is called with both NP config and LP config
if (isFunction(config.get)) {
ccsEnabled = config.get('monitoring.ui.ccs.enabled');
} else {
ccsEnabled = get(config, 'ui.ccs.enabled');
}

export function prefixIndexPattern(config: Config, indexPattern: string, ccs?: string) {
const ccsEnabled = getConfigCcs(config);
if (!ccsEnabled || !ccs) {
return appendMetricbeatIndex(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop appending the metricbeat-* pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a thought here that there's a possibility people might be using monitoring.ui.metricbeat.index to append custom index patterns. Should we add a deprecation warning if that config key is specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever supported the user using this as it wasn't documented anywhere and we didn't technically support metricbeat-*. if that's the case would deprecating it be confusing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, okay if it's not in the docs I guess it's not bad to just let it go away silently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#120384 has me wondering if we should re-think this approach. I get the feeling there's more than 1 customer problem we've solved by reaching for monitoring.ui.metricbeat.index

Copy link
Contributor Author

@neptunian neptunian Dec 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we kept the config value there, we aren't using it anymore because we aren't querying metricbeat index anymore. If we recommended that kind of hack, hopefully we let the user know that. We probably should have discussed a fix whether we should be setting ccs to default to *.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I guess we could say merging this PR raises the importance of having a proper config (which is #120384)

config,
indexPattern,
ccsEnabled ? ccs : undefined,
monitoringIndicesOnly
);
return indexPattern;
}

const patterns = indexPattern.split(',');
const prefixedPattern = patterns.map((pattern) => `${ccs}:${pattern}`).join(',');

// if a wildcard is used, then we also want to search the local indices
if (ccs === '*') {
return appendMetricbeatIndex(
config,
`${prefixedPattern},${indexPattern}`,
ccs,
monitoringIndicesOnly
);
return `${prefixedPattern},${indexPattern}`;
}

return appendMetricbeatIndex(config, prefixedPattern, ccs, monitoringIndicesOnly);
return prefixedPattern;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/monitoring/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const INDEX_PATTERN_LOGSTASH = '.monitoring-logstash-6-*,.monitoring-logs
export const INDEX_PATTERN_BEATS = '.monitoring-beats-6-*,.monitoring-beats-7-*';
export const INDEX_ALERTS = '.monitoring-alerts-6*,.monitoring-alerts-7*';
export const INDEX_PATTERN_ELASTICSEARCH = '.monitoring-es-6-*,.monitoring-es-7-*';
export const DS_INDEX_PATTERN_METRICS = 'metrics';
export const DS_INDEX_PATTERN_LOGS = 'logs';
export const DS_INDEX_PATTERN_ES = 'elasticsearch';
export const INDEX_PATTERN_ENTERPRISE_SEARCH = '.monitoring-ent-search-*';

// This is the unique token that exists in monitoring indices collected by metricbeat
Expand Down Expand Up @@ -584,3 +587,12 @@ export const ALERT_EMAIL_SERVICES = ['gmail', 'hotmail', 'icloud', 'outlook365',
export const SAVED_OBJECT_TELEMETRY = 'monitoring-telemetry';

export const TELEMETRY_METRIC_BUTTON_CLICK = 'btnclick__';

export type INDEX_PATTERN_TYPES =
| 'elasticsearch'
| 'kibana'
| 'logstash'
| 'beats'
| 'enterprisesearch';

export type DS_INDEX_PATTERN_TYPES = typeof DS_INDEX_PATTERN_METRICS | typeof DS_INDEX_PATTERN_LOGS;
30 changes: 11 additions & 19 deletions x-pack/plugins/monitoring/server/alerts/base_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import {
CommonAlertParams,
} from '../../common/types/alerts';
import { fetchClusters } from '../lib/alerts/fetch_clusters';
import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern';
import { INDEX_PATTERN_ELASTICSEARCH } from '../../common/constants';
import { AlertSeverity } from '../../common/enums';
import { appendMetricbeatIndex } from '../lib/alerts/append_mb_index';
import { parseDuration } from '../../../alerting/common';
import { Globals } from '../static_globals';
import { getNewIndexPatterns } from '../lib/cluster/get_index_patterns';

type ExecutedState =
| {
Expand Down Expand Up @@ -226,23 +224,18 @@ export class BaseRule {
);

const esClient = services.scopedClusterClient.asCurrentUser;
const availableCcs = Globals.app.config.ui.ccs.enabled;
const clusters = await this.fetchClusters(esClient, params as CommonAlertParams, availableCcs);
const data = await this.fetchData(params, esClient, clusters, availableCcs);
const clusters = await this.fetchClusters(esClient, params as CommonAlertParams);
const data = await this.fetchData(params, esClient, clusters);
return await this.processData(data, clusters, services, state);
}

protected async fetchClusters(
esClient: ElasticsearchClient,
params: CommonAlertParams,
ccs?: boolean
) {
let esIndexPattern = appendMetricbeatIndex(Globals.app.config, INDEX_PATTERN_ELASTICSEARCH);
if (ccs) {
esIndexPattern = getCcsIndexPattern(esIndexPattern, ccs);
}
protected async fetchClusters(esClient: ElasticsearchClient, params: CommonAlertParams) {
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType: 'elasticsearch',
});
if (!params.limit) {
return await fetchClusters(esClient, esIndexPattern);
return await fetchClusters(esClient, indexPatterns);
}
const limit = parseDuration(params.limit);
const rangeFilter = this.ruleOptions.fetchClustersRange
Expand All @@ -253,14 +246,13 @@ export class BaseRule {
},
}
: undefined;
return await fetchClusters(esClient, esIndexPattern, rangeFilter);
return await fetchClusters(esClient, indexPatterns, rangeFilter);
}

protected async fetchData(
params: CommonAlertParams | unknown,
esClient: ElasticsearchClient,
clusters: AlertCluster[],
availableCcs: boolean
clusters: AlertCluster[]
): Promise<Array<AlertData & unknown>> {
throw new Error('Child classes must implement `fetchData`');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ import {
CCRReadExceptionsStats,
} from '../../common/types/alerts';
import { AlertInstance } from '../../../alerting/server';
import {
INDEX_PATTERN_ELASTICSEARCH,
RULE_CCR_READ_EXCEPTIONS,
RULE_DETAILS,
} from '../../common/constants';
import { RULE_CCR_READ_EXCEPTIONS, RULE_DETAILS } from '../../common/constants';
import { fetchCCRReadExceptions } from '../lib/alerts/fetch_ccr_read_exceptions';
import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern';
import { AlertMessageTokenType, AlertSeverity } from '../../common/enums';
import { parseDuration } from '../../../alerting/common/parse_duration';
import { SanitizedAlert, RawAlertInstance } from '../../../alerting/common';
import { AlertingDefaults, createLink } from './alert_helpers';
import { appendMetricbeatIndex } from '../lib/alerts/append_mb_index';
import { Globals } from '../static_globals';
import { getNewIndexPatterns } from '../lib/cluster/get_index_patterns';

export class CCRReadExceptionsRule extends BaseRule {
constructor(public sanitizedRule?: SanitizedAlert) {
Expand Down Expand Up @@ -72,20 +67,20 @@ export class CCRReadExceptionsRule extends BaseRule {
protected async fetchData(
params: CommonAlertParams,
esClient: ElasticsearchClient,
clusters: AlertCluster[],
availableCcs: boolean
clusters: AlertCluster[]
): Promise<AlertData[]> {
let esIndexPattern = appendMetricbeatIndex(Globals.app.config, INDEX_PATTERN_ELASTICSEARCH);
if (availableCcs) {
esIndexPattern = getCcsIndexPattern(esIndexPattern, availableCcs);
}
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType: 'elasticsearch',
dataset: 'ccr',
});
const { duration: durationString } = params;
const duration = parseDuration(durationString);
const endMs = +new Date();
const startMs = endMs - duration;
const stats = await fetchCCRReadExceptions(
esClient,
esIndexPattern,
indexPatterns,
startMs,
endMs,
Globals.app.config.ui.max_bucket_size,
Expand Down
28 changes: 9 additions & 19 deletions x-pack/plugins/monitoring/server/alerts/cluster_health_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ import {
AlertInstanceState,
} from '../../common/types/alerts';
import { AlertInstance } from '../../../alerting/server';
import {
RULE_CLUSTER_HEALTH,
LEGACY_RULE_DETAILS,
INDEX_PATTERN_ELASTICSEARCH,
} from '../../common/constants';
import { RULE_CLUSTER_HEALTH, LEGACY_RULE_DETAILS } from '../../common/constants';
import { AlertMessageTokenType, AlertClusterHealthType, AlertSeverity } from '../../common/enums';
import { AlertingDefaults } from './alert_helpers';
import { SanitizedAlert } from '../../../alerting/common';
import { Globals } from '../static_globals';
import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern';
import { appendMetricbeatIndex } from '../lib/alerts/append_mb_index';
import { fetchClusterHealth } from '../lib/alerts/fetch_cluster_health';
import { getNewIndexPatterns } from '../lib/cluster/get_index_patterns';

const RED_STATUS_MESSAGE = i18n.translate('xpack.monitoring.alerts.clusterHealth.redMessage', {
defaultMessage: 'Allocate missing primary and replica shards',
Expand Down Expand Up @@ -66,19 +61,14 @@ export class ClusterHealthRule extends BaseRule {
protected async fetchData(
params: CommonAlertParams,
esClient: ElasticsearchClient,
clusters: AlertCluster[],
availableCcs: boolean
clusters: AlertCluster[]
): Promise<AlertData[]> {
let esIndexPattern = appendMetricbeatIndex(Globals.app.config, INDEX_PATTERN_ELASTICSEARCH);
if (availableCcs) {
esIndexPattern = getCcsIndexPattern(esIndexPattern, availableCcs);
}
const healths = await fetchClusterHealth(
esClient,
clusters,
esIndexPattern,
params.filterQuery
);
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType: 'elasticsearch',
dataset: 'cluster_stats',
});
const healths = await fetchClusterHealth(esClient, clusters, indexPatterns, params.filterQuery);
return healths.map((clusterHealth) => {
const shouldFire = clusterHealth.health !== AlertClusterHealthType.Green;
const severity =
Expand Down
19 changes: 9 additions & 10 deletions x-pack/plugins/monitoring/server/alerts/cpu_usage_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ import {
CommonAlertFilter,
} from '../../common/types/alerts';
import { AlertInstance } from '../../../alerting/server';
import { INDEX_PATTERN_ELASTICSEARCH, RULE_CPU_USAGE, RULE_DETAILS } from '../../common/constants';
import { RULE_CPU_USAGE, RULE_DETAILS } from '../../common/constants';
// @ts-ignore
import { ROUNDED_FLOAT } from '../../common/formatting';
import { fetchCpuUsageNodeStats } from '../lib/alerts/fetch_cpu_usage_node_stats';
import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern';
import { AlertMessageTokenType, AlertSeverity } from '../../common/enums';
import { RawAlertInstance, SanitizedAlert } from '../../../alerting/common';
import { parseDuration } from '../../../alerting/common/parse_duration';
import { AlertingDefaults, createLink } from './alert_helpers';
import { appendMetricbeatIndex } from '../lib/alerts/append_mb_index';
import { Globals } from '../static_globals';
import { getNewIndexPatterns } from '../lib/cluster/get_index_patterns';

export class CpuUsageRule extends BaseRule {
constructor(public sanitizedRule?: SanitizedAlert) {
Expand All @@ -60,20 +59,20 @@ export class CpuUsageRule extends BaseRule {
protected async fetchData(
params: CommonAlertParams,
esClient: ElasticsearchClient,
clusters: AlertCluster[],
availableCcs: boolean
clusters: AlertCluster[]
): Promise<AlertData[]> {
let esIndexPattern = appendMetricbeatIndex(Globals.app.config, INDEX_PATTERN_ELASTICSEARCH);
if (availableCcs) {
esIndexPattern = getCcsIndexPattern(esIndexPattern, availableCcs);
}
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType: 'elasticsearch',
dataset: 'node_stats',
});
const duration = parseDuration(params.duration);
const endMs = +new Date();
const startMs = endMs - duration;
const stats = await fetchCpuUsageNodeStats(
esClient,
clusters,
esIndexPattern,
indexPatterns,
startMs,
endMs,
Globals.app.config.ui.max_bucket_size,
Expand Down
19 changes: 9 additions & 10 deletions x-pack/plugins/monitoring/server/alerts/disk_usage_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ import {
CommonAlertFilter,
} from '../../common/types/alerts';
import { AlertInstance } from '../../../alerting/server';
import { INDEX_PATTERN_ELASTICSEARCH, RULE_DISK_USAGE, RULE_DETAILS } from '../../common/constants';
import { RULE_DISK_USAGE, RULE_DETAILS } from '../../common/constants';
// @ts-ignore
import { ROUNDED_FLOAT } from '../../common/formatting';
import { fetchDiskUsageNodeStats } from '../lib/alerts/fetch_disk_usage_node_stats';
import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern';
import { AlertMessageTokenType, AlertSeverity } from '../../common/enums';
import { RawAlertInstance, SanitizedAlert } from '../../../alerting/common';
import { AlertingDefaults, createLink } from './alert_helpers';
import { appendMetricbeatIndex } from '../lib/alerts/append_mb_index';
import { Globals } from '../static_globals';
import { getNewIndexPatterns } from '../lib/cluster/get_index_patterns';

export class DiskUsageRule extends BaseRule {
constructor(public sanitizedRule?: SanitizedAlert) {
Expand All @@ -59,18 +58,18 @@ export class DiskUsageRule extends BaseRule {
protected async fetchData(
params: CommonAlertParams,
esClient: ElasticsearchClient,
clusters: AlertCluster[],
availableCcs: boolean
clusters: AlertCluster[]
): Promise<AlertData[]> {
let esIndexPattern = appendMetricbeatIndex(Globals.app.config, INDEX_PATTERN_ELASTICSEARCH);
if (availableCcs) {
esIndexPattern = getCcsIndexPattern(esIndexPattern, availableCcs);
}
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType: 'elasticsearch',
dataset: 'node_stats',
});
const { duration, threshold } = params;
const stats = await fetchDiskUsageNodeStats(
esClient,
clusters,
esIndexPattern,
indexPatterns,
duration as string,
Globals.app.config.ui.max_bucket_size,
params.filterQuery
Expand Down
Loading