The reasons behind v8 breaking changes #99
Replies: 3 comments 7 replies
-
do you have an estimate of when v8 is gonna be GA? good job and thanks! |
Beta Was this translation helpful? Give feedback.
-
Hey folks, v8.0.0 just was shipped to NuGet. Bug #103 was not solved in that release, according to complexity, but was not classified as show-stopper. I would love to hear your feedbacks and questions |
Beta Was this translation helpful? Give feedback.
-
Hi, can you help me in upgrading? I have configured it previously as follows: // includeLabels: a string array with labels I want to include
.GrafanaLoki(
uri: "http://loki:3100",
filtrationLabels: includeLabels,
filtrationMode: LokiLabelFiltrationMode.Include) Since the new LokiLabel has a key and a value, I don't know what to put there as value. Can I leave it out? Is this correct? .GrafanaLoki(
uri: "http://loki:3100",
labels: includeLabels.Select(labelString => new LokiLabel() { Key = labelString })) Thank you :) |
Beta Was this translation helpful? Give feedback.
-
👋 Intro
Hello community!
The v8 release is going to go beta in a short time. 🏎️ This release will has the most breaking changes in
Serilog.Sinks.Grafana.Loki
lifetime.A lot of you use this sink in your projects (we appreciate it a lot 💜). During this time authors of the sink have received a lot of questions, feature requests and bug reports. We have collected and analyzed a considerable number of feedbacks, use case scenarios etc. And at the certain time is became clearly that some things need to be done. So the main idea of this post to tell you about the reasons that led to taken decisions.
💡 Changing default text formatter to
LokiJsonTextFormatter
LokiJsonTextFormatter
has been introduced to sink's users a while ago and quickly became a favorite. In conjunction with Loki's 2.0+ parsing features it is a powerful instrument to work with structured data without losing performance, related to weak label configuration by user (also known as high cardinality problem).Using this formatter you are receiving all metadata as a part of log entry and it could be easily parsed into labels with
json
pipeline. Data after parsing could be used for filtering, formatting and graphing.We started recommending this instrument a while ago and from v8 release we are going to use it is a default formatter instead of
MessageTemplateTextFormatter
. Also configuration parameteroutputTemplate
, used byMessageTemplateTextFormatter
was removed.💡 Redesigning behavior of log level metadata and deleting
ILabelAwareTextFormatter
interfaceThe discussions about log level exists almost from the very beginning of this sink. Serilog's LogEvent provides
LogEventLevel
as a separate property.This sink was designed with an idea that it is a sink for logger, so log level should always be provided as a part of log entry. To my surprise so many people came with "I haven't configured this label, why it is created?". I haven't changed this behavior a long time, cause it was one of core ideas. Also this label was not involved in the process of filtering and have appeared always.
That caused to the creation of
ILabelAwareTextFormatter
interface andcreateLevelLabel
configuration property in the process of creatingLokiJsonTextFormatter
.This was not an elegant decision, but helped us to avoid the duplication of level as labels (one from the sink, second - from parsed log entry) and didn't break a behavior of default formatter. Due to large number of questions, from v7 level label was not created by default. By this was not a salvation we needed.
From v8 we are considering log level as a usual log property. It is added to every log entry and could be mapped to the label, using the standard approach. According to this change interface
ILabelAwareTextFormatter
andcreateLevelLabel
configuration property have become useless and were removed.💡 Mapping log event properties to labels
Label is one of most important thinks in Loki. It is a key-value pair, used by Loki to organize events. The main use case of label is querying and filtering the data. By according to internals of Loki, incorrect use of labels led to high cardinality problem. And there are some best practices for labels.
First public version (v3) of this sink has only possibility to exclude some properties from mapping to the labels. This wasn't a good solution, cause you needed to add all exclusion rules explicitly, what becomes a hell with a huge amount of labels (especially in cases with external libs.
We have changed this behavior in v4. It brought us a
filtrationMode
andfiltrationLabels
, where you could select one of modes: Include/Exclude and define properties' names to map 'em to the labels. Or you could leave it blank and in this case you will face the high cardinality problem. We always recommended to useInclude
mode with some always present labels (such a app name). But in last discussion we have found that this behavior is straightforward, but has no sense.From v8 we propose you a clear way - you define only properties that should be mapped into a labels (or none if you don't need it). For this case use a new
propertiesAsLabels
configuration parameters. The rest of properties would be passed to a formatted and should be included as a part of log entry.💡 Properties, mapped to the labels won't be passed to the text formatter
This change is internal and will not be noticed by most of users. Before v8
LokiJsonTextFormatter
has received aLogEvent
and a list of labels viaILabelAwareTextFormatter
. It used labels list to exclude properties, that are already mapped from payload body. This causes no property duplication (similar tolevel
label case).From now
LokiJsonTextFormatter
implementsITextFormatter
interface and received only list of properties that were not mapped. So pay attention if you provide a customITextFormatter
to the sink.💡 Introducing
IReservedPropertyRenamingStrategy
Issue #94 describes a interesting bug. In a process of messaging formatting, executed by
LokiJsonTextFormatter
there could be a problem if a log event property name (provided by your or worse - by external code) equals to some parameter names, used by sink (Message, MessageTemplate etc), two labels with the same name are generated. But only one of them is accepted by Loki.So v7.1.1 fixes it, checking if keyword is in reserved keyword list. It renames original property name by adding underscore to the start of name.
This could be not acceptable but you organization's naming conventions. So we created a
IReservedPropertyRenamingStrategy
interface with a simple methodstring Rename(string originalName);
, what gets a original property name and return renamed one. It is called in some cases (but won't limited to in the future):level
property. If you have a property namedlevel
in your code, it would be renamed, using a provided strategy (this will recursively check for a collision - if output of rename is taken, it would rename it too)🐛 Known issue
MessageTemplate
property is not adjusted in this case and render would be wrong. We are looking the ways to solve this before v8 leaving betaPlease, let us know what you are thinking about this changes and give this version a chance to be tested in your business cases 🙏.
Glory to Ukraine! 🇺🇦
Beta Was this translation helpful? Give feedback.
All reactions