-
Notifications
You must be signed in to change notification settings - Fork 199
Added matchers in listLokiLabelValues #380
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
Open
rahulvijil
wants to merge
7
commits into
grafana:main
Choose a base branch
from
rahulvijil:list_loki_label_values/customize
base: main
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.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
306c1bf
Added matchers in listLokiLabelValues
rahulvijil 62086ae
Refactor
rahulvijil ad97797
Add optional arg in fetchData
rahulvijil e6df9cf
Add comments
rahulvijil 93e7029
Keep the generic method fetchData
rahulvijil 817796a
Call fetchLabels
rahulvijil fc166fd
Add matchers support to LabelNames as well
rahulvijil 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,7 @@ type ListLokiLabelValuesParams struct { | |
| LabelName string `json:"labelName" jsonschema:"required,description=The name of the label to retrieve values for (e.g. 'app'\\, 'env'\\, 'pod')"` | ||
| StartRFC3339 string `json:"startRfc3339,omitempty" jsonschema:"description=Optionally\\, the start time of the query in RFC3339 format (defaults to 1 hour ago)"` | ||
| EndRFC3339 string `json:"endRfc3339,omitempty" jsonschema:"description=Optionally\\, the end time of the query in RFC3339 format (defaults to now)"` | ||
| Matchers string `json:"matchers"` | ||
| } | ||
|
|
||
| // listLokiLabelValues lists all values for a specific label in a Loki datasource | ||
|
|
@@ -265,16 +266,21 @@ func listLokiLabelValues(ctx context.Context, args ListLokiLabelValuesParams) ([ | |
| return nil, fmt.Errorf("creating Loki client: %w", err) | ||
| } | ||
|
|
||
| // Use the client's fetchData method | ||
| urlPath := fmt.Sprintf("/loki/api/v1/label/%s/values", args.LabelName) | ||
|
|
||
| // Manually include matchers in query string if provided | ||
| if args.Matchers != "" { | ||
| encoded := url.QueryEscape(args.Matchers) | ||
| urlPath = fmt.Sprintf("%s?query=%s", urlPath, encoded) | ||
| } | ||
|
|
||
| // Call the original fetchData with start/end as before | ||
| result, err := client.fetchData(ctx, urlPath, args.StartRFC3339, args.EndRFC3339) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, fmt.Errorf("fetching label values: %w", err) | ||
| } | ||
|
|
||
| if len(result) == 0 { | ||
|
Comment on lines
295
to
306
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. Are these changes needed?
Author
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. Not actually, I will revert |
||
| // Return empty slice instead of nil | ||
| return []string{}, nil | ||
| } | ||
|
|
||
|
|
||
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.
Hi @rahulvijil,
thanks for your contribution. Would you mind adding two things to this
matchersprop:omitemptyThere 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.
Added the description