mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
* [Infra UI] Test for metrics GraphQL endpoint * Moving apollo-boost to devDeps * Converting tests to typescript * Renaming infraops to infra
This commit is contained in:
parent
1feba0f951
commit
d6ebb86c62
9 changed files with 10896 additions and 0 deletions
|
@ -12,6 +12,7 @@ export default function ({ loadTestFile }) {
|
|||
loadTestFile(require.resolve('./xpack_main'));
|
||||
loadTestFile(require.resolve('./logstash'));
|
||||
loadTestFile(require.resolve('./kibana'));
|
||||
loadTestFile(require.resolve('./infra'));
|
||||
loadTestFile(require.resolve('./beats'));
|
||||
});
|
||||
}
|
||||
|
|
12
x-pack/test/api_integration/apis/infra/index.js
Normal file
12
x-pack/test/api_integration/apis/infra/index.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
|
||||
export default function ({ loadTestFile }) {
|
||||
describe('InfraOps GraphQL Endpoints', () => {
|
||||
loadTestFile(require.resolve('./metrics'));
|
||||
});
|
||||
}
|
77
x-pack/test/api_integration/apis/infra/metrics.ts
Normal file
77
x-pack/test/api_integration/apis/infra/metrics.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from 'expect.js';
|
||||
import { first, last } from 'lodash';
|
||||
import { MetricsQuery } from '../../../../plugins/infra/common/graphql/types';
|
||||
import { metricsQuery } from '../../../../plugins/infra/public/containers/metrics/metrics.gql_query';
|
||||
import { KbnTestProvider } from './types';
|
||||
|
||||
const metricTests: KbnTestProvider = ({ getService }) => {
|
||||
const esArchiver = getService('esArchiver');
|
||||
const client = getService('infraOpsGraphQLClient');
|
||||
|
||||
describe('metrics', () => {
|
||||
before(() => esArchiver.load('infra'));
|
||||
after(() => esArchiver.unload('infra'));
|
||||
|
||||
it('should basically work', () => {
|
||||
return client
|
||||
.query<MetricsQuery.Query>({
|
||||
query: metricsQuery,
|
||||
variables: {
|
||||
sourceId: 'default',
|
||||
metrics: ['hostCpuUsage'],
|
||||
timerange: {
|
||||
to: 1539806283952,
|
||||
from: 1539805341208,
|
||||
interval: '>=1m',
|
||||
},
|
||||
nodeId: 'demo-stack-nginx-01',
|
||||
nodeType: 'host',
|
||||
},
|
||||
})
|
||||
.then(resp => {
|
||||
const { metrics } = resp.data.source;
|
||||
expect(metrics.length).to.equal(1);
|
||||
const metric = first(metrics);
|
||||
expect(metric).to.have.property('id', 'hostCpuUsage');
|
||||
expect(metric).to.have.property('series');
|
||||
const series = first(metric.series);
|
||||
expect(series).to.have.property('id', 'user');
|
||||
expect(series).to.have.property('data');
|
||||
const datapoint = last(series.data);
|
||||
expect(datapoint).to.have.property('timestamp', 1539806220000);
|
||||
expect(datapoint).to.have.property('value', 0.0065);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support multiple metrics', () => {
|
||||
return client
|
||||
.query<MetricsQuery.Query>({
|
||||
query: metricsQuery,
|
||||
variables: {
|
||||
sourceId: 'default',
|
||||
metrics: ['hostCpuUsage', 'hostLoad'],
|
||||
timerange: {
|
||||
to: 1539806283952,
|
||||
from: 1539805341208,
|
||||
interval: '>=1m',
|
||||
},
|
||||
nodeId: 'demo-stack-nginx-01',
|
||||
nodeType: 'host',
|
||||
},
|
||||
})
|
||||
.then(resp => {
|
||||
const { metrics } = resp.data.source;
|
||||
expect(metrics.length).to.equal(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// tslint:disable-next-line no-default-export
|
||||
export default metricTests;
|
21
x-pack/test/api_integration/apis/infra/types.ts
Normal file
21
x-pack/test/api_integration/apis/infra/types.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { InMemoryCache } from 'apollo-cache-inmemory';
|
||||
import { ApolloClient } from 'apollo-client';
|
||||
|
||||
export interface EsArchiver {
|
||||
load(name: string): void;
|
||||
unload(name: string): void;
|
||||
}
|
||||
|
||||
export interface KbnTestProviderOptions {
|
||||
getService(name: string): any;
|
||||
getService(name: 'esArchiver'): EsArchiver;
|
||||
getService(name: 'infraOpsGraphQLClient'): ApolloClient<InMemoryCache>;
|
||||
}
|
||||
|
||||
export type KbnTestProvider = (options: KbnTestProviderOptions) => void;
|
|
@ -9,6 +9,7 @@ import {
|
|||
EsSupertestWithoutAuthProvider,
|
||||
SupertestWithoutAuthProvider,
|
||||
UsageAPIProvider,
|
||||
InfraOpsGraphQLProvider
|
||||
} from './services';
|
||||
|
||||
export default async function ({ readConfigFile }) {
|
||||
|
@ -26,6 +27,7 @@ export default async function ({ readConfigFile }) {
|
|||
esSupertest: kibanaAPITestsConfig.get('services.esSupertest'),
|
||||
supertestWithoutAuth: SupertestWithoutAuthProvider,
|
||||
esSupertestWithoutAuth: EsSupertestWithoutAuthProvider,
|
||||
infraOpsGraphQLClient: InfraOpsGraphQLProvider,
|
||||
es: EsProvider,
|
||||
esArchiver: kibanaCommonConfig.get('services.esArchiver'),
|
||||
usageAPI: UsageAPIProvider,
|
||||
|
|
|
@ -8,3 +8,4 @@ export { EsProvider } from './es';
|
|||
export { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth';
|
||||
export { SupertestWithoutAuthProvider } from './supertest_without_auth';
|
||||
export { UsageAPIProvider } from './usage_api';
|
||||
export { InfraOpsGraphQLProvider } from './infraops_graphql_client';
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { format as formatUrl } from 'url';
|
||||
import fetch from 'node-fetch';
|
||||
import { InMemoryCache } from 'apollo-cache-inmemory';
|
||||
import { ApolloClient } from 'apollo-client';
|
||||
import { HttpLink } from 'apollo-link-http';
|
||||
|
||||
export function InfraOpsGraphQLProvider({ getService }) {
|
||||
const config = getService('config');
|
||||
const kbnURL = formatUrl(config.get('servers.kibana'));
|
||||
|
||||
return new ApolloClient({
|
||||
cache: new InMemoryCache(),
|
||||
link: new HttpLink({
|
||||
credentials: 'same-origin',
|
||||
fetch,
|
||||
headers: {
|
||||
'kbn-xsrf': 'xxx',
|
||||
},
|
||||
uri: `${kbnURL}/api/infra/graphql`,
|
||||
}),
|
||||
});
|
||||
|
||||
}
|
||||
|
BIN
x-pack/test/functional/es_archives/infra/data.json.gz
Normal file
BIN
x-pack/test/functional/es_archives/infra/data.json.gz
Normal file
Binary file not shown.
10752
x-pack/test/functional/es_archives/infra/mappings.json
Normal file
10752
x-pack/test/functional/es_archives/infra/mappings.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue