console icon indicating copy to clipboard operation
console copied to clipboard

Filtering by header content

Open ErykCh opened this issue 3 years ago • 10 comments

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.

ErykCh avatar Dec 03 '21 16:12 ErykCh

That should already be possible.

Try this as filter code: return headers["metadata"].source == "SUMPTIONBUCKETS";

rikimaru0345 avatar Dec 08 '21 16:12 rikimaru0345

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.

ErykCh avatar Dec 15 '21 08:12 ErykCh

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.

ErykCh avatar Dec 15 '21 08:12 ErykCh

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 👍

rikimaru0345 avatar Dec 19 '21 13:12 rikimaru0345

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

ErykCh avatar Dec 21 '21 18:12 ErykCh

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 avatar Dec 23 '21 18:12 rikimaru0345

@rikimaru0345 was this resolved?

twmb avatar Oct 19 '23 15:10 twmb

This may be a problem in the backend too. To be investigated.

weeco avatar Jan 26 '24 15:01 weeco

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

armsargis avatar Feb 08 '24 14:02 armsargis

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.

armsargis avatar Feb 08 '24 18:02 armsargis