-
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
[Logs UI] Reimplement log source configuration routes in plain HTTP+JSON #64021
Merged
weltenwort
merged 30 commits into
elastic:master
from
weltenwort:logs-ui-reimplement-source-routes-as-http
Apr 28, 2020
Merged
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4b54c1b
Add initial draft of http+json log source route
weltenwort 9dec483
Add api test for log source read route
weltenwort 2eccbe4
Extract common log source api types
weltenwort 0426212
Add support for PATCH method in framework adapter
weltenwort 12945ae
Add route to update source config
weltenwort 8633729
Add tests for source config PATCH route
weltenwort 5cceac0
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
weltenwort e9d4f89
Add log source status route
weltenwort 308eb59
Start moving Logs UI over to the new source API (WIP)
weltenwort bc6c2e2
Correctly concatenate index names in fields domain
weltenwort cbe5a55
Only query field caps when at least one index exists
weltenwort 7441b24
Provide more values from source hook to stay compatible
weltenwort a4d554a
Switch more pages to the new log source container
weltenwort a8d8a0e
Load data source on log rate and categories pages
weltenwort 1a7369e
Add update operation to log source hook
weltenwort 19a79c2
Move source configuration ui code to logs page dir
weltenwort 8b23fe3
Trigger log source loading on a higher page level
weltenwort 3cb1126
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
weltenwort bac844b
Make redirect tests more stable
weltenwort 90795b9
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
elasticmachine 1e9fe00
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
elasticmachine 2476c50
Improve generic argument names
weltenwort fee6041
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
weltenwort df3eadb
Use scopedHistory-compatible Prompt component
weltenwort 241a9ed
Fix custom prompt usage
weltenwort 18d303f
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
weltenwort fff15e1
Use the new source provider in the context provider
weltenwort e1f753c
Move "view in context" modal into the page content
weltenwort e7c0806
Merge branch 'master' into logs-ui-reimplement-source-routes-as-http
weltenwort 8cc81b5
Adapt to new source config getter signature
weltenwort 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
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/infra/common/http_api/log_sources/get_log_source_configuration.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,57 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
import { badRequestErrorRT, forbiddenErrorRT, routeTimingMetadataRT } from '../shared'; | ||
import { logSourceConfigurationRT } from './log_source_configuration'; | ||
|
||
/** | ||
* request | ||
*/ | ||
|
||
export const getLogSourceConfigurationRequestParamsRT = rt.type({ | ||
// the id of the source configuration | ||
sourceId: rt.string, | ||
}); | ||
|
||
export type GetLogSourceConfigurationRequestParams = rt.TypeOf< | ||
typeof getLogSourceConfigurationRequestParamsRT | ||
>; | ||
|
||
/** | ||
* response | ||
*/ | ||
|
||
export const getLogSourceConfigurationSuccessResponsePayloadRT = rt.intersection([ | ||
rt.type({ | ||
data: logSourceConfigurationRT, | ||
}), | ||
rt.partial({ | ||
timing: routeTimingMetadataRT, | ||
}), | ||
]); | ||
|
||
export type GetLogSourceConfigurationSuccessResponsePayload = rt.TypeOf< | ||
typeof getLogSourceConfigurationSuccessResponsePayloadRT | ||
>; | ||
|
||
export const getLogSourceConfigurationErrorResponsePayloadRT = rt.union([ | ||
badRequestErrorRT, | ||
forbiddenErrorRT, | ||
]); | ||
|
||
export type GetLogSourceConfigurationErrorReponsePayload = rt.TypeOf< | ||
typeof getLogSourceConfigurationErrorResponsePayloadRT | ||
>; | ||
|
||
export const getLogSourceConfigurationResponsePayloadRT = rt.union([ | ||
getLogSourceConfigurationSuccessResponsePayloadRT, | ||
getLogSourceConfigurationErrorResponsePayloadRT, | ||
]); | ||
|
||
export type GetLogSourceConfigurationReponsePayload = rt.TypeOf< | ||
typeof getLogSourceConfigurationResponsePayloadRT | ||
>; |
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/infra/common/http_api/log_sources/get_log_source_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,61 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
import { routeTimingMetadataRT } from '../shared'; | ||
import { | ||
getLogSourceConfigurationPath, | ||
LOG_SOURCE_CONFIGURATION_PATH, | ||
} from './log_source_configuration'; | ||
|
||
export const LOG_SOURCE_STATUS_PATH_SUFFIX = 'status'; | ||
export const LOG_SOURCE_STATUS_PATH = `${LOG_SOURCE_CONFIGURATION_PATH}/${LOG_SOURCE_STATUS_PATH_SUFFIX}`; | ||
export const getLogSourceStatusPath = (sourceId: string) => | ||
`${getLogSourceConfigurationPath(sourceId)}/${LOG_SOURCE_STATUS_PATH_SUFFIX}`; | ||
|
||
/** | ||
* request | ||
*/ | ||
|
||
export const getLogSourceStatusRequestParamsRT = rt.type({ | ||
// the id of the source configuration | ||
sourceId: rt.string, | ||
}); | ||
|
||
export type GetLogSourceStatusRequestParams = rt.TypeOf<typeof getLogSourceStatusRequestParamsRT>; | ||
|
||
/** | ||
* response | ||
*/ | ||
|
||
const logIndexFieldRT = rt.strict({ | ||
name: rt.string, | ||
type: rt.string, | ||
searchable: rt.boolean, | ||
aggregatable: rt.boolean, | ||
}); | ||
|
||
export type LogIndexField = rt.TypeOf<typeof logIndexFieldRT>; | ||
|
||
const logSourceStatusRT = rt.strict({ | ||
logIndexFields: rt.array(logIndexFieldRT), | ||
logIndexNames: rt.array(rt.string), | ||
}); | ||
|
||
export type LogSourceStatus = rt.TypeOf<typeof logSourceStatusRT>; | ||
|
||
export const getLogSourceStatusSuccessResponsePayloadRT = rt.intersection([ | ||
rt.type({ | ||
data: logSourceStatusRT, | ||
}), | ||
rt.partial({ | ||
timing: routeTimingMetadataRT, | ||
}), | ||
]); | ||
|
||
export type GetLogSourceStatusSuccessResponsePayload = rt.TypeOf< | ||
typeof getLogSourceStatusSuccessResponsePayloadRT | ||
>; |
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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './get_log_source_configuration'; | ||
export * from './get_log_source_status'; | ||
export * from './log_source_configuration'; | ||
export * from './patch_log_source_configuration'; |
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/infra/common/http_api/log_sources/log_source_configuration.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,78 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
|
||
export const LOG_SOURCE_CONFIGURATION_PATH_PREFIX = '/api/infra/log_source_configurations'; | ||
export const LOG_SOURCE_CONFIGURATION_PATH = `${LOG_SOURCE_CONFIGURATION_PATH_PREFIX}/{sourceId}`; | ||
export const getLogSourceConfigurationPath = (sourceId: string) => | ||
`${LOG_SOURCE_CONFIGURATION_PATH_PREFIX}/${sourceId}`; | ||
|
||
export const logSourceConfigurationOriginRT = rt.keyof({ | ||
fallback: null, | ||
internal: null, | ||
stored: null, | ||
}); | ||
|
||
export type LogSourceConfigurationOrigin = rt.TypeOf<typeof logSourceConfigurationOriginRT>; | ||
|
||
const logSourceFieldsConfigurationRT = rt.strict({ | ||
timestamp: rt.string, | ||
tiebreaker: rt.string, | ||
}); | ||
|
||
const logSourceCommonColumnConfigurationRT = rt.strict({ | ||
id: rt.string, | ||
}); | ||
|
||
const logSourceTimestampColumnConfigurationRT = rt.strict({ | ||
timestampColumn: logSourceCommonColumnConfigurationRT, | ||
}); | ||
|
||
const logSourceMessageColumnConfigurationRT = rt.strict({ | ||
messageColumn: logSourceCommonColumnConfigurationRT, | ||
}); | ||
|
||
const logSourceFieldColumnConfigurationRT = rt.strict({ | ||
fieldColumn: rt.intersection([ | ||
logSourceCommonColumnConfigurationRT, | ||
rt.strict({ | ||
field: rt.string, | ||
}), | ||
]), | ||
}); | ||
|
||
const logSourceColumnConfigurationRT = rt.union([ | ||
logSourceTimestampColumnConfigurationRT, | ||
logSourceMessageColumnConfigurationRT, | ||
logSourceFieldColumnConfigurationRT, | ||
]); | ||
|
||
export const logSourceConfigurationPropertiesRT = rt.strict({ | ||
name: rt.string, | ||
description: rt.string, | ||
logAlias: rt.string, | ||
fields: logSourceFieldsConfigurationRT, | ||
logColumns: rt.array(logSourceColumnConfigurationRT), | ||
}); | ||
|
||
export type LogSourceConfigurationProperties = rt.TypeOf<typeof logSourceConfigurationPropertiesRT>; | ||
|
||
export const logSourceConfigurationRT = rt.exact( | ||
rt.intersection([ | ||
rt.type({ | ||
id: rt.string, | ||
origin: logSourceConfigurationOriginRT, | ||
configuration: logSourceConfigurationPropertiesRT, | ||
}), | ||
rt.partial({ | ||
updatedAt: rt.number, | ||
version: rt.string, | ||
}), | ||
]) | ||
); | ||
|
||
export type LogSourceConfiguration = rt.TypeOf<typeof logSourceConfigurationRT>; |
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/infra/common/http_api/log_sources/patch_log_source_configuration.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,60 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
import { badRequestErrorRT, forbiddenErrorRT } from '../shared'; | ||
import { getLogSourceConfigurationSuccessResponsePayloadRT } from './get_log_source_configuration'; | ||
import { logSourceConfigurationPropertiesRT } from './log_source_configuration'; | ||
|
||
/** | ||
* request | ||
*/ | ||
|
||
export const patchLogSourceConfigurationRequestParamsRT = rt.type({ | ||
// the id of the source configuration | ||
sourceId: rt.string, | ||
}); | ||
|
||
export type PatchLogSourceConfigurationRequestParams = rt.TypeOf< | ||
typeof patchLogSourceConfigurationRequestParamsRT | ||
>; | ||
|
||
const logSourceConfigurationProperiesPatchRT = rt.partial({ | ||
...logSourceConfigurationPropertiesRT.type.props, | ||
fields: rt.partial(logSourceConfigurationPropertiesRT.type.props.fields.type.props), | ||
}); | ||
|
||
export type LogSourceConfigurationPropertiesPatch = rt.TypeOf< | ||
typeof logSourceConfigurationProperiesPatchRT | ||
>; | ||
|
||
export const patchLogSourceConfigurationRequestBodyRT = rt.type({ | ||
data: logSourceConfigurationProperiesPatchRT, | ||
}); | ||
|
||
export type PatchLogSourceConfigurationRequestBody = rt.TypeOf< | ||
typeof patchLogSourceConfigurationRequestBodyRT | ||
>; | ||
|
||
/** | ||
* response | ||
*/ | ||
|
||
export const patchLogSourceConfigurationSuccessResponsePayloadRT = getLogSourceConfigurationSuccessResponsePayloadRT; | ||
|
||
export type PatchLogSourceConfigurationSuccessResponsePayload = rt.TypeOf< | ||
typeof patchLogSourceConfigurationSuccessResponsePayloadRT | ||
>; | ||
|
||
export const patchLogSourceConfigurationResponsePayloadRT = rt.union([ | ||
patchLogSourceConfigurationSuccessResponsePayloadRT, | ||
badRequestErrorRT, | ||
forbiddenErrorRT, | ||
]); | ||
|
||
export type PatchLogSourceConfigurationReponsePayload = rt.TypeOf< | ||
typeof patchLogSourceConfigurationResponsePayloadRT | ||
>; |
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
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/infra/public/containers/logs/log_source/api/fetch_log_source_configuration.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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
getLogSourceConfigurationPath, | ||
getLogSourceConfigurationSuccessResponsePayloadRT, | ||
} from '../../../../../common/http_api/log_sources'; | ||
import { decodeOrThrow } from '../../../../../common/runtime_types'; | ||
import { npStart } from '../../../../legacy_singletons'; | ||
|
||
export const callFetchLogSourceConfigurationAPI = async (sourceId: string) => { | ||
const response = await npStart.http.fetch(getLogSourceConfigurationPath(sourceId), { | ||
method: 'GET', | ||
}); | ||
|
||
return decodeOrThrow(getLogSourceConfigurationSuccessResponsePayloadRT)(response); | ||
}; |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/infra/public/containers/logs/log_source/api/fetch_log_source_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,20 @@ | ||
/* | ||
* 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 { | ||
getLogSourceStatusPath, | ||
getLogSourceStatusSuccessResponsePayloadRT, | ||
} from '../../../../../common/http_api/log_sources'; | ||
import { decodeOrThrow } from '../../../../../common/runtime_types'; | ||
import { npStart } from '../../../../legacy_singletons'; | ||
|
||
export const callFetchLogSourceStatusAPI = async (sourceId: string) => { | ||
const response = await npStart.http.fetch(getLogSourceStatusPath(sourceId), { | ||
method: 'GET', | ||
}); | ||
|
||
return decodeOrThrow(getLogSourceStatusSuccessResponsePayloadRT)(response); | ||
}; |
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/infra/public/containers/logs/log_source/api/patch_log_source_configuration.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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
getLogSourceConfigurationPath, | ||
patchLogSourceConfigurationSuccessResponsePayloadRT, | ||
patchLogSourceConfigurationRequestBodyRT, | ||
LogSourceConfigurationPropertiesPatch, | ||
} from '../../../../../common/http_api/log_sources'; | ||
import { decodeOrThrow } from '../../../../../common/runtime_types'; | ||
import { npStart } from '../../../../legacy_singletons'; | ||
|
||
export const callPatchLogSourceConfigurationAPI = async ( | ||
sourceId: string, | ||
patchedProperties: LogSourceConfigurationPropertiesPatch | ||
) => { | ||
const response = await npStart.http.fetch(getLogSourceConfigurationPath(sourceId), { | ||
method: 'PATCH', | ||
body: JSON.stringify( | ||
patchLogSourceConfigurationRequestBodyRT.encode({ | ||
data: patchedProperties, | ||
}) | ||
), | ||
}); | ||
|
||
return decodeOrThrow(patchLogSourceConfigurationSuccessResponsePayloadRT)(response); | ||
}; |
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.
Small nit: I personally find generics easier / quicker to parse with meaningful type variables, could we change these from
A, O, I
?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.
Good point, I absolutely agree. I stuck with the io-ts naming scheme during experimentation and forgot to clean it up afterwards.