fix(agent): Respect processor order in file #13614
Merged
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.
resolves #12849
Processor and aggregators are sensitive to order changes in Telegraf as their order defines the actual processing done and the metrics that are taken into account. When loading the configuration files, the order of those plugins is preserved taking the
order
option into account. However, the agent itself sorts the processors again before actually setting up the processing pipeline. While this on itself does not cause an issue, there is a subtle twist as the "order" is reversed using the sorting. This is necessary because the agent constructs the pipeline from output to input and thus needs to start with the "last" processor.However, the sorting only affects the processors with an explicit
order
setting, leaving all other processors in the initial order. As a consequence, those processors will then process in reverse order wrt the appearance in the config file...This PR removes the superfluous sorting in the agent and takes the config-order as-is. It then adds the processors from output-to-input, i.e. it truly iterates the processors in reverse order, thus keeping the processing order equivalent to the appearance in the file while respecting explicit order statements.