Skip to content

Commit

Permalink
Fixing type check and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed May 14, 2020
1 parent 12a30bc commit 4bd0684
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useMetricsExplorerState = (
derivedIndexPattern: IIndexPattern
) => {
const [refreshSignal, setRefreshSignal] = useState(0);
const [afterKey, setAfterKey] = useState<string | null>(null);
const [afterKey, setAfterKey] = useState<string | null | Record<string, string | null>>(null);
const {
defaultViewState,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const renderUseMetricsExplorerDataHook = () => {
source,
derivedIndexPattern,
timeRange,
afterKey: null as string | null,
afterKey: null as string | null | Record<string, string | null>,
signal: 1,
},
wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useMetricsExplorerData(
source: SourceQuery.Query['source']['configuration'] | undefined,
derivedIndexPattern: IIndexPattern,
timerange: MetricsExplorerTimeOptions,
afterKey: string | null,
afterKey: string | null | Record<string, string | null>,
signal: any,
fetch?: HttpHandler
) {
Expand Down
59 changes: 49 additions & 10 deletions x-pack/test/api_integration/apis/infra/metrics_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ export default function({ getService }: FtrProviderContext) {
{
aggregation: 'avg',
field: 'system.cpu.user.pct',
rate: false,
},
{
aggregation: 'count',
rate: false,
},
],
};
Expand All @@ -52,7 +50,7 @@ export default function({ getService }: FtrProviderContext) {
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('id', 'Everything');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
Expand Down Expand Up @@ -81,7 +79,6 @@ export default function({ getService }: FtrProviderContext) {
{
aggregation: 'avg',
field: 'system.cpu.user.pct',
rate: false,
},
],
};
Expand All @@ -93,7 +90,7 @@ export default function({ getService }: FtrProviderContext) {
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('id', 'Everything');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
Expand Down Expand Up @@ -124,7 +121,7 @@ export default function({ getService }: FtrProviderContext) {
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(1);
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('id', 'Everything');
expect(firstSeries.columns).to.eql([]);
expect(firstSeries.rows).to.have.length(0);
});
Expand All @@ -144,7 +141,6 @@ export default function({ getService }: FtrProviderContext) {
metrics: [
{
aggregation: 'count',
rate: false,
},
],
};
Expand All @@ -169,10 +165,55 @@ export default function({ getService }: FtrProviderContext) {
timestamp: 1547571300000,
});
expect(body.pageInfo).to.eql({
afterKey: 'system.fsstat',
afterKey: { groupBy0: 'system.fsstat' },
total: 12,
});
});

it('should work with multiple groupBy', async () => {
const postBody = {
timerange: {
field: '@timestamp',
to: max,
from: min,
interval: '>=1m',
},
indexPattern: 'metricbeat-*',
groupBy: ['host.name', 'system.network.name'],
limit: 3,
afterKey: null,
metrics: [
{
aggregation: 'rate',
field: 'system.network.out.bytes',
},
],
};
const response = await supertest
.post('/api/infra/metrics_explorer')
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body = decodeOrThrow(metricsExplorerResponseRT)(response.body);
expect(body.series).length(3);
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'demo-stack-mysql-01 / eth0');
expect(firstSeries.columns).to.eql([
{ name: 'timestamp', type: 'date' },
{ name: 'metric_0', type: 'number' },
{ name: 'groupBy', type: 'string' },
]);
expect(firstSeries.rows).to.have.length(9);
expect(firstSeries.rows![1]).to.eql({
groupBy: 'demo-stack-mysql-01 / eth0',
metric_0: 53577.683333333334,
timestamp: 1547571300000,
});
expect(body.pageInfo).to.eql({
afterKey: { groupBy0: 'demo-stack-mysql-01', groupBy1: 'eth2' },
total: 4,
});
});
});

describe('without data', () => {
Expand All @@ -191,7 +232,6 @@ export default function({ getService }: FtrProviderContext) {
{
aggregation: 'avg',
field: 'system.cpu.user.pct',
rate: false,
},
],
};
Expand Down Expand Up @@ -225,7 +265,6 @@ export default function({ getService }: FtrProviderContext) {
{
aggregation: 'avg',
field: 'system.cpu.user.pct',
rate: false,
},
],
};
Expand Down

0 comments on commit 4bd0684

Please sign in to comment.