Skip to content
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

631 loki output #661

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

romanchechyotkin
Copy link

Loki

Added loki output plugin

Fixes #631

}

func (p *Plugin) send(ctx context.Context, data []byte) (int, error) {
output := map[string]interface{}{
Copy link
Collaborator

@DmitryRomanov DmitryRomanov Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Good job but it's better to split up messages and extract fields to labels.

Here is example:

There is sample of config for file.d:

pipelines:
  loki:
    settings:
      capacity: 1000
    input:
      type: http
      emulate_mode: "elasticsearch"
      address: ":9200"
    actions:
      - type: parse_es
      - type: json_decode
        field: message
    output:
      type: loki
      address: http://localhost:3100
      # you can suggest your structure of config
      timestamp_field: timestamp
      message_field: message
      # I don’t know the purpose of the stream yet
      stream:
        - label: test_label
          value: test_value

File with input messages (data.json):

{"index": {"_index": "index-main","_type": "span"}}
{"timestamp":"2024-08-01T10:31:55.665748976Z","k8s_container":"container","message":"Started"}
{"index": {"_index": "index-main","_type": "span"}}
{"timestamp":"2024-08-01T10:35:55.665748976Z","k8s_container":"container","message":"Stopped"}

send to file.d

curl "127.0.0.1:9200/input" -v -H 'Content-Type: application/json' -d @data.json

And file.d sends to loki:

{
  "streams": [
    {
      "stream": {
        "test_label": "test_value"
      },
      "values": [
          [ "17225143070000000", "Started", {"k8s_container": "container"} ],
          [ "17225143080000000", "Stopped", {"k8s_container": "container"} ]
      ]
    }
  ]
}

Feel free for ask any questions!

@romanchechyotkin
Copy link
Author

romanchechyotkin commented Aug 1, 2024

Hello, thanks for feedback, yesterday i found out that there is loki-go client by Grafana, i tried to create my wheel as Loki HTTP client, may be rewrite using this library?
https://github.com/grafana/loki-client-go
I can see the the phrase DONT USE IT by authors, but this client is used by this library https://github.com/samber/slog-loki

What do you think, rewrite using library or make a little bit refactoring

@romanchechyotkin
Copy link
Author

but what do you thnk about current logs output
image
image

@DmitryRomanov
Copy link
Collaborator

Hello, thanks for feedback, yesterday i found out that there is loki-go client by Grafana, i tried to create my wheel as Loki HTTP client, may be rewrite using this library? https://github.com/grafana/loki-client-go I can see the the phrase DONT USE IT by authors, but this client is used by this library https://github.com/samber/slog-loki

What do you think, rewrite using library or make a little bit refactoring

I think it's better to not use libraries (to avoid using dependencies) and make some fixes.

@DmitryRomanov
Copy link
Collaborator

but what do you thnk about current logs output image image

looks good to me. try searching by labels and others logql examples

@romanchechyotkin
Copy link
Author

all logs
image

select where kind=normal22
image

@DmitryRomanov
Copy link
Collaborator

Firefox_Screenshot_2024-08-16T07-42-05 592Z

Here is example of logs from Promtail to Loki. We have fields app, container, node_name, pod and you can search by them. And our k8s input plugin adds those labels as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: add output to loki
2 participants