-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Infra UI] Test for metrics GraphQL endpoint #24179
Merged
simianhacker
merged 6 commits into
elastic:master
from
simianhacker:tests-metric-endpoint
Oct 19, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad3c891
[Infra UI] Test for metrics GraphQL endpoint
simianhacker ce5e95e
Moving apollo-boost to devDeps
simianhacker 5aa709f
Merge branch 'master' of github.com:elastic/kibana into tests-metric-…
simianhacker 47ea822
Merge branch 'master' of github.com:elastic/kibana into tests-metric-…
simianhacker ab73a43
Converting tests to typescript
simianhacker bc0e393
Renaming infraops to infra
simianhacker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
x-pack/test/api_integration/services/infraops_graphql_client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`, | ||
}), | ||
}); | ||
|
||
} | ||
|
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and configure the
ApolloClient
like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done