-
Notifications
You must be signed in to change notification settings - Fork 19
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 support for custom labels #38
Conversation
```js | ||
import loki from 'k6/x/loki'; | ||
let labels = loki.Labels({ | ||
"format": ["json", "logfmt"], // must contain at least one of the supported log formats |
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.
Is format
a special kind of label that is send to loki either way and it know what to do with it?
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.
Yes, it is. The label defines the format of the log line.
Because of this, we can make sure, that if we filter on that label when querying, the log lines can be parsed.
0f1c933
to
4e45a28
Compare
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
4e45a28
to
4f40460
Compare
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.
LGTM. only one nit
stream := &logproto.Stream{Labels: labels.String()} | ||
batch.Streams[stream.Labels] = stream | ||
|
||
var now time.Time | ||
logFmt := string(labels[model.LabelName("format")]) | ||
if !isValidLogFormat(logFmt) { | ||
panic(fmt.Sprintf("%s is not a valid log format", logFmt)) |
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.
not sure that we need panic
here. can we use a construction like this:
common.Throw(rt, fmt.Errorf("%s is not a valid log format", logFmt))
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.
Changed in #45
Passing a
Label
object as fifth argument to theConfig
constructor allows you to override the built-in labels by custom ones.The custom labels map requires at least the
format
key, which needs to hold one of the supported log formats. Theinstance
key will override the otherwise automatically generatedinstance
label.Example:
Signed-off-by: Christian Haudum christian.haudum@gmail.com