-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Refactor router config parser and add route precedence test #11039
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Telemetry Routing Overview | ||
|
||
Fluent Bit's telemetry router provides a unified configuration surface for | ||
logs, metrics, and traces. Routes are defined on a per-input basis and apply to | ||
all signals produced by that input. Each route declares an optional signal | ||
filter, a condition, per-route processors, and the list of output targets that | ||
should receive matching telemetry. | ||
|
||
## Configuration Structure | ||
|
||
Routes are declared inside `pipeline.inputs[]` entries in the Fluent Bit YAML | ||
configuration: | ||
|
||
```yaml | ||
pipeline: | ||
inputs: | ||
- name: opentelemetry | ||
processors: | ||
- name: parser | ||
parser: json | ||
routes: | ||
logs: | ||
- name: errors | ||
condition: | ||
rules: | ||
- field: "$level" | ||
op: eq | ||
value: "error" | ||
to: | ||
outputs: | ||
- name: loki | ||
fallback: s3_archive | ||
- name: default | ||
condition: | ||
default: true | ||
to: | ||
outputs: | ||
- name: elasticsearch | ||
metrics: | ||
- name: cpu_hot | ||
condition: | ||
rules: | ||
- field: "$metric.name" | ||
op: regex | ||
value: "^cpu_" | ||
to: | ||
outputs: | ||
- name: prometheus_remote | ||
``` | ||
|
||
### Key elements | ||
|
||
* **Input processors** – shared processors executed before any routing logic. | ||
* **Routes** – grouped by telemetry signal. Each key under `routes` must be a | ||
signal label (`logs`, `metrics`, `traces`, or a comma-separated combination) | ||
whose array value contains the ordered route definitions for that signal. A | ||
key of `any` targets all telemetry types. | ||
* `condition.rules` contains record accessor comparisons evaluated against the | ||
chunk. Routes can also mark themselves as the default handler with | ||
`condition.default: true`. | ||
* `processors` (optional) define per-route processor chains executed after the | ||
condition succeeds and before dispatching to outputs. | ||
* `to.outputs` lists the primary output targets. Entries may be simple names | ||
or objects with an optional `fallback` output used when the primary target | ||
fails. | ||
|
||
## Evaluation Order | ||
|
||
1. Execute input-level processors. | ||
2. For each route whose signal mask matches the chunk type: | ||
1. Evaluate the route condition. Routes flagged as `default` bypass rule | ||
evaluation. | ||
2. If the condition succeeds, run the route processors and then attempt to | ||
send the chunk to each configured output. | ||
3. When an output write fails permanently, the router retries once using the | ||
configured fallback output (if any). | ||
|
||
## Conditions and Field Resolution | ||
|
||
Route conditions rely on record accessors that are aware of the telemetry type: | ||
|
||
* **Logs** – record keys, metadata, `exists`, `eq`, `regex`, `contains`, `in`. | ||
* **Metrics** – metric name/value, resource and attribute keys, numeric | ||
comparison operators (`gt`, `lt`, `gte`, `lte`). | ||
* **Traces** – span fields and resource/scope attributes with equality, regex, | ||
and duration comparisons. | ||
|
||
The loader validates that each referenced field is supported by the selected | ||
signals, providing early feedback during configuration parsing. | ||
|
||
## Output Fallbacks | ||
|
||
Outputs may declare a secondary target that receives the chunk when the primary | ||
write fails with a permanent error. Fallback dispatch happens once per output | ||
attempt and produces debug logs as well as `fluentbit_routing_fallback_total` | ||
metrics to aid troubleshooting. | ||
|
||
## Metrics and Observability | ||
|
||
The router exposes Prometheus counters using the `fluentbit_routing_*` prefix | ||
covering routed records, bytes, condition failures, and fallback events. The | ||
labels capture the input name, route name, target output, and signal type. | ||
|
||
## Cleanup Helpers | ||
|
||
The router exposes `flb_router_routes_destroy()` to release all resources | ||
allocated during YAML parsing. Callers should destroy the list after invoking | ||
`flb_router_config_parse()` once the configuration has been consumed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2015-2024 The Fluent Bit Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <fluent-bit/flb_mem.h> | ||
#include <fluent-bit/flb_log.h> | ||
#include <fluent-bit/flb_router.h> | ||
|
||
uint32_t flb_router_signal_from_chunk(struct flb_event_chunk *chunk) | ||
{ | ||
if (!chunk) { | ||
return 0; | ||
} | ||
|
||
switch (chunk->type) { | ||
case FLB_EVENT_TYPE_LOGS: | ||
return FLB_ROUTER_SIGNAL_LOGS; | ||
case FLB_EVENT_TYPE_METRICS: | ||
return FLB_ROUTER_SIGNAL_METRICS; | ||
case FLB_EVENT_TYPE_TRACES: | ||
return FLB_ROUTER_SIGNAL_TRACES; | ||
default: | ||
break; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int flb_condition_eval_logs(struct flb_event_chunk *chunk, | ||
struct flb_route *route) | ||
{ | ||
(void) chunk; | ||
(void) route; | ||
|
||
/* | ||
* The full condition evaluation engine requires field resolvers that map | ||
* record accessors to the different telemetry payload shapes. The wiring | ||
* of those resolvers is part of a bigger effort and will be implemented in | ||
* follow-up changes. For the time being we simply report that the | ||
* condition failed so that the runtime can rely on explicit default | ||
* routes. | ||
*/ | ||
return FLB_FALSE; | ||
} | ||
|
||
int flb_condition_eval_metrics(struct flb_event_chunk *chunk, | ||
struct flb_route *route) | ||
{ | ||
(void) chunk; | ||
(void) route; | ||
|
||
return FLB_FALSE; | ||
} | ||
|
||
int flb_condition_eval_traces(struct flb_event_chunk *chunk, | ||
struct flb_route *route) | ||
{ | ||
(void) chunk; | ||
(void) route; | ||
|
||
return FLB_FALSE; | ||
} | ||
|
||
int flb_route_condition_eval(struct flb_event_chunk *chunk, | ||
struct flb_route *route) | ||
{ | ||
uint32_t signal; | ||
|
||
if (!route) { | ||
return FLB_FALSE; | ||
} | ||
|
||
if (!route->condition) { | ||
return FLB_TRUE; | ||
} | ||
|
||
signal = flb_router_signal_from_chunk(chunk); | ||
if (signal == 0) { | ||
return FLB_FALSE; | ||
} | ||
|
||
if ((route->signals != 0) && (route->signals != FLB_ROUTER_SIGNAL_ANY) && | ||
((route->signals & signal) == 0)) { | ||
return FLB_FALSE; | ||
} | ||
|
||
if (route->condition->is_default) { | ||
return FLB_TRUE; | ||
} | ||
|
||
if (cfl_list_is_empty(&route->condition->rules) == 0) { | ||
return FLB_TRUE; | ||
} | ||
|
||
switch (signal) { | ||
case FLB_ROUTER_SIGNAL_LOGS: | ||
return flb_condition_eval_logs(chunk, route); | ||
case FLB_ROUTER_SIGNAL_METRICS: | ||
return flb_condition_eval_metrics(chunk, route); | ||
case FLB_ROUTER_SIGNAL_TRACES: | ||
return flb_condition_eval_traces(chunk, route); | ||
default: | ||
break; | ||
} | ||
|
||
return FLB_FALSE; | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The router condition evaluator returns
FLB_TRUE
wheneverroute->condition->rules
is non-empty, so any route that declares at least one rule will match every chunk regardless of its contents. This bypasses the signal-specific evaluators entirely (they are never called) and causes conditional routes to supersede default routes even though the rule logic is not yet implemented. As a result, routing decisions will ignore the configured predicates and send all traffic to the first conditional route.Useful? React with 👍 / 👎.