console
console copied to clipboard
Filtering by header content
Hi, I would like to be able to filter using data in header. For example.
Message has in the header key: metadata and value for this key: {"source":"SUMPTIONBUCKETS"}
I would like to put in the filter return header.metadata.source == 'SUMPTIONBUCKETS' to get this message.
That should already be possible.
Try this as filter code: return headers["metadata"].source == "SUMPTIONBUCKETS";
Thanks.
It's nice if it was added to the tooltip visible after hovering over Parameters and Examples.
Because this is difficult to guess without analyzing the source code.
And I think doing
return header.metadata.source == 'SUMPTIONBUCKETS';
instead
return headers["metadata"].source == "SUMPTIONBUCKETS";
it would be consistent with the other parameters and more readable.
I think both types of access should already work. (If not, it might be a bug in the interpreter)
I'll add headers and a few examples to the help things at the bottom 👍
Yes, return headers.metadata.source == 'SUMPTIONBUCKETS' works. I used header instead of headers.
But I'm not able to retrieve data when value is directly under a key in headers. So I have key: isDeleted value: boolean key: schemaVersion value: String key: exportDuration value: integer
and the following do not work return headers.isDeleted == false return !headers.isDeleted return headers["isDeleted"] == false return !headers["isDeleted"]
return headers.schemaVersion == 'v2.3.0'
but the numbers work (I have correct results):
return headers.exportDuration > 200
Glad to hear that property-access works.
But the other issue (maybe it's because it is a boolean or something??) is definitely a bug. I will put it on my list and find out what's going on when I have some time 👍
@rikimaru0345 was this resolved?
This may be a problem in the backend too. To be investigated.
Hi in the code: backend/pkg/kafka/consumer.go:287
vm.Set("headers", args.HeadersByKey)
And HeadersByKey is defined as:
HeadersByKey map[string][]byte
So it seems that during evaluation, it is interpreted as an Array in JavaScript. When I try:
String.fromCharCode.apply(null, headers.eventId) == '18216'
it works as expected. Also, the condition:
headers.eventId instanceOf Array
returns true
Probably converting map values to strings should be fine:
vm.Set("headers", convertToStringValues(args.HeadersByKey))
func convertToStringValues(data map[string][]byte) map[string]string {
converted := make(map[string]string, len(data))
for key, byteValue := range data {
converted[key] = string(byteValue)
}
return converted
}
However, this means the documentation should be updated accordingly and, if type conversion is needed, it should be done in JavaScript itself.