Skip to content

Commit 697fe28

Browse files
[Monitoring] Revert direct shipping code (#72505) (#72845)
* Backout these changes * Fix test # Conflicts: # x-pack/plugins/monitoring/server/config.test.ts Co-authored-by: Elastic Machine <[email protected]>
1 parent 49ef8bc commit 697fe28

File tree

5 files changed

+5
-202
lines changed

5 files changed

+5
-202
lines changed

x-pack/plugins/monitoring/server/config.test.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,6 @@ describe('config schema', () => {
2727
},
2828
"enabled": true,
2929
},
30-
"elasticsearch": Object {
31-
"apiVersion": "7.x",
32-
"customHeaders": Object {},
33-
"healthCheck": Object {
34-
"delay": "PT2.5S",
35-
},
36-
"ignoreVersionMismatch": false,
37-
"logFetchCount": 10,
38-
"logQueries": false,
39-
"pingTimeout": "PT30S",
40-
"preserveHost": true,
41-
"requestHeadersWhitelist": Array [
42-
"authorization",
43-
],
44-
"requestTimeout": "PT30S",
45-
"shardTimeout": "PT30S",
46-
"sniffInterval": false,
47-
"sniffOnConnectionFault": false,
48-
"sniffOnStart": false,
49-
"ssl": Object {
50-
"alwaysPresentCertificate": false,
51-
"keystore": Object {},
52-
"truststore": Object {},
53-
"verificationMode": "full",
54-
},
55-
"startupTimeout": "PT5S",
56-
},
5730
"enabled": true,
5831
"kibana": Object {
5932
"collection": Object {
@@ -125,17 +98,13 @@ describe('createConfig()', () => {
12598
it('should wrap in Elasticsearch config', async () => {
12699
const config = createConfig(
127100
configSchema.validate({
128-
elasticsearch: {
129-
hosts: 'http://localhost:9200',
130-
},
131101
ui: {
132102
elasticsearch: {
133103
hosts: 'http://localhost:9200',
134104
},
135105
},
136106
})
137107
);
138-
expect(config.elasticsearch.hosts).toEqual(['http://localhost:9200']);
139108
expect(config.ui.elasticsearch.hosts).toEqual(['http://localhost:9200']);
140109
});
141110

@@ -147,9 +116,6 @@ describe('createConfig()', () => {
147116
};
148117
const config = createConfig(
149118
configSchema.validate({
150-
elasticsearch: {
151-
ssl,
152-
},
153119
ui: {
154120
elasticsearch: {
155121
ssl,
@@ -162,7 +128,6 @@ describe('createConfig()', () => {
162128
key: 'contents-of-packages/kbn-dev-utils/certs/elasticsearch.key',
163129
certificateAuthorities: ['contents-of-packages/kbn-dev-utils/certs/ca.crt'],
164130
});
165-
expect(config.elasticsearch.ssl).toEqual(expected);
166131
expect(config.ui.elasticsearch.ssl).toEqual(expected);
167132
});
168133
});

x-pack/plugins/monitoring/server/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const monitoringElasticsearchConfigSchema = elasticsearchConfigSchema.ext
2121

2222
export const configSchema = schema.object({
2323
enabled: schema.boolean({ defaultValue: true }),
24-
elasticsearch: monitoringElasticsearchConfigSchema,
2524
ui: schema.object({
2625
enabled: schema.boolean({ defaultValue: true }),
2726
ccs: schema.object({
@@ -86,7 +85,6 @@ export type MonitoringConfig = ReturnType<typeof createConfig>;
8685
export function createConfig(config: TypeOf<typeof configSchema>) {
8786
return {
8887
...config,
89-
elasticsearch: new ElasticsearchConfig(config.elasticsearch as ElasticsearchConfigType),
9088
ui: {
9189
...config.ui,
9290
elasticsearch: new MonitoringElasticsearchConfig(config.ui.elasticsearch),

x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
import { noop } from 'lodash';
88
import sinon from 'sinon';
9-
import moment from 'moment';
109
import expect from '@kbn/expect';
1110
import { BulkUploader } from '../bulk_uploader';
12-
import { MONITORING_SYSTEM_API_VERSION } from '../../../common/constants';
1311

1412
const FETCH_INTERVAL = 300;
1513
const CHECK_DELAY = 500;
@@ -314,92 +312,5 @@ describe('BulkUploader', () => {
314312
done();
315313
}, CHECK_DELAY);
316314
});
317-
318-
it('uses a direct connection to the monitoring cluster, when configured', (done) => {
319-
const dateInIndex = '2020.02.10';
320-
const oldNow = moment.now;
321-
moment.now = () => 1581310800000;
322-
const prodClusterUuid = '1sdfd5';
323-
const prodCluster = {
324-
callWithInternalUser: sinon
325-
.stub()
326-
.withArgs('monitoring.bulk')
327-
.callsFake((arg) => {
328-
let resolution = null;
329-
if (arg === 'info') {
330-
resolution = { cluster_uuid: prodClusterUuid };
331-
}
332-
return new Promise((resolve) => resolve(resolution));
333-
}),
334-
};
335-
const monitoringCluster = {
336-
callWithInternalUser: sinon
337-
.stub()
338-
.withArgs('bulk')
339-
.callsFake(() => {
340-
return new Promise((resolve) => setTimeout(resolve, CHECK_DELAY + 1));
341-
}),
342-
};
343-
344-
const collectorFetch = sinon.stub().returns({
345-
type: 'kibana_stats',
346-
result: { type: 'kibana_stats', payload: { testData: 12345 } },
347-
});
348-
349-
const collectors = new MockCollectorSet(server, [
350-
{
351-
fetch: collectorFetch,
352-
isReady: () => true,
353-
formatForBulkUpload: (result) => result,
354-
isUsageCollector: false,
355-
},
356-
]);
357-
const customServer = {
358-
...server,
359-
elasticsearchPlugin: {
360-
createCluster: () => monitoringCluster,
361-
getCluster: (name) => {
362-
if (name === 'admin' || name === 'data') {
363-
return prodCluster;
364-
}
365-
return monitoringCluster;
366-
},
367-
},
368-
config: {
369-
get: (key) => {
370-
if (key === 'monitoring.elasticsearch') {
371-
return {
372-
hosts: ['http://localhost:9200'],
373-
username: 'tester',
374-
password: 'testing',
375-
ssl: {},
376-
};
377-
}
378-
return null;
379-
},
380-
},
381-
};
382-
const kbnServerStatus = { toJSON: () => ({ overall: { state: 'green' } }) };
383-
const kbnServerVersion = 'master';
384-
const uploader = new BulkUploader({
385-
...customServer,
386-
interval: FETCH_INTERVAL,
387-
kbnServerStatus,
388-
kbnServerVersion,
389-
});
390-
uploader.start(collectors);
391-
setTimeout(() => {
392-
uploader.stop();
393-
const firstCallArgs = monitoringCluster.callWithInternalUser.firstCall.args;
394-
expect(firstCallArgs[0]).to.be('bulk');
395-
expect(firstCallArgs[1].body[0].index._index).to.be(
396-
`.monitoring-kibana-${MONITORING_SYSTEM_API_VERSION}-${dateInIndex}`
397-
);
398-
expect(firstCallArgs[1].body[1].type).to.be('kibana_stats');
399-
expect(firstCallArgs[1].body[1].cluster_uuid).to.be(prodClusterUuid);
400-
moment.now = oldNow;
401-
done();
402-
}, CHECK_DELAY);
403-
});
404315
});
405316
});

x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { defaultsDeep, uniq, compact, get } from 'lodash';
7+
import { defaultsDeep, uniq, compact } from 'lodash';
88

99
import {
1010
TELEMETRY_COLLECTION_INTERVAL,
1111
KIBANA_STATS_TYPE_MONITORING,
1212
} from '../../common/constants';
1313

1414
import { sendBulkPayload, monitoringBulk } from './lib';
15-
import { hasMonitoringCluster } from '../es_client/instantiate_client';
1615

1716
/*
1817
* Handles internal Kibana stats collection and uploading data to Monitoring
@@ -31,13 +30,11 @@ import { hasMonitoringCluster } from '../es_client/instantiate_client';
3130
* @param {Object} xpackInfo server.plugins.xpack_main.info object
3231
*/
3332
export class BulkUploader {
34-
constructor({ config, log, interval, elasticsearch, kibanaStats }) {
33+
constructor({ log, interval, elasticsearch, kibanaStats }) {
3534
if (typeof interval !== 'number') {
3635
throw new Error('interval number of milliseconds is required');
3736
}
3837

39-
this._hasDirectConnectionToMonitoringCluster = false;
40-
this._productionClusterUuid = null;
4138
this._timer = null;
4239
// Hold sending and fetching usage until monitoring.bulk is successful. This means that we
4340
// send usage data on the second tick. But would save a lot of bandwidth fetching usage on
@@ -54,15 +51,6 @@ export class BulkUploader {
5451
plugins: [monitoringBulk],
5552
});
5653

57-
if (hasMonitoringCluster(config.elasticsearch)) {
58-
this._log.info(`Detected direct connection to monitoring cluster`);
59-
this._hasDirectConnectionToMonitoringCluster = true;
60-
this._cluster = elasticsearch.legacy.createClient('monitoring-direct', config.elasticsearch);
61-
elasticsearch.legacy.client.callAsInternalUser('info').then((data) => {
62-
this._productionClusterUuid = get(data, 'cluster_uuid');
63-
});
64-
}
65-
6654
this.kibanaStats = kibanaStats;
6755
this.kibanaStatusGetter = null;
6856
}
@@ -181,14 +169,7 @@ export class BulkUploader {
181169
}
182170

183171
async _onPayload(payload) {
184-
return await sendBulkPayload(
185-
this._cluster,
186-
this._interval,
187-
payload,
188-
this._log,
189-
this._hasDirectConnectionToMonitoringCluster,
190-
this._productionClusterUuid
191-
);
172+
return await sendBulkPayload(this._cluster, this._interval, payload, this._log);
192173
}
193174

194175
getKibanaStats(type) {

x-pack/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,12 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import moment from 'moment';
7-
import { chunk, get } from 'lodash';
8-
import {
9-
MONITORING_SYSTEM_API_VERSION,
10-
KIBANA_SYSTEM_ID,
11-
KIBANA_STATS_TYPE_MONITORING,
12-
KIBANA_SETTINGS_TYPE,
13-
} from '../../../common/constants';
14-
15-
const SUPPORTED_TYPES = [KIBANA_STATS_TYPE_MONITORING, KIBANA_SETTINGS_TYPE];
16-
export function formatForNormalBulkEndpoint(payload, productionClusterUuid) {
17-
const dateSuffix = moment.utc().format('YYYY.MM.DD');
18-
return chunk(payload, 2).reduce((accum, chunk) => {
19-
const type = get(chunk[0], 'index._type');
20-
if (!type || !SUPPORTED_TYPES.includes(type)) {
21-
return accum;
22-
}
23-
24-
const { timestamp } = chunk[1];
25-
26-
accum.push({
27-
index: {
28-
_index: `.monitoring-kibana-${MONITORING_SYSTEM_API_VERSION}-${dateSuffix}`,
29-
},
30-
});
31-
accum.push({
32-
[type]: chunk[1],
33-
type,
34-
timestamp,
35-
cluster_uuid: productionClusterUuid,
36-
});
37-
return accum;
38-
}, []);
39-
}
6+
import { MONITORING_SYSTEM_API_VERSION, KIBANA_SYSTEM_ID } from '../../../common/constants';
407

418
/*
429
* Send the Kibana usage data to the ES Monitoring Bulk endpoint
4310
*/
44-
export async function sendBulkPayload(
45-
cluster,
46-
interval,
47-
payload,
48-
log,
49-
hasDirectConnectionToMonitoringCluster = false,
50-
productionClusterUuid = null
51-
) {
52-
if (hasDirectConnectionToMonitoringCluster) {
53-
if (productionClusterUuid === null) {
54-
log.warn(
55-
`Unable to determine production cluster uuid to use for shipping monitoring data. Kibana monitoring data will appear in a standalone cluster in the Stack Monitoring UI.`
56-
);
57-
}
58-
const formattedPayload = formatForNormalBulkEndpoint(payload, productionClusterUuid);
59-
return await cluster.callAsInternalUser('bulk', {
60-
body: formattedPayload,
61-
});
62-
}
63-
11+
export async function sendBulkPayload(cluster, interval, payload) {
6412
return cluster.callAsInternalUser('monitoring.bulk', {
6513
system_id: KIBANA_SYSTEM_ID,
6614
system_api_version: MONITORING_SYSTEM_API_VERSION,

0 commit comments

Comments
 (0)