-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fix: Correctly encode step when translating proto to http internally #13171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import ( | |
"net/http/httptest" | ||
"net/url" | ||
"strconv" | ||
strings "strings" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -202,6 +202,57 @@ func Test_codec_EncodeDecodeRequest(t *testing.T) { | |
Step: 30 * 1e3, // step is expected in ms; default is 0 or no step | ||
AggregateBy: "series", | ||
}, false}, | ||
{"detected_fields", func() (*http.Request, error) { | ||
return DefaultCodec.EncodeRequest(ctx, &DetectedFieldsRequest{ | ||
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. I'm a bit confused as to why we use a wrapped queryrange.DetectedFieldsRequest and not the raw logproto.DetectedFieldsRequest here - is this the right thing to do? 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. the query-frontend is messy for sure I think it's fine. |
||
logproto.DetectedFieldsRequest{ | ||
Query: `{foo="bar"}`, | ||
Start: start, | ||
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. Other proto api objects use unix nanos for time, but these 3 (DetectedFields/DetectedLabels/QueryPatterns) use google.protobuf.Timestamp instead. Is there a reason for that? Should we be consistent across all our APIs and use one or the other? |
||
End: end, | ||
Step: 30 * 1e3, // step is expected in ms; default is 0 or no step | ||
LineLimit: 100, | ||
FieldLimit: 100, | ||
}, | ||
"/loki/api/v1/detected_fields", | ||
}) | ||
}, &DetectedFieldsRequest{ | ||
logproto.DetectedFieldsRequest{ | ||
Query: `{foo="bar"}`, | ||
Start: start, | ||
End: end, | ||
Step: 30 * 1e3, // step is expected in ms; default is 0 or no step | ||
LineLimit: 100, | ||
FieldLimit: 100, | ||
}, | ||
"/loki/api/v1/detected_fields", | ||
}, false}, | ||
{"patterns", func() (*http.Request, error) { | ||
return DefaultCodec.EncodeRequest(ctx, &logproto.QueryPatternsRequest{ | ||
Start: start, | ||
End: end, | ||
Step: 30 * 1e3, // step is expected in ms | ||
}) | ||
}, &logproto.QueryPatternsRequest{ | ||
Start: start, | ||
End: end, | ||
Step: 30 * 1e3, // step is expected in ms; default is 0 or no step | ||
}, false}, | ||
{"detected_labels", func() (*http.Request, error) { | ||
return DefaultCodec.EncodeRequest(ctx, &DetectedLabelsRequest{ | ||
"/loki/api/v1/detected_labels", | ||
logproto.DetectedLabelsRequest{ | ||
Query: `{foo="bar"}`, | ||
Start: start, | ||
End: end, | ||
}, | ||
}) | ||
}, &DetectedLabelsRequest{ | ||
"/loki/api/v1/detected_labels", | ||
logproto.DetectedLabelsRequest{ | ||
Query: `{foo="bar"}`, | ||
Start: start, | ||
End: end, | ||
}, | ||
}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
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.
An alternative is to format the step as a duration string so 3000 becomes 3000ms instead of 3.000 seconds.