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

Add env support to expressions #10

Merged
merged 2 commits into from
Jul 9, 2020
Merged

Add env support to expressions #10

merged 2 commits into from
Jul 9, 2020

Conversation

camdencheek
Copy link
Contributor

@camdencheek camdencheek commented Jul 8, 2020

Description of Changes

Depends on #9

Add env() support to expressions

To provide support for using environment variables for labeling,
tagging, and routing entries, this commit adds the env() function
to expressions.

An example expression: env("FOO").

In addition, this commit fixes an issue with the algorithm for parsing
expressions from ExprStrings where there are paranthesis nested inside
the expression. This issue was made clear by trying to use the env()
function inside an ExprString.

This commit also adds the GetExprEnv and PutExprEnv functions which
provide a way to re-use allocated environment maps. This keeps us from
having to allocate a map for every entry that is rendered as an
expression, which should help improve performance of plugins that
make heavy use of expressions.

Also adds another checkbox to PR templates for adding a changelog entry

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CI passes

@camdencheek camdencheek requested a review from jmwilliams89 July 8, 2020 18:46
@camdencheek camdencheek force-pushed the env-in-exprs branch 2 times, most recently from e9e9148 to deedf3c Compare July 8, 2020 20:27
Previously, fields could only select values located on the entry's
record. However, it's often necessary to filter or parse values that
would more naturally exist on fields like labels.

This commit refactors fields into an interface which is fulfilled by
both the `RecordField` and the `LabelField` objects. `RecordField` is
essentially what was previously called `Field`.

Notably, this change makes the zero-value of `Field` invalid, since it
will contain a `nil` pointer.
To provide support for using environment variables for labeling,
   tagging, and routing entries, this commit adds the `env()` function
   to expressions.

An example expression: `env("FOO")`.

In addition, this commit fixes an issue with the algorithm for parsing
   expressions from `ExprString`s where there are paranthesis nested inside
   the expression. This issue was made clear by trying to use the `env()`
   function inside an `ExprString`.

This commit also adds the `GetExprEnv` and `PutExprEnv` functions which
   provide a way to re-use allocated environment maps. This keeps us from
   having to allocate a map for every entry that is rendered as an
   expression, which should help improve performance of plugins that
   make heavy use of expressions.
@codecov
Copy link

codecov bot commented Jul 8, 2020

Codecov Report

Merging #10 into master will increase coverage by 0.12%.
The diff coverage is 87.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #10      +/-   ##
==========================================
+ Coverage   75.82%   75.94%   +0.12%     
==========================================
  Files          58       60       +2     
  Lines        3478     3566      +88     
==========================================
+ Hits         2637     2708      +71     
- Misses        628      637       +9     
- Partials      213      221       +8     
Impacted Files Coverage Δ
plugin/builtin/transformer/restructure.go 69.48% <43.48%> (-3.69%) ⬇️
entry/field.go 86.21% <85.19%> (-7.25%) ⬇️
entry/record_field.go 88.79% <88.79%> (ø)
plugin/helper/expr_string.go 87.88% <95.00%> (+1.52%) ⬆️
entry/entry.go 100.00% <100.00%> (ø)
entry/label_field.go 100.00% <100.00%> (ø)
plugin/builtin/parser/syslog.go 74.53% <100.00%> (ø)
...ugin/builtin/transformer/k8s_metadata_decorator.go 43.08% <100.00%> (ø)
plugin/builtin/transformer/metadata.go 70.49% <100.00%> (ø)
plugin/builtin/transformer/router.go 59.70% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5432688...b723fa5. Read the comment docs.

@camdencheek camdencheek merged commit 9aa4d6f into master Jul 9, 2020
@camdencheek camdencheek deleted the env-in-exprs branch July 9, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants