-
Notifications
You must be signed in to change notification settings - Fork 4
feat(alarms): Support filtering alarms by source #432
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
Draft
Ahalya-ni
wants to merge
13
commits into
users/ahalya/refactor/ahalya/move-reusable-to-utils
Choose a base branch
from
users/ahalya/feat/alarms/source-filter-final-2.0
base: users/ahalya/refactor/ahalya/move-reusable-to-utils
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−19
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a6f987d
added source
Ahalya-ni 568315a
resolve conflicts
Ahalya-ni 9d7e3b9
remove unwanted changes
Ahalya-ni 6de0b58
add code comment
Ahalya-ni 9f8a4bb
resolve nit comments
Ahalya-ni 9f55d10
add source query builder test
Ahalya-ni 198d172
update the logic to use multiplevaluesquery
Ahalya-ni 102b195
update test
Ahalya-ni 3de45fb
address comments
Ahalya-ni 41b2ab3
create new const file for source properties
Ahalya-ni c1d3f96
update constants
Ahalya-ni 0d2c1d3
export the required method from the utils
Ahalya-ni 6630743
resolve conflicts
Ahalya-ni 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,8 +7,9 @@ import { ExpressionTransformFunction, transformComputedFieldsQuery } from "core/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { ALARMS_TIME_FIELDS, AlarmsQueryBuilderFields } from "./constants/AlarmsQueryBuilder.constants"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { QueryBuilderOption, Workspace } from "core/types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { WorkspaceUtils } from "shared/workspace.utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { getVariableOptions, multipleValuesQuery, timeFieldsQuery } from "core/utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { getFilterConcatOperator, getVariableOptions, multipleValuesQuery, timeFieldsQuery } from "core/utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { BackendSrv, getBackendSrv, getTemplateSrv, TemplateSrv } from "@grafana/runtime"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { MINION_ID_CUSTOM_PROPERTY, SYSTEM_CUSTOM_PROPERTY } from "./constants/SourceProperties.constants"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export abstract class AlarmsDataSourceCore extends DataSourceBase<AlarmsQuery> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private readonly queryAlarmsUrl = `${this.instanceSettings.url}${QUERY_ALARMS_RELATIVE_PATH}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -65,19 +66,30 @@ export abstract class AlarmsDataSourceCore extends DataSourceBase<AlarmsQuery> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Object.values(AlarmsQueryBuilderFields).map(field => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const dataField = field.dataField as string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dataField, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.isTimeField(dataField) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? timeFieldsQuery(dataField) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
: multipleValuesQuery(dataField), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (dataField === AlarmsQueryBuilderFields.SOURCE.dataField) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [dataField, this.getSourceTransformation()]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (this.isTimeField(dataField)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [dataField, timeFieldsQuery(dataField)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [dataField, multipleValuesQuery(dataField)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
66
to
77
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. Use switch case with callback variable.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private isTimeField(field: string): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ALARMS_TIME_FIELDS.includes(field); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private getSourceTransformation(): ExpressionTransformFunction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ahalya-ni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (value: string, operation: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const systemExpression = multipleValuesQuery(`properties.${SYSTEM_CUSTOM_PROPERTY}`)(value, operation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const minionExpression = multipleValuesQuery(`properties.${MINION_ID_CUSTOM_PROPERTY}`)(value, operation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const logicalOperator = getFilterConcatOperator(operation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return `(${systemExpression} ${logicalOperator} ${minionExpression})`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private getStatusCodeErrorMessage(errorDetails: { statusCode: string; message: string }): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let errorMessage: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch (errorDetails.statusCode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or 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 hidden or 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
2 changes: 2 additions & 0 deletions
2
src/datasources/alarms/constants/SourceProperties.constants.ts
This file contains hidden or 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,2 @@ | ||
export const SYSTEM_CUSTOM_PROPERTY = 'system'; | ||
export const MINION_ID_CUSTOM_PROPERTY = 'minionId'; |
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.
As far as I understand, the purpose of this funtion is to return
||
for postive operations and&&
for neagative operation.This is needed when we split one query into multiple queries.
For example,
To split
source = abc
intominionId = abc || system = abc
.To split
source != abc
intominionId = abc && system = abc
.To split
source = {abc, efg}
intominionId = abc || system = abc || minionId = efg || system = efg
.To split
partNumber = {1, 2, 3}
intopartNumber = 1 || partNumber = 2 || partNumber =
.So, I would suggest to name this as
getLogicalOperatorToCombineSplitQuery
to be clear. I'm happy to consider better name suggestions.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.
Please update the test cases to reflect this purpose.
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.
The operators such as
IS_NOT_BLANK
is not really applicable for themultipleValuesQuery
. Because, if those operators are used that won't be aisMultiValueExpression
at all.So, let's not couple the responsibilities. Have two methods.
I'm happy to consider better name suggestions.