-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix inputs extractors list not updating after deletion #17289
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
643e01d
use store to get extractors list
ousmaneo b80d396
add changelog
ousmaneo b300cdb
Merge branch 'master' into issue-16858
grotlue 039b548
remove getInitialState to use default from store
ousmaneo c9dbdee
Merge branch 'master' into issue-16858
ousmaneo 6f4f74a
move components to typescrypt
ousmaneo 6b41292
Merge branch 'master' into issue-16858
grotlue c3e0cbf
Merge branch 'master' into issue-16858
ousmaneo b11c881
fix review
ousmaneo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "fixed" | ||
message = "Fix inputs extractors list not updating after deletion" | ||
|
||
issues = ["16858"] | ||
pulls = ["17289"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,21 +23,123 @@ import * as URLUtils from 'util/URLUtils'; | |
import UserNotification from 'util/UserNotification'; | ||
import { singletonStore, singletonActions } from 'logic/singleton'; | ||
|
||
export type InputSummary = { | ||
creator_user_id: string; | ||
node: string; | ||
name: string; | ||
created_at: string; | ||
global: boolean; | ||
attributes: { | ||
[_key: string]: Object; | ||
}; | ||
id: string; | ||
title: string; | ||
type: string; | ||
content_pack: string; | ||
static_fields: { | ||
[_key: string]: string; | ||
}; | ||
}; | ||
|
||
export type NodeSummary = { | ||
cluster_id: string, | ||
hostname: string, | ||
is_leader: boolean, | ||
is_master: boolean, | ||
last_seen: string, | ||
node_id: string, | ||
short_node_id: string, | ||
transport_address: string, | ||
type: string, | ||
}; | ||
|
||
type RateMetricsResponse = { | ||
total: number, | ||
mean: number, | ||
five_minute: number, | ||
fifteen_minute: number, | ||
one_minute: number, | ||
}; | ||
|
||
type TimerMetricsResponse = { | ||
min: number, | ||
max: number, | ||
std_dev: number, | ||
mean: number, | ||
'95th_percentile': number, | ||
'99th_percentile': number, | ||
'98th_percentile': number, | ||
} | ||
type TimerRateMetricsResponse = { | ||
rate: RateMetricsResponse, | ||
rate_unit: string, | ||
time: TimerMetricsResponse, | ||
duration_unit: string, | ||
}; | ||
|
||
export type ExtractorMetrics = { | ||
condition_misses: number, | ||
execution: TimerRateMetricsResponse, | ||
total: TimerRateMetricsResponse, | ||
condition: TimerRateMetricsResponse, | ||
condition_hits: number, | ||
converters: TimerRateMetricsResponse, | ||
}; | ||
|
||
export type ExtractorType = { | ||
creator_user_id: string, | ||
extractor_type?: string, | ||
source_field: string, | ||
condition_type: string, | ||
converter_exceptions: number, | ||
title: string, | ||
type: string, | ||
cursor_strategy: string, | ||
exceptions: number, | ||
target_field: string, | ||
extractor_config: { | ||
[_key: string]: Object, | ||
}, | ||
condition_value: string, | ||
converters: { | ||
[_key: string]: Object, | ||
}[], | ||
id?: string, | ||
metrics: ExtractorMetrics, | ||
order: number, | ||
}; | ||
|
||
type ExtractorsActionsType = { | ||
list: (inputId: string) => Promise<Array<ExtractorType>>, | ||
get: (inputId: string, extractorId: string) => Promise<ExtractorType>, | ||
create: (inputId: string, extractor: ExtractorType, calledFromMethod: boolean) => Promise<unknown>, | ||
save: (inputId: string, extractor: ExtractorType) => Promise<unknown>, | ||
update: (inputId: string, extractor: ExtractorType, calledFromMethod: boolean) => Promise<unknown>, | ||
delete: (inputId: string, extractor: ExtractorType) => Promise<unknown>, | ||
order: { asyncResult: true }, | ||
import: (inputId: string, orderedExtractors: Array<ExtractorType>) => Promise<unknown>, | ||
}; | ||
|
||
export type ExtractorsStoreState = { | ||
extractors: Array<ExtractorType>, | ||
extractor: ExtractorType, | ||
}; | ||
|
||
export const ExtractorsActions = singletonActions( | ||
'core.Extractors', | ||
() => Reflux.createActions({ | ||
() => Reflux.createActions<ExtractorsActionsType>({ | ||
list: { asyncResult: true }, | ||
get: { asyncResult: true }, | ||
create: { asyncResult: true }, | ||
save: { asyncResult: true }, | ||
update: { asyncResult: true }, | ||
delete: { asyncResult: true }, | ||
order: { asyncResult: true }, | ||
import: {}, | ||
import: { asyncResult: true }, | ||
}), | ||
); | ||
|
||
function getExtractorDTO(extractor) { | ||
function getExtractorDTO(extractor: ExtractorType) { | ||
const conditionValue = extractor.condition_type && extractor.condition_type !== 'none' ? extractor.condition_value : ''; | ||
|
||
return { | ||
|
@@ -56,29 +158,44 @@ function getExtractorDTO(extractor) { | |
|
||
export const ExtractorsStore = singletonStore( | ||
'core.Extractors', | ||
() => Reflux.createStore({ | ||
() => Reflux.createStore<ExtractorsStoreState>({ | ||
listenables: [ExtractorsActions], | ||
sourceUrl: '/system/inputs/', | ||
extractors: undefined, | ||
extractor: undefined, | ||
|
||
getInitialState() { | ||
return this.getState(); | ||
}, | ||
|
||
init() { | ||
this.trigger({ extractors: this.extractors, extractor: this.extractor }); | ||
this.trigger({ extractors: this.extractors, extractor: this.extractory }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
|
||
list(inputId) { | ||
getState() { | ||
return { | ||
extractors: this.extractors, | ||
extractor: this.extractor, | ||
}; | ||
}, | ||
|
||
propagateState() { | ||
this.trigger(this.getState()); | ||
}, | ||
|
||
list(inputId: string) { | ||
const promise = fetch('GET', URLUtils.qualifyUrl(URLUtils.concatURLPath(this.sourceUrl, inputId, 'extractors'))); | ||
|
||
promise.then((response) => { | ||
this.extractors = response.extractors; | ||
this.trigger({ extractors: this.extractors }); | ||
this.propagateState(); | ||
}); | ||
|
||
ExtractorsActions.list.promise(promise); | ||
}, | ||
|
||
// Creates an basic extractor object that we can use to create new extractors. | ||
new(type, field) { | ||
new(type: string, field: string) { | ||
if (ExtractorUtils.EXTRACTOR_TYPES.indexOf(type) === -1) { | ||
throw new Error(`Invalid extractor type provided: ${type}`); | ||
} | ||
|
@@ -92,18 +209,18 @@ export const ExtractorsStore = singletonStore( | |
}; | ||
}, | ||
|
||
get(inputId, extractorId) { | ||
get(inputId: string, extractorId: string) { | ||
const promise = fetch('GET', URLUtils.qualifyUrl(URLUtils.concatURLPath(this.sourceUrl, inputId, 'extractors', extractorId))); | ||
|
||
promise.then((response) => { | ||
this.extractor = response; | ||
this.trigger({ extractor: this.extractor }); | ||
this.propagateState(); | ||
}); | ||
|
||
ExtractorsActions.get.promise(promise); | ||
}, | ||
|
||
save(inputId, extractor) { | ||
save(inputId: string, extractor: ExtractorType) { | ||
let promise; | ||
|
||
if (extractor.id) { | ||
|
@@ -115,13 +232,13 @@ export const ExtractorsStore = singletonStore( | |
ExtractorsActions.save.promise(promise); | ||
}, | ||
|
||
_silentExtractorCreate(inputId, extractor) { | ||
_silentExtractorCreate(inputId: string, extractor: ExtractorType) { | ||
const url = URLUtils.qualifyUrl(ApiRoutes.ExtractorsController.create(inputId).url); | ||
|
||
return fetch('POST', url, getExtractorDTO(extractor)); | ||
}, | ||
|
||
create(inputId, extractor, calledFromMethod) { | ||
create(inputId: string, extractor: ExtractorType, calledFromMethod: boolean) { | ||
const promise = this._silentExtractorCreate(inputId, extractor); | ||
|
||
promise | ||
|
@@ -144,7 +261,7 @@ export const ExtractorsStore = singletonStore( | |
return promise; | ||
}, | ||
|
||
update(inputId, extractor, calledFromMethod) { | ||
update(inputId: string, extractor: ExtractorType, calledFromMethod: boolean) { | ||
const url = URLUtils.qualifyUrl(ApiRoutes.ExtractorsController.update(inputId, extractor.id).url); | ||
|
||
const promise = fetch('PUT', url, getExtractorDTO(extractor)); | ||
|
@@ -169,7 +286,7 @@ export const ExtractorsStore = singletonStore( | |
return promise; | ||
}, | ||
|
||
delete(inputId, extractor) { | ||
delete(inputId: string, extractor: ExtractorType) { | ||
const url = URLUtils.qualifyUrl(ApiRoutes.ExtractorsController.delete(inputId, extractor.id).url); | ||
|
||
const promise = fetch('DELETE', url); | ||
|
@@ -190,7 +307,7 @@ export const ExtractorsStore = singletonStore( | |
ExtractorsActions.delete.promise(promise); | ||
}, | ||
|
||
order(inputId, orderedExtractors) { | ||
order(inputId: string, orderedExtractors: Array<ExtractorType>) { | ||
const url = URLUtils.qualifyUrl(ApiRoutes.ExtractorsController.order(inputId).url); | ||
const orderedExtractorsMap = {}; | ||
|
||
|
@@ -216,7 +333,7 @@ export const ExtractorsStore = singletonStore( | |
ExtractorsActions.order.promise(promise); | ||
}, | ||
|
||
import(inputId, extractors) { | ||
import(inputId: string, extractors: Array<ExtractorType>) { | ||
let successfulImports = 0; | ||
let failedImports = 0; | ||
const promises = []; | ||
|
@@ -235,6 +352,8 @@ export const ExtractorsStore = singletonStore( | |
if (failedImports === 0) { | ||
UserNotification.success(`Import results: ${successfulImports} extractor(s) imported.`, | ||
'Import operation successful'); | ||
|
||
this.propagateState(); | ||
} else { | ||
UserNotification.warning(`Import results: ${successfulImports} extractor(s) imported, ${failedImports} error(s).`, | ||
'Import operation completed'); | ||
|
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.