forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Stack Monitoring] Convert setup routes to TypeScript (elastic#131265)
- Loading branch information
1 parent
065ea3e
commit ecca231
Showing
43 changed files
with
753 additions
and
367 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
createLogViewsServiceSetupMock, | ||
createLogViewsServiceStartMock, | ||
} from './services/log_views/log_views_service.mock'; | ||
import { InfraPluginSetup, InfraPluginStart } from './types'; | ||
|
||
const createInfraSetupMock = () => { | ||
const infraSetupMock: jest.Mocked<InfraPluginSetup> = { | ||
defineInternalSourceConfiguration: jest.fn(), | ||
logViews: createLogViewsServiceSetupMock(), | ||
}; | ||
|
||
return infraSetupMock; | ||
}; | ||
|
||
const createInfraStartMock = () => { | ||
const infraStartMock: jest.Mocked<InfraPluginStart> = { | ||
getMetricIndices: jest.fn(), | ||
logViews: createLogViewsServiceStartMock(), | ||
}; | ||
return infraStartMock; | ||
}; | ||
|
||
export const infraPluginMock = { | ||
createSetupContract: createInfraSetupMock, | ||
createStartContract: createInfraStartMock, | ||
}; |
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
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/monitoring/common/http_api/cluster/post_cluster.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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { ccsRT, clusterUuidRT, timeRangeRT } from '../shared'; | ||
|
||
export const postClusterRequestParamsRT = rt.type({ | ||
clusterUuid: clusterUuidRT, | ||
}); | ||
|
||
export const postClusterRequestPayloadRT = rt.intersection([ | ||
rt.partial({ | ||
ccs: ccsRT, | ||
}), | ||
rt.type({ | ||
timeRange: timeRangeRT, | ||
codePaths: rt.array(rt.string), | ||
}), | ||
]); | ||
|
||
export type PostClusterRequestPayload = rt.TypeOf<typeof postClusterRequestPayloadRT>; | ||
|
||
export const postClusterResponsePayloadRT = rt.type({ | ||
// TODO: add payload entries | ||
}); |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/monitoring/common/http_api/cluster/post_clusters.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,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { timeRangeRT } from '../shared'; | ||
|
||
export const postClustersRequestPayloadRT = rt.type({ | ||
timeRange: timeRangeRT, | ||
codePaths: rt.array(rt.string), | ||
}); | ||
|
||
export type PostClustersRequestPayload = rt.TypeOf<typeof postClustersRequestPayloadRT>; | ||
|
||
export const postClustersResponsePayloadRT = rt.type({ | ||
// TODO: add payload entries | ||
}); |
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,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './post_cluster_setup_status'; | ||
export * from './post_node_setup_status'; | ||
export * from './post_disable_internal_collection'; |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/monitoring/common/http_api/setup/post_cluster_setup_status.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,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { | ||
booleanFromStringRT, | ||
ccsRT, | ||
clusterUuidRT, | ||
createLiteralValueFromUndefinedRT, | ||
timeRangeRT, | ||
} from '../shared'; | ||
|
||
export const postClusterSetupStatusRequestParamsRT = rt.partial({ | ||
clusterUuid: clusterUuidRT, | ||
}); | ||
|
||
export const postClusterSetupStatusRequestQueryRT = rt.partial({ | ||
// This flag is not intended to be used in production. It was introduced | ||
// as a way to ensure consistent API testing - the typical data source | ||
// for API tests are archived data, where the cluster configuration and data | ||
// are consistent from environment to environment. However, this endpoint | ||
// also attempts to retrieve data from the running stack products (ES and Kibana) | ||
// which will vary from environment to environment making it difficult | ||
// to write tests against. Therefore, this flag exists and should only be used | ||
// in our testing environment. | ||
skipLiveData: rt.union([booleanFromStringRT, createLiteralValueFromUndefinedRT(false)]), | ||
}); | ||
|
||
export const postClusterSetupStatusRequestPayloadRT = rt.partial({ | ||
ccs: ccsRT, | ||
timeRange: timeRangeRT, | ||
}); | ||
|
||
export type PostClusterSetupStatusRequestPayload = rt.TypeOf< | ||
typeof postClusterSetupStatusRequestPayloadRT | ||
>; | ||
|
||
export const postClusterSetupStatusResponsePayloadRT = rt.type({ | ||
// TODO: add payload entries | ||
}); |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/monitoring/common/http_api/setup/post_disable_internal_collection.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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { clusterUuidRT } from '../shared'; | ||
|
||
export const postDisableInternalCollectionRequestParamsRT = rt.partial({ | ||
// the cluster uuid seems to be required but never used | ||
clusterUuid: clusterUuidRT, | ||
}); |
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/monitoring/common/http_api/setup/post_node_setup_status.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,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { | ||
booleanFromStringRT, | ||
ccsRT, | ||
createLiteralValueFromUndefinedRT, | ||
timeRangeRT, | ||
} from '../shared'; | ||
|
||
export const postNodeSetupStatusRequestParamsRT = rt.type({ | ||
nodeUuid: rt.string, | ||
}); | ||
|
||
export const postNodeSetupStatusRequestQueryRT = rt.partial({ | ||
// This flag is not intended to be used in production. It was introduced | ||
// as a way to ensure consistent API testing - the typical data source | ||
// for API tests are archived data, where the cluster configuration and data | ||
// are consistent from environment to environment. However, this endpoint | ||
// also attempts to retrieve data from the running stack products (ES and Kibana) | ||
// which will vary from environment to environment making it difficult | ||
// to write tests against. Therefore, this flag exists and should only be used | ||
// in our testing environment. | ||
skipLiveData: rt.union([booleanFromStringRT, createLiteralValueFromUndefinedRT(false)]), | ||
}); | ||
|
||
export const postNodeSetupStatusRequestPayloadRT = rt.partial({ | ||
ccs: ccsRT, | ||
timeRange: timeRangeRT, | ||
}); | ||
|
||
export type PostNodeSetupStatusRequestPayload = rt.TypeOf< | ||
typeof postNodeSetupStatusRequestPayloadRT | ||
>; | ||
|
||
export const postNodeSetupStatusResponsePayloadRT = rt.type({ | ||
// TODO: add payload entries | ||
}); |
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/monitoring/common/http_api/shared/literal_value.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,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { either } from 'fp-ts'; | ||
import * as rt from 'io-ts'; | ||
import { createLiteralValueFromUndefinedRT } from './literal_value'; | ||
|
||
describe('LiteralValueFromUndefined runtime type', () => { | ||
it('decodes undefined to a given literal value', () => { | ||
expect(createLiteralValueFromUndefinedRT('SOME_VALUE').decode(undefined)).toEqual( | ||
either.right('SOME_VALUE') | ||
); | ||
}); | ||
|
||
it('can be used to define default values when decoding', () => { | ||
expect( | ||
rt.union([rt.boolean, createLiteralValueFromUndefinedRT(true)]).decode(undefined) | ||
).toEqual(either.right(true)); | ||
}); | ||
|
||
it('rejects other values', () => { | ||
expect( | ||
either.isLeft(createLiteralValueFromUndefinedRT('SOME_VALUE').decode('DEFINED')) | ||
).toBeTruthy(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/monitoring/common/http_api/shared/query_string_boolean.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,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { either } from 'fp-ts'; | ||
import { booleanFromStringRT } from './query_string_boolean'; | ||
|
||
describe('BooleanFromString runtime type', () => { | ||
it('decodes string "true" to a boolean', () => { | ||
expect(booleanFromStringRT.decode('true')).toEqual(either.right(true)); | ||
}); | ||
|
||
it('decodes string "false" to a boolean', () => { | ||
expect(booleanFromStringRT.decode('false')).toEqual(either.right(false)); | ||
}); | ||
|
||
it('rejects other strings', () => { | ||
expect(either.isLeft(booleanFromStringRT.decode('maybe'))).toBeTruthy(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.