Skip to content

Commit

Permalink
fix kibana metricsets property paths (elastic#122034)
Browse files Browse the repository at this point in the history
* fix kibana metricsets property paths

* return inner kibana object

* fix functional test

* rename

* adapt tests to datastream

* rebuild archived data

* extract buildKibanaInfo for reuse

* add license

* lint

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
klacabane and kibanamachine committed Dec 31, 2021
1 parent 81513dc commit 9aaf9a5
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 23,413 deletions.
16 changes: 10 additions & 6 deletions x-pack/plugins/monitoring/common/types/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ElasticsearchSourceKibanaStats {
};
transport_address?: string;
host?: string;
version?: string;
};
os?: {
memory?: {
Expand Down Expand Up @@ -416,7 +417,9 @@ export interface ElasticsearchMetricbeatNode {
export interface ElasticsearchMetricbeatSource {
'@timestamp'?: string;
service?: {
id?: string;
address?: string;
version?: string;
};
elasticsearch?: {
node?: ElasticsearchLegacySource['source_node'] & ElasticsearchMetricbeatNode;
Expand Down Expand Up @@ -534,15 +537,16 @@ export interface ElasticsearchMetricbeatSource {
};
};
kibana?: {
kibana?: {
transport_address?: string;
stats?: {
name?: string;
host?: string;
uuid?: string;
index?: string;
status?: string;
};
stats?: {
transport_address?: string;
concurrent_connections?: number;
snapshot?: boolean;
host?: {
name?: string;
};
process?: {
uptime?: {
ms?: number;
Expand Down
35 changes: 35 additions & 0 deletions x-pack/plugins/monitoring/server/lib/kibana/build_kibana_info.ts
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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ElasticsearchResponseHit } from '../../../common/types/es';

export interface KibanaInfo {
transport_address?: string;
name?: string;
index?: string;
host?: string;
uuid?: string;
status?: string;
snapshot?: boolean;
version?: string;
}

export const buildKibanaInfo = (hit: ElasticsearchResponseHit): KibanaInfo => {
const source = hit._source;
if (source.kibana_stats) return source.kibana_stats.kibana as KibanaInfo;

return {
name: source.kibana?.stats?.name,
host: source.kibana?.stats?.host?.name,
status: source.kibana?.stats?.status,
transport_address: source.kibana?.stats?.transport_address,
uuid: source.service?.id,
snapshot: source.kibana?.stats?.snapshot,
index: source.kibana?.stats?.index,
version: source.service?.version,
};
};
17 changes: 10 additions & 7 deletions x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import { checkParam, MissingRequiredError } from '../error_missing_required';
import { calculateAvailability } from '../calculate_availability';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';
import { buildKibanaInfo } from './build_kibana_info';

export function handleResponse(resp: ElasticsearchResponse) {
const legacySource = resp.hits?.hits[0]?._source.kibana_stats;
const mbSource = resp.hits?.hits[0]?._source.kibana?.stats;
const kibana = resp.hits?.hits[0]?._source.kibana?.kibana ?? legacySource?.kibana;
const availabilityTimestamp =
resp.hits?.hits[0]?._source['@timestamp'] ?? legacySource?.timestamp;
const hit = resp.hits?.hits[0];
const legacySource = hit?._source.kibana_stats;
const mbSource = hit?._source.kibana?.stats;
const availabilityTimestamp = hit?._source['@timestamp'] ?? legacySource?.timestamp;
if (!availabilityTimestamp) {
throw new MissingRequiredError('timestamp');
}
return merge(kibana, {

return merge(buildKibanaInfo(hit!), {
availability: calculateAvailability(availabilityTimestamp),
os_memory_free: mbSource?.os?.memory?.free_in_bytes ?? legacySource?.os?.memory?.free_in_bytes,
uptime: mbSource?.process?.uptime?.ms ?? legacySource?.process?.uptime_in_millis,
Expand All @@ -42,13 +43,15 @@ export function getKibanaInfo(
ignore_unavailable: true,
filter_path: [
'hits.hits._source.kibana_stats.kibana',
'hits.hits._source.kibana.kibana',
'hits.hits._source.kibana.stats',
'hits.hits._source.kibana_stats.os.memory.free_in_bytes',
'hits.hits._source.kibana.stats.os.memory.free_in_bytes',
'hits.hits._source.kibana_stats.process.uptime_in_millis',
'hits.hits._source.kibana.stats.process.uptime.ms',
'hits.hits._source.kibana_stats.timestamp',
'hits.hits._source.@timestamp',
'hits.hits._source.service.id',
'hits.hits._source.service.version',
],
body: {
query: {
Expand Down
25 changes: 10 additions & 15 deletions x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { calculateAvailability } from '../calculate_availability';
// @ts-ignore
import { KibanaMetric } from '../metrics';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';
import { ElasticsearchResponse, ElasticsearchResponseHit } from '../../../common/types/es';
import { KibanaInfo, buildKibanaInfo } from './build_kibana_info';

interface Kibana {
process?: {
Expand All @@ -36,13 +37,7 @@ interface Kibana {
total?: number;
};
concurrent_connections?: number;
kibana?: {
transport_address?: string;
name?: string;
host?: string;
uuid?: string;
status?: string;
};
kibana?: KibanaInfo;
availability: boolean;
}

Expand Down Expand Up @@ -98,15 +93,15 @@ export async function getKibanas(
'kibana_stats.requests.total',
'kibana.stats.request.total',
'kibana_stats.kibana.transport_address',
'kibana.kibana.transport_address',
'kibana.stats.transport_address',
'kibana_stats.kibana.name',
'kibana.kibana.name',
'kibana.stats.name',
'kibana_stats.kibana.host',
'kibana.kibana.host',
'kibana.stats.host.name',
'kibana_stats.kibana.uuid',
'kibana.kibana.uuid',
'service.id',
'kibana_stats.kibana.status',
'kibana.kibana.status',
'kibana.stats.status',
'kibana_stats.concurrent_connections',
'kibana.stats.concurrent_connections',
],
Expand All @@ -117,12 +112,12 @@ export async function getKibanas(
const response: ElasticsearchResponse = await callWithRequest(req, 'search', params);
const instances = response.hits?.hits ?? [];

return instances.map((hit) => {
return instances.map((hit: ElasticsearchResponseHit) => {
const legacyStats = hit._source.kibana_stats;
const mbStats = hit._source.kibana?.stats;

const kibana: Kibana = {
kibana: hit._source.kibana?.kibana ?? legacyStats?.kibana,
kibana: buildKibanaInfo(hit),
concurrent_connections:
mbStats?.concurrent_connections ?? legacyStats?.concurrent_connections,
process: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import expect from '@kbn/expect';
import { normalizeDataTypeDifferences } from '../normalize_data_type_differences';
import instanceFixture from './fixtures/instance';
import { getLifecycleMethods } from '../data_stream';

export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('instance detail mb', () => {
const archive =
Expand All @@ -22,11 +23,11 @@ export default function ({ getService }) {
};

before('load archive', () => {
return esArchiver.load(archive);
return setup(archive);
});

after('unload archive', () => {
return esArchiver.unload(archive);
return tearDown();
});

it('should summarize single kibana instance with metrics', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import expect from '@kbn/expect';
import listingFixture from './fixtures/listing';
import { getLifecycleMethods } from '../data_stream';

export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('listing mb', () => {
const archive =
Expand All @@ -21,11 +22,11 @@ export default function ({ getService }) {
};

before('load archive', () => {
return esArchiver.load(archive);
return setup(archive);
});

after('unload archive', () => {
return esArchiver.unload(archive);
return tearDown();
});

it('should summarize list of kibana instances with stats', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import expect from '@kbn/expect';
import { normalizeDataTypeDifferences } from '../normalize_data_type_differences';
import overviewFixture from './fixtures/overview';
import { getLifecycleMethods } from '../data_stream';

export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('overview mb', () => {
const archive =
Expand All @@ -22,11 +23,11 @@ export default function ({ getService }) {
};

before('load archive', () => {
return esArchiver.load(archive);
return setup(archive);
});

after('unload archive', () => {
return esArchiver.unload(archive);
return tearDown();
});

it('should summarize kibana instances with stats', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function ({ getService, getPageObjects }) {
{
from: 'Aug 29, 2017 @ 17:24:14.254',
to: 'Aug 29, 2017 @ 17:25:44.142',
useCreate: true,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function ({ getService, getPageObjects }) {
{
from: 'Aug 29, 2017 @ 17:24:14.254',
to: 'Aug 29, 2017 @ 17:25:44.142',
useCreate: true,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function ({ getService, getPageObjects }) {
{
from: 'Aug 29, 2017 @ 17:24:14.254',
to: 'Aug 29, 2017 @ 17:25:44.142',
useCreate: true,
}
);

Expand Down
Binary file not shown.
Loading

0 comments on commit 9aaf9a5

Please sign in to comment.