Skip to content

Commit

Permalink
[Stack Monitoring] support entsearch package (#148668)
Browse files Browse the repository at this point in the history
### Summary

Update stack monitoring to read from data streams created by the
[enterprisesearch
package](elastic/integrations#4926)

### Testing
- build [enterprisesearch
package](elastic/integrations#4926)
- start stack: `elastic-package stack up -v -d --version
8.7.0-SNAPSHOT`; make sure your image contains [this
change](elastic/elastic-agent#2121)
- start enterprisesearch service: `elastic-package service up -v`
- install elasticsearch integration with variables
- `hosts: http://host.docker.internal:9201; username: elastic; password:
changeme`
- install enterprisesearch integration with variables
- `hosts: http://host.docker.internal:3002; username: elastic; password:
changeme`
- connect [local
kibana](https://github.com/elastic/kibana/blob/2d893bf40b47864058065f8fd2998d63c87f65f9/x-pack/plugins/monitoring/dev_docs/how_to/work_with_packages.md#connecting-a-local-kibana)
- navigate to Stack Monitoring on the local kibana, enterprise search
section shows up with populated graphs

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
klacabane and kibanamachine authored Jan 30, 2023
1 parent 7eaa352 commit 870f79d
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 28 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const BEATS_SYSTEM_ID = 'beats';
* The name of the Enterprise Search System ID used to publish and look up Enterprise Search stats through the Monitoring system.
* @type {string}
*/
export const ENTERPRISE_SEARCH_SYSTEM_ID = 'enterprise_search';
export const ENTERPRISE_SEARCH_SYSTEM_ID = 'enterprisesearch';

/**
* The name of the Apm System ID used to publish and look up Apm stats through the Monitoring system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function getLegacyIndexPattern({
case 'beats':
indexPattern = INDEX_PATTERN_BEATS;
break;
case 'enterprise_search':
case 'enterprisesearch':
indexPattern = INDEX_PATTERN_ENTERPRISE_SEARCH;
break;
case 'filebeat':
Expand Down Expand Up @@ -127,6 +127,7 @@ export const getElasticsearchDataset = getDataset('elasticsearch');
export const getKibanaDataset = getDataset('kibana');
export const getLogstashDataset = getDataset('logstash');
export const getBeatDataset = getDataset('beats');
export const getEntsearchDataset = getDataset('enterprisesearch');

function buildDatasetPattern(
moduleType?: INDEX_PATTERN_TYPES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { EnterpriseSearchMetric, EnterpriseSearchMetricFields } from '../metrics';
import { createQuery } from '../create_query';
import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
import { getEntsearchDataset } from '../cluster/get_index_patterns';

/**
* {@code createQuery} for all Enterprise Search instances.
Expand Down Expand Up @@ -53,6 +54,8 @@ export function createEnterpriseSearchQuery(options: {
},
{ term: { 'event.dataset': 'enterprisesearch.health' } },
{ term: { 'event.dataset': 'enterprisesearch.stats' } },
{ term: { 'data_stream.dataset': getEntsearchDataset('health') } },
{ term: { 'data_stream.dataset': getEntsearchDataset('stats') } },
],
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TimeRange } from '../../../common/http_api/shared';
import { ElasticsearchResponse } from '../../../common/types/es';
import { Globals } from '../../static_globals';
import { Cluster, LegacyRequest } from '../../types';
import { getLegacyIndexPattern } from '../cluster/get_index_patterns';
import { getIndexPatterns } from '../cluster/get_index_patterns';
import { EnterpriseSearchMetric } from '../metrics';
import { createEnterpriseSearchQuery } from './create_enterprise_search_query';
import {
Expand Down Expand Up @@ -37,8 +37,8 @@ export function getEnterpriseSearchForClusters(
const config = req.server.config;
const maxBucketSize = config.ui.max_bucket_size;

const indexPatterns = getLegacyIndexPattern({
moduleType: 'enterprise_search',
const indexPatterns = getIndexPatterns({
moduleType: 'enterprisesearch',
ccs,
config: Globals.app.config,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TimeRange } from '../../../common/http_api/shared';
import { ElasticsearchResponse } from '../../../common/types/es';
import { Globals } from '../../static_globals';
import { LegacyRequest } from '../../types';
import { getLegacyIndexPattern } from '../cluster/get_index_patterns';
import { getIndexPatterns } from '../cluster/get_index_patterns';
import { createEnterpriseSearchQuery } from './create_enterprise_search_query';
import {
entSearchAggFilterPath,
Expand All @@ -27,9 +27,8 @@ export async function getStats(
const end = moment.utc(req.payload.timeRange.max).valueOf();
const maxBucketSize = config.ui.max_bucket_size;

// just get the legacy pattern since no integration exists yet
const indexPattern = getLegacyIndexPattern({
moduleType: 'enterprise_search',
const indexPattern = getIndexPatterns({
moduleType: 'enterprisesearch',
config: Globals.app.config,
ccs: req.payload.ccs,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface Bucket {
};
}

type COLLECTION_PRODUCT_NAMES = Exclude<INDEX_PATTERN_TYPES, 'enterprise_search'>;
type COLLECTION_PRODUCT_NAMES = Exclude<INDEX_PATTERN_TYPES, 'enterprisesearch'>;

const NUMBER_OF_SECONDS_AGO_TO_LOOK = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { MetricbeatMonitoredProduct, PackagesMonitoredProduct, QueryOptions } from '../types';
import type { MonitoredProduct, QueryOptions } from '../types';

const MAX_BUCKET_SIZE = 50;

Expand All @@ -14,7 +14,7 @@ const MAX_BUCKET_SIZE = 50;
* Each module (beats, kibana...) can contain one or multiple metricsets with error messages
*/
interface ErrorsQueryOptions extends QueryOptions {
products: MetricbeatMonitoredProduct[] | PackagesMonitoredProduct[];
products: Array<Exclude<MonitoredProduct, MonitoredProduct.Cluster>>;
errorQueryType: 'metricbeatErrorsQuery' | 'packageErrorsQuery';
errorQueryIsDataStream?: boolean;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ export const errorsQuery = ({
},
{
range: {
timestamp: {
'@timestamp': {
gte: timeRange.min,
lte: timeRange.max,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ export function registerV1HealthRoute(server: MonitoringCore) {
getDsIndexPattern({ config, moduleType: 'kibana' }),
getDsIndexPattern({ config, moduleType: 'logstash' }),
getDsIndexPattern({ config, moduleType: 'beats' }),
getDsIndexPattern({ config, moduleType: 'enterprisesearch' }),
].join(',');

const entSearchIndex = getIndexPatterns({ config, moduleType: 'enterprise_search' });
const entSearchIndex = getIndexPatterns({ config, moduleType: 'enterprisesearch' });

const monitoredClustersFn = () =>
fetchMonitoredClusters({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const metricbeatMonitoring7Pattern =
/(.*:)?\.monitoring-(es|kibana|beats|logstash|ent-search)-7.*-mb.*/;
const metricbeatMonitoring8Pattern =
/(.*:)?\.ds-\.monitoring-(es|kibana|beats|logstash|ent-search)-8-mb.*/;
const packagePattern = /(.*:)?\.ds-metrics-(elasticsearch|kibana|beats|logstash)\..*/;
const packagePattern =
/(.*:)?\.ds-metrics-(elasticsearch|kibana|beats|logstash|enterprisesearch)\..*/;

const getCollectionMode = (index: string): CollectionMode => {
if (internalMonitoringPattern.test(index)) return CollectionMode.Internal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe(__filename, () => {
{
key: 'cluster-id.1',
doc_count: 11874,
enterpriseSearch: {
enterprisesearch: {
meta: {},
doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
Expand Down Expand Up @@ -310,7 +310,7 @@ describe(__filename, () => {
},
},

enterpriseSearch: {
enterprisesearch: {
'ent-search-node-id.1': {
health: {
'metricbeat-8': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getElasticsearchDataset,
getKibanaDataset,
getLogstashDataset,
getEntsearchDataset,
} from '../../../../../lib/cluster/get_index_patterns';

const MAX_BUCKET_SIZE = 100;
Expand Down Expand Up @@ -187,7 +188,7 @@ export const enterpriseSearchQuery = ({ timeRange, timeout }: QueryOptions) => {
size: MAX_BUCKET_SIZE,
},
aggs: {
enterpriseSearch: {
enterprisesearch: {
terms: {
field: 'agent.id',
},
Expand All @@ -202,6 +203,11 @@ export const enterpriseSearchQuery = ({ timeRange, timeout }: QueryOptions) => {
'metricset.name': 'health',
},
},
{
term: {
'data_stream.dataset': getEntsearchDataset('health'),
},
},
],
},
},
Expand All @@ -219,6 +225,11 @@ export const enterpriseSearchQuery = ({ timeRange, timeout }: QueryOptions) => {
'metricset.name': 'stats',
},
},
{
term: {
'data_stream.dataset': getEntsearchDataset('stats'),
},
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const fetchPackageErrors = async ({
MonitoredProduct.Elasticsearch,
MonitoredProduct.Kibana,
MonitoredProduct.Logstash,
MonitoredProduct.EnterpriseSearch,
],
errorQueryType: 'packageErrorsQuery',
errorQueryIsDataStream: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ export enum MonitoredProduct {
Kibana = 'kibana',
Beats = 'beat',
Logstash = 'logstash',
EnterpriseSearch = 'enterpriseSearch',
EnterpriseSearch = 'enterprisesearch',
}
export type MetricbeatMonitoredProduct = Exclude<MonitoredProduct, MonitoredProduct.Cluster>;
export type PackagesMonitoredProduct = Exclude<
MetricbeatMonitoredProduct,
MonitoredProduct.EnterpriseSearch
>;

export type SearchFn = (params: any) => Promise<ElasticsearchResponse>;

export interface QueryOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function entSearchOverviewRoute(server: MonitoringCore) {
try {
const [stats, metrics] = await Promise.all([
getStats(req, clusterUuid),
getMetrics(req, 'enterprise_search', metricSet, [], {
getMetrics(req, 'enterprisesearch', metricSet, [], {
skipClusterUuidFilter: true,
}),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { FtrProviderContext } from '../../../api_integration/ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Enterprisesearch', () => {
loadTestFile(require.resolve('./overview'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { getTestRunner } from '../../utils/test_runner';

import response from '../../fixtures/enterprisesearch/overview.json';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

const testRunner = getTestRunner({
testName: 'Overview',
archiveRoot: 'x-pack/test/monitoring_api_integration/archives/enterprisesearch',
getService,
});

const timeRange = {
min: '2023-01-11T20:54:00.000Z',
max: '2023-01-11T21:01:00.000Z',
};

testRunner(() => {
it('should summarize enterprisesearch cluster with metrics', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/FDTNEesSQ7GbzOXIO9qImw/enterprise_search')
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);

expect(body).to.eql(response);
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/monitoring_api_integration/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
describe('Monitoring Endpoints', function () {
loadTestFile(require.resolve('./apm'));
loadTestFile(require.resolve('./beats'));
loadTestFile(require.resolve('./enterprisesearch'));
});
}
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
5 changes: 4 additions & 1 deletion x-pack/test/monitoring_api_integration/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import path from 'path';

const PACKAGES = [{ name: 'beat', version: '0.0.1' }];
const PACKAGES = [
{ name: 'beat', version: '0.0.1' },
{ name: 'enterprisesearch', version: '1.0.0' },
];

export const getPackagesArgs = (): string[] => {
return PACKAGES.flatMap((pkg, i) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const {
? 'kibana'
: source.beat
? 'beats'
: source.enterprisesearch
? 'ent-search'
: source.elasticsearch
? 'es'
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getLifecycleMethods = (getService: FtrProviderContext['getService']
// the tests suites. since the archiver doesn't have any reference to the
// mappings it can't automatically delete it and we have to do the cleanup manually
await deleteDataStream('.monitoring-*');
await deleteDataStream('metrics-beats.stack_monitoring.*');
await deleteDataStream('metrics-*.stack_monitoring.*');
},
};
};

0 comments on commit 870f79d

Please sign in to comment.