-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…70647) * [Metrics UI] Register function for Observability homepage * Updating types; removing relative path from appLink Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
df4e455
commit e1f017e
Showing
6 changed files
with
783 additions
and
1 deletion.
There are no files selected for viewing
215 changes: 215 additions & 0 deletions
215
x-pack/plugins/infra/public/__snapshots__/metrics_overview_fetchers.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/infra/public/metrics_overview_fetchers.test.ts
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,91 @@ | ||
/* | ||
* 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 { coreMock } from 'src/core/public/mocks'; | ||
import { createMetricsHasData, createMetricsFetchData } from './metrics_overview_fetchers'; | ||
import { CoreStart } from 'kibana/public'; | ||
import { InfraClientStartDeps, InfraClientStartExports } from './types'; | ||
import moment from 'moment'; | ||
import { FAKE_SNAPSHOT_RESPONSE } from './test_utils'; | ||
|
||
function setup() { | ||
const core = coreMock.createStart(); | ||
const mockedGetStartServices = jest.fn(() => { | ||
const deps = {}; | ||
return Promise.resolve([ | ||
core as CoreStart, | ||
deps as InfraClientStartDeps, | ||
void 0 as InfraClientStartExports, | ||
]) as Promise<[CoreStart, InfraClientStartDeps, InfraClientStartExports]>; | ||
}); | ||
return { core, mockedGetStartServices }; | ||
} | ||
|
||
describe('Metrics UI Observability Homepage Functions', () => { | ||
describe('createMetricsHasData()', () => { | ||
it('should return true when true', async () => { | ||
const { core, mockedGetStartServices } = setup(); | ||
core.http.get.mockResolvedValue({ | ||
status: { | ||
indexFields: [], | ||
logIndicesExist: false, | ||
metricIndicesExist: true, | ||
}, | ||
}); | ||
const hasData = createMetricsHasData(mockedGetStartServices); | ||
const response = await hasData(); | ||
expect(core.http.get).toHaveBeenCalledTimes(1); | ||
expect(response).toBeTruthy(); | ||
}); | ||
it('should return false when false', async () => { | ||
const { core, mockedGetStartServices } = setup(); | ||
core.http.get.mockResolvedValue({ | ||
status: { | ||
indexFields: [], | ||
logIndicesExist: false, | ||
metricIndicesExist: false, | ||
}, | ||
}); | ||
const hasData = createMetricsHasData(mockedGetStartServices); | ||
const response = await hasData(); | ||
expect(core.http.get).toHaveBeenCalledTimes(1); | ||
expect(response).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('createMetricsFetchData()', () => { | ||
it('should just work', async () => { | ||
const { core, mockedGetStartServices } = setup(); | ||
core.http.post.mockResolvedValue(FAKE_SNAPSHOT_RESPONSE); | ||
const fetchData = createMetricsFetchData(mockedGetStartServices); | ||
const endTime = moment(); | ||
const startTime = endTime.clone().subtract(1, 'h'); | ||
const bucketSize = '300s'; | ||
const response = await fetchData({ | ||
startTime: startTime.toISOString(), | ||
endTime: endTime.toISOString(), | ||
bucketSize, | ||
}); | ||
expect(core.http.post).toHaveBeenCalledTimes(1); | ||
expect(core.http.post).toHaveBeenCalledWith('/api/metrics/snapshot', { | ||
body: JSON.stringify({ | ||
sourceId: 'default', | ||
metrics: [{ type: 'cpu' }, { type: 'memory' }, { type: 'rx' }, { type: 'tx' }], | ||
groupBy: [], | ||
nodeType: 'host', | ||
timerange: { | ||
from: startTime.valueOf(), | ||
to: endTime.valueOf(), | ||
interval: '300s', | ||
forceInterval: true, | ||
ignoreLookback: true, | ||
}, | ||
}), | ||
}); | ||
expect(response).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.