Coder Social home page Coder Social logo

Make log level a label about loki HOT 4 CLOSED

grafana avatar grafana commented on May 19, 2024 1
Make log level a label

from loki.

Comments (4)

tomwilkie avatar tomwilkie commented on May 19, 2024

Going to close as a dupe of #88, although not quite the same the solutions are consistent - we want to extract data from the log lines themselve into labels. A good example is log level.

from loki.

klausenbusk avatar klausenbusk commented on May 19, 2024

How exactly is the current solution implemented? I assume it is implemented client side and Grafana parse every logline for a log level (warn, info, ...)? But I haven't found the relevant code yet.

Edit: Found it: https://github.com/grafana/grafana/blob/e1acc772979e4dd8db4fbaeda58b842991c00f99/packages/grafana-data/src/types/logs.ts#L9

from loki.

davkal avatar davkal commented on May 19, 2024

To have the log level as a label, it must be done by the logging agent, e.g., Promtail is doing it via pipelines: https://github.com/grafana/loki/blob/master/docs/clients/promtail/pipelines.md

Grafana cannot create its own set of labels. It does two different, additional things: using the level label (if present) as a hint to color the log volume histogram. If it cannot find level as a label, it parses each log line like you described. The other thing grafana does is parse log lines into fields, i.e., JSON or logfmt structured logs. Those fields are then shown separately when expanding a single log row in Explore.

from loki.

klausenbusk avatar klausenbusk commented on May 19, 2024

Grafana cannot create its own set of labels. It does two different, additional things: using the level label (if present) as a hint to color the log volume histogram. If it cannot find level as a label, it parses each log line like you described. The other thing grafana does is parse log lines into fields, i.e., JSON or logfmt structured logs. Those fields are then shown separately when expanding a single log row in Explore.

Thanks for the explanation :)

For anyone else stumbling on this issue and wondering how it is implemented, the relevant code is here:
https://github.com/grafana/grafana/blob/e1acc772979e4dd8db4fbaeda58b842991c00f99/packages/grafana-data/src/types/logs.ts#L9
https://github.com/grafana/grafana/blob/e1acc772979e4dd8db4fbaeda58b842991c00f99/public/app/core/logs_model.ts#L298-L300
https://github.com/grafana/grafana/blob/e1acc772979e4dd8db4fbaeda58b842991c00f99/public/app/core/logs_model.ts#L314-L320
https://github.com/grafana/grafana/blob/e1acc772979e4dd8db4fbaeda58b842991c00f99/packages/grafana-data/src/utils/logs.ts#L13-L42

The other thing grafana does is parse log lines into fields, i.e., JSON or logfmt structured logs. Those fields are then shown separately when expanding a single log row in Explore.

Explained here: https://grafana.com/blog/2019/11/25/grafana-v6.5-released/#explore-logs-log-row-details

from loki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.