-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(detected-fields): get fields from /detected_fields
API
#518
Conversation
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.
@@ -316,6 +327,10 @@ const emptyStateStyles = { | |||
}), | |||
}; | |||
|
|||
function getFieldByLabel(fields: Array<SelectableValue<DetectedField>>, fieldLabel: string | undefined) { |
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.
We should really not define functions with required arguments that can be undefined. Rather, we should not call this function if fieldLabel
is undefined.
Random, but, for example, this would return a field with undefined label, if both things happen at the same time. In any case, even without running conditions, an undefined required parameter is not a good funciton signature.
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.
True! Fun fact, and this should not be an excuse, I used the "Refactor -> Extract as function" functionality for this.
@@ -340,28 +355,23 @@ function getStyles(theme: GrafanaTheme2) { | |||
}; | |||
} | |||
|
|||
const avgFields = ['duration', 'count', 'total', 'bytes']; | |||
const avgFieldTypes = ['duration']; |
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.
I've no context, why did you remove the other fields? Do we need the array?
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 shout. On thing that changed is that we now make a decision based on the "type" the API returns, not based on the field name anymore. But I was in fact missing "bytes" here.
src/services/variables.ts
Outdated
@@ -17,3 +17,19 @@ export const EXPLORATION_DS = { uid: VAR_DATASOURCE_EXPR }; | |||
export const ALL_VARIABLE_VALUE = '$__all'; | |||
export const LEVEL_VARIABLE_VALUE = 'detected_level'; | |||
export const PATTERNS_TEXT_FILTER = 'patternsFilter'; | |||
|
|||
export class DetectedField { |
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.
This should definitely not be here.
import { getSortByPreference } from 'services/store'; | ||
import { StatusWrapper } from './StatusWrapper'; | ||
|
||
export class DetectedField { |
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.
Apologies, I was pretty vague with my previous comment. Ideally, my suggestion would be to just move this to its own little module file. Can be under services, or feel free to introduce a models
or data
folder.
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.
Makes total sense!
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.
We can "ignore" ☝️ , as it also happens in main. |
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.
This PR uses Loki's
/detected_fields
API to get fields from there. The PR also contains a lot of renaming, thus there are quite a lot of small changes.For the user, nothing really should change.
Note: This does only work with a recent Grafana version that contains grafana/grafana#89849
Fixes #245