|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import expect from '@kbn/expect'; |
| 21 | +import _ from 'lodash'; |
| 22 | + |
| 23 | +/* |
| 24 | + * Create a single-level array with strings for all the paths to values in the |
| 25 | + * source object, up to 3 deep. Going deeper than 3 causes a bit too much churn |
| 26 | + * in the tests. |
| 27 | + */ |
| 28 | +function flatKeys(source) { |
| 29 | + const recursivelyFlatKeys = (obj, path = [], depth = 0) => { |
| 30 | + return depth < 3 && _.isObject(obj) |
| 31 | + ? _.map(obj, (v, k) => recursivelyFlatKeys(v, [...path, k], depth + 1)) |
| 32 | + : path.join('.'); |
| 33 | + }; |
| 34 | + |
| 35 | + return _.uniq(_.flattenDeep(recursivelyFlatKeys(source))).sort((a, b) => a.localeCompare(b)); |
| 36 | +} |
| 37 | + |
| 38 | +export default function({ getService }) { |
| 39 | + const supertest = getService('supertest'); |
| 40 | + |
| 41 | + describe('/api/telemetry/v2/clusters/_stats', () => { |
| 42 | + it('should pull local stats and validate data types', async () => { |
| 43 | + const timeRange = { |
| 44 | + min: '2018-07-23T22:07:00Z', |
| 45 | + max: '2018-07-23T22:13:00Z', |
| 46 | + }; |
| 47 | + |
| 48 | + const { body } = await supertest |
| 49 | + .post('/api/telemetry/v2/clusters/_stats') |
| 50 | + .set('kbn-xsrf', 'xxx') |
| 51 | + .send({ timeRange, unencrypted: true }) |
| 52 | + .expect(200); |
| 53 | + |
| 54 | + expect(body.length).to.be(1); |
| 55 | + const stats = body[0]; |
| 56 | + expect(stats.collection).to.be('local'); |
| 57 | + expect(stats.stack_stats.kibana.count).to.be.a('number'); |
| 58 | + expect(stats.stack_stats.kibana.indices).to.be.a('number'); |
| 59 | + expect(stats.stack_stats.kibana.os.platforms[0].platform).to.be.a('string'); |
| 60 | + expect(stats.stack_stats.kibana.os.platforms[0].count).to.be(1); |
| 61 | + expect(stats.stack_stats.kibana.os.platformReleases[0].platformRelease).to.be.a('string'); |
| 62 | + expect(stats.stack_stats.kibana.os.platformReleases[0].count).to.be(1); |
| 63 | + expect(stats.stack_stats.kibana.plugins.telemetry.opt_in_status).to.be(false); |
| 64 | + expect(stats.stack_stats.kibana.plugins.telemetry.usage_fetcher).to.be.a('string'); |
| 65 | + expect(stats.stack_stats.kibana.plugins.stack_management).to.be.an('object'); |
| 66 | + expect(stats.stack_stats.kibana.plugins.ui_metric).to.be.an('object'); |
| 67 | + expect(stats.stack_stats.kibana.plugins.application_usage).to.be.an('object'); |
| 68 | + expect(stats.stack_stats.kibana.plugins.kql.defaultQueryLanguage).to.be.a('string'); |
| 69 | + expect(stats.stack_stats.kibana.plugins['tsvb-validation']).to.be.an('object'); |
| 70 | + expect(stats.stack_stats.kibana.plugins.localization).to.be.an('object'); |
| 71 | + expect(stats.stack_stats.kibana.plugins.csp.strict).to.be(true); |
| 72 | + expect(stats.stack_stats.kibana.plugins.csp.warnLegacyBrowsers).to.be(true); |
| 73 | + expect(stats.stack_stats.kibana.plugins.csp.rulesChangedFromDefault).to.be(false); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should pull local stats and validate fields', async () => { |
| 77 | + const timeRange = { |
| 78 | + min: '2018-07-23T22:07:00Z', |
| 79 | + max: '2018-07-23T22:13:00Z', |
| 80 | + }; |
| 81 | + |
| 82 | + const { body } = await supertest |
| 83 | + .post('/api/telemetry/v2/clusters/_stats') |
| 84 | + .set('kbn-xsrf', 'xxx') |
| 85 | + .send({ timeRange, unencrypted: true }) |
| 86 | + .expect(200); |
| 87 | + |
| 88 | + const stats = body[0]; |
| 89 | + |
| 90 | + const actual = flatKeys(stats); |
| 91 | + expect(actual).to.be.an('array'); |
| 92 | + const expected = [ |
| 93 | + 'cluster_name', |
| 94 | + 'cluster_stats.cluster_uuid', |
| 95 | + 'cluster_stats.indices.analysis', |
| 96 | + 'cluster_stats.indices.completion', |
| 97 | + 'cluster_stats.indices.count', |
| 98 | + 'cluster_stats.indices.docs', |
| 99 | + 'cluster_stats.indices.fielddata', |
| 100 | + 'cluster_stats.indices.mappings', |
| 101 | + 'cluster_stats.indices.query_cache', |
| 102 | + 'cluster_stats.indices.segments', |
| 103 | + 'cluster_stats.indices.shards', |
| 104 | + 'cluster_stats.indices.store', |
| 105 | + 'cluster_stats.nodes.count', |
| 106 | + 'cluster_stats.nodes.discovery_types', |
| 107 | + 'cluster_stats.nodes.fs', |
| 108 | + 'cluster_stats.nodes.ingest', |
| 109 | + 'cluster_stats.nodes.jvm', |
| 110 | + 'cluster_stats.nodes.network_types', |
| 111 | + 'cluster_stats.nodes.os', |
| 112 | + 'cluster_stats.nodes.packaging_types', |
| 113 | + 'cluster_stats.nodes.plugins', |
| 114 | + 'cluster_stats.nodes.process', |
| 115 | + 'cluster_stats.nodes.versions', |
| 116 | + 'cluster_stats.status', |
| 117 | + 'cluster_stats.timestamp', |
| 118 | + 'cluster_uuid', |
| 119 | + 'collection', |
| 120 | + 'collectionSource', |
| 121 | + 'stack_stats.kibana.count', |
| 122 | + 'stack_stats.kibana.indices', |
| 123 | + 'stack_stats.kibana.os', |
| 124 | + 'stack_stats.kibana.plugins', |
| 125 | + 'stack_stats.kibana.versions', |
| 126 | + 'timestamp', |
| 127 | + 'version', |
| 128 | + ]; |
| 129 | + |
| 130 | + expect(expected.every(m => actual.includes(m))).to.be.ok(); |
| 131 | + }); |
| 132 | + }); |
| 133 | +} |
0 commit comments