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

Add variable type selector to optimize API usage #148

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

Loori-R
Copy link
Contributor

@Loori-R Loori-R commented Apr 3, 2024

add variable type selector to optimize API usage, favoring /api/v1/labels and /api/v1/label/.../values over /api/v1/series.

#144

image

Copy link
Contributor

@dmitryk-dk dmitryk-dk left a comment

Choose a reason for hiding this comment

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

Overall looks good! Add some somments


const data: string[] = await this.request(url, [], urlParams);
// Convert string array to Record<string , []>
return data.reduce((ac, a) => ({ ...ac, [a]: '' }), {});
Copy link
Contributor

Choose a reason for hiding this comment

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

from the comment i see that the Record should be Record<string , []>, but in the reduce the object is {[string]: string}. Maybe I miss something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there's a mistake here. I checked, only keys are used everywhere, so it's more logical to leave it as string[].

if (labelNamesQuery) {
return this.labelNamesQuery();
return this.datasource.getTagKeys({ filters: [], timeRange });
}

const labelValuesQuery = this.query.match(labelValuesRegex);
if (labelValuesQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should check the length also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of no matches, the result will be null, not an empty array.

dmitryk-dk
dmitryk-dk previously approved these changes Apr 8, 2024
Copy link
Contributor

@dmitryk-dk dmitryk-dk left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@dmitryk-dk dmitryk-dk left a comment

Choose a reason for hiding this comment

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

LGTM!

@Loori-R Loori-R merged commit d7837d0 into main Apr 9, 2024
9 checks passed
@Loori-R Loori-R deleted the issue-144/optimize-api-calls branch April 9, 2024 12:53
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.

2 participants