4

I have created simple script to test Grafana Loki. It sends messages over Fluentbit:

from fluent import sender


messages = [
    {'from': 'userA', 'to': 'userB', 'log': 'Hello!'},
    {'from': 'userB', 'to': 'userA', 'log': 'Hi!'},
]
for message in messages:
    logger = sender.FluentSender('app', host='foo', port=24224)
    result = logger.emit('app.messages', message)
    if result:
        print('Message sent: {}'.format(message))

Fluent-bit config:

[INPUT]
    Name        forward
    Listen      0.0.0.0
    Port        24224
[Output]
    Name loki
    Match *
    Url ${LOKI_URL}
    RemoveKeys source
    Labels {job="remote-log"}
    LabelKeys container_name
    BatchWait 1
    BatchSize 1001024
    LineFormat json
    LogLevel info

And I get the message in Grafana:

enter image description here

Grafana is showing no unique labels. How do I set unique label and in general how do I add them? I thought it can be done once message is sent as the first parameter of logger.emit is label, but it is missing in Grafana. I might extend my Fluent Bit configuration to do a filtering... But setting labels in an App level would be cool

Rumid
  • 1,627
  • 2
  • 21
  • 39
Roman Newaza
  • 11,405
  • 11
  • 58
  • 89

1 Answers1

0

Not sure if you resolved this but the function json should allow for interpretation of log events in JSON formatting them as key value outputs.

{hostname=~'.+'} 
| json 

Unfortunately (this got me too), the json function in LogQL is strictly RFC compliant therefore JSON elements that are strings must be quoted with ". (RFC 7159)

Below is an example of this with single (') vs. double (") quotes. As you can see the single quotes are not interpreted however the double quotes are.

enter image description here

samson4649
  • 81
  • 5