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

core: add log groups support and full OTLP <--> OTLP #8898

Merged
merged 9 commits into from
Jun 7, 2024

Conversation

edsiper
Copy link
Member

@edsiper edsiper commented May 30, 2024

This is a big patch, every commit has been properly documented. Here is a highlight of the changes in this PR:

  • Introduce new groups concepts for logs serialization. Now, it is possible to group records that share metadata.
  • OpenTelemetry input (logs): create groups and set metadata properly (gRPC)
  • OpenTelemetry output (logs): decode and encode OTLP based on groups metadata

These changes will be included in the next v3.1 release which is scheduled for the end of June (or earlier).


Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
As of today, log records can support metadata content in addition to the record
content it self, however for some cases this is not enough if we want to share
metadata across a group of records.

Today we serialize log records in the following pseudo-schema:

 [ [TIMESTAMP, { METADATA }], { RECORD_CONTENT}]

A common chunk contain records in the following way:

 [ [1717104810, {}], {"key": "some value", "number": 12} ]
 [ [1717104811, {"color": "blue" }], {"key": "some value", "number": 13} ]
 [ [1717104812, {"color": "red"  }], {"key": "some value", "number": 14} ]
 [ [1717104813, {"color": "green"}], {"key": "some value", "number": 15} ]
 [ [1717104814, {}], {"key": "some value", "number": 16} ]

In this patch, we are introducing the concept of `groups`, which are implemented
through a new type of records that marks the beginning and the end of the group. To
avoid breaking changes and overall compatibility, we use the TIMESTAMP field to
mark those as special records.

 - start of a group:  [ [ -1, { METADATA }, { RECORD_CONTENT} ]
 - end of a group  :  [ [ -2, { METADATA }, { RECORD_CONTENT} ]

Here is an example where the middle records are group together:

 [ [1717104810, {}], {"key": "some value", "number": 12} ]
 [ [        -1, {"type": "colors"}], {"numbers": true}]
 [ [1717104811, {"color": "blue" }], {"key": "some value", "number": 13} ]
 [ [1717104812, {"color": "red"  }], {"key": "some value", "number": 14} ]
 [ [1717104813, {"color": "green"}], {"key": "some value", "number": 15} ]
 [ [        -2, {}], {}]
 [ [1717104814, {}], {"key": "some value", "number": 16} ]

Iterating the records don't introduce any problems, however is up to the plugins like
inputs, processors, filters and outputs to interpret the group fields or simply skip
them. note: in the next patch the decoder offers a new API to skip groups definitions.

API usage
=========

To manipulate groups, the workflow is as follows:

 1. A group gets initialized (the header is opened)

 2. the user/dev can optionally add content in the METADATA or RECORD_CONTENT fields.

 3. the group header is finalized. Close the header, the group is still open.

 4. Append normal records.

 5. Group is finalized.

These are the new functions available for groups handling:

 int flb_log_event_encoder_group_init(struct flb_log_event_encoder *context);
 int flb_log_event_encoder_group_header_end(struct flb_log_event_encoder *context)
 int flb_log_event_encoder_group_end(struct flb_log_event_encoder *context)

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
There are cases where the parser might interpret different the incoming
string buffer (e.g: $), by passing a fresh copy of the pattern workaround
the problem.

There are no performance penalties since this happens on the record accessor
context creation, not when doing the lookups.

note: the other workaround might be to tweak the parser which is more work.

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
In recent patch, we introduced the concept of groups. This patch implements
the following changes to the log event decoder:

- decoder now has a flag to read or skip groups definitions (default: on)
- new API to retrieve the type of record being read

new functions available:

 int flb_log_event_decoder_read_groups(struct flb_log_event_decoder *context,
                                       int read_groups)

 int flb_log_event_decoder_get_record_type(struct flb_log_event *event,
                                           int32_t *type)

record types supported:

 - FLB_LOG_EVENT_NORMAL
 - FLB_LOG_EVENT_GROUP_START
 - FLB_LOG_EVENT_GROUP_END

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
The following patch, enhance the logs handling by using the new Fluent Bit
groups support for log events. This provides a smooth communication and
translation layer betweeen in_opentelemetry and out_opentelemetry.

This patch also adds a new configuration property called `logs_metadata_key` which
defines which metadata key holds specific OTLP data per record.

The changes are supported for gRPC payloads, upcoming patches will add
support for JSON payloads.

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
…port

The following patch introduce a big change on how the plugin now process the logs
with OTLP format, the high-level features are:

1. Full metadata support:
  - with the new changes in in_opentelemetry, there is no metadata loss

2. Proper encoding of non-OTLP records as OTLP
  - The plugin is flexible enough to encode any type of log record.

At a low level, we re-architect how resource logs, resource, span_logs, scope and
logs are handled. All of this has been implemented on top of the new Fluent Bit
groups support for logs.

Use cases tested:

 - OTel Collector (gRPC) --> Fluent Bit --> OTel Collector (gRPC)
 - dummy, tail, forward  --> Fluent Bit --> OTel Collector (gRPC)

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
@alrz
Copy link

alrz commented Jun 12, 2024

I tried this on unstable:master, the attributes from otel input is still entirely dropped when exporting to elasticsearch (only message is being sent, however resource does get emitted in a separate record). Does that need additional config?

@edsiper
Copy link
Member Author

edsiper commented Jun 25, 2024

@alrz this is supported in otel -> otel, do you want to send otel -> elasticsearch ? the elastic plugin will need to be updated to receive that extra metadata.

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

Successfully merging this pull request may close these issues.

2 participants