Skip to content
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

Merged
merged 6 commits into from
Jul 5, 2024

Conversation

svennergr
Copy link
Contributor

@svennergr svennergr commented Jul 4, 2024

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

@svennergr svennergr requested a review from a team as a code owner July 4, 2024 13:23
Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great! Left a few comments, but also locally I'm seeing some errors:

imagen

@@ -316,6 +327,10 @@ const emptyStateStyles = {
}),
};

function getFieldByLabel(fields: Array<SelectableValue<DetectedField>>, fieldLabel: string | undefined) {
Copy link
Contributor

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.

Copy link
Contributor Author

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'];
Copy link
Contributor

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?

Copy link
Contributor Author

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/Components/ServiceScene/ServiceScene.tsx Show resolved Hide resolved
@@ -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 {
Copy link
Contributor

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.

@svennergr
Copy link
Contributor Author

Changes look great! Left a few comments, but also locally I'm seeing some errors:

imagen

probably based on the last main merge. thank you, i'll take a look!

@svennergr svennergr requested a review from matyax July 5, 2024 09:52
import { getSortByPreference } from 'services/store';
import { StatusWrapper } from './StatusWrapper';

export class DetectedField {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense!

Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that, during the initial logs load after selecting a service, the logs query fails.

Test.mov

The error is:

imagen

Only happens in this branch.

@matyax
Copy link
Contributor

matyax commented Jul 5, 2024

We can "ignore" ☝️ , as it also happens in main.

Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagen

@svennergr svennergr merged commit a38f364 into main Jul 5, 2024
3 checks passed
svennergr added a commit that referenced this pull request Jul 9, 2024
…ields-api"

This reverts commit a38f364, reversing
changes made to 4bfeb6e.
svennergr added a commit that referenced this pull request Jul 9, 2024
…ields-api" (#534)

This reverts commit a38f364, reversing
changes made to 4bfeb6e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[detected fields tab] implement detected_fields API
2 participants