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

[confmap] log a warning when using $VAR in config (WIP) #9547

Merged
merged 28 commits into from
Mar 26, 2024

Conversation

tomasmota
Copy link
Contributor

Description: As requested by @mx-psi , added a no-op log for when variables using the deprecated $VAR style are used. The logger should be replaced once it is clear how to pass it down (see #9443). Also, from my testing, the function passed to os.Expand is in fact only run when we have $VAR and not for ${env:VAR}, so I did not add additional checking.

Link to tracking Issue: #9162

Testing: I am not sure how to go about testing it, since we are not passing a logger in yet, there is no easy way to know what is being logged or what the map looks like. Some ideas on this would be appreciated

@tomasmota tomasmota requested review from a team and bogdandrutu February 9, 2024 11:17
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.03%. Comparing base (7f13812) to head (169069f).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9547      +/-   ##
==========================================
+ Coverage   90.99%   91.03%   +0.03%     
==========================================
  Files         353      353              
  Lines       18706    18709       +3     
==========================================
+ Hits        17022    17031       +9     
+ Misses       1356     1349       -7     
- Partials      328      329       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tomasmota tomasmota changed the title [confmap] log a warning when using $VAR in config [confmap] log a warning when using $VAR in config (WIP) Feb 9, 2024
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR! I left some suggestions:

  • String sets are typically represented in Go with the type `map[string]struct{}. I left some suggestions to do just that
  • We need to warn only for $var, not for ${var}
  • We need some new unit tests for this!

confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
@tomasmota
Copy link
Contributor Author

Thanks for opening the PR! I left some suggestions:

  • String sets are typically represented in Go with the type `map[string]struct{}. I left some suggestions to do just that
  • We need to warn only for $var, not for ${var}
  • We need some new unit tests for this!

Thanks, regarding the unit tests, as stated in the PR, I would appreciate a suggestion with regards to how I could check for the warning. Not sure how do do it before the logger is being injected :/

@mx-psi
Copy link
Member

mx-psi commented Feb 12, 2024

For testing you can replace the logger with https://pkg.go.dev/go.uber.org/zap/zaptest/observer

@tomasmota
Copy link
Contributor Author

For testing you can replace the logger with https://pkg.go.dev/go.uber.org/zap/zaptest/observer

That's what I wanted to do, but then I need to pass down the logger in ConverterSettings instead of hardcoding, so I can change it in the test, and from reading #9443 I got the impression that it is not yet totally clear how to pass it down. I would intuitively just add

type ConverterSettings struct{
    Logger *zap.Logger
}

Is this what you were expecting I do?

Copy link
Contributor

github-actions bot commented Mar 1, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added Stale and removed Stale labels Mar 1, 2024
@mx-psi
Copy link
Member

mx-psi commented Mar 6, 2024

For testing you can replace the logger with pkg.go.dev/go.uber.org/zap/zaptest/observer

That's what I wanted to do, but then I need to pass down the logger in ConverterSettings instead of hardcoding, so I can change it in the test, and from reading #9443 I got the impression that it is not yet totally clear how to pass it down. I would intuitively just add

type ConverterSettings struct{
    Logger *zap.Logger
}

Is this what you were expecting I do?

@tomasmota Hey, apologies for the delay on replying, I went on vacation and had a huge backlog afterwards :) Yes, this is what I want to do, we can do it on this PR but IMO it's not necessary for testing right now

@mx-psi
Copy link
Member

mx-psi commented Mar 13, 2024

@tomasmota is this ready for another review?

crobert-1 and others added 12 commits March 14, 2024 07:42
…en-telemetry#9732)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
The descriptions for each header in the feature request template for
this repository are useful to the person filing a request, but serve no
purpose to the issue reader. These can be commented out to in the
displayed markdown to save the user from having to delete each one (or
if not deleted, save the reader from having to parse through extra
information).
This follows open-telemetry#9556 and uses the Meter func instead of managing the scope
in the batch processor manually. Replaces open-telemetry#9581

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [Wandalen/wretry.action](https://togithub.com/Wandalen/wretry.action)
| action | patch | `v1.4.5` -> `v1.4.9` |
| [actions/cache](https://togithub.com/actions/cache) | action | patch |
`v4.0.0` -> `v4.0.1` |

---

### Release Notes

<details>
<summary>Wandalen/wretry.action (Wandalen/wretry.action)</summary>

###
[`v1.4.9`](https://togithub.com/Wandalen/wretry.action/compare/v1.4.8...v1.4.9)

[Compare
Source](https://togithub.com/Wandalen/wretry.action/compare/v1.4.8...v1.4.9)

###
[`v1.4.8`](https://togithub.com/Wandalen/wretry.action/compare/v1.4.7...v1.4.8)

[Compare
Source](https://togithub.com/Wandalen/wretry.action/compare/v1.4.7...v1.4.8)

###
[`v1.4.7`](https://togithub.com/Wandalen/wretry.action/compare/v1.4.6...v1.4.7)

[Compare
Source](https://togithub.com/Wandalen/wretry.action/compare/v1.4.6...v1.4.7)

###
[`v1.4.6`](https://togithub.com/Wandalen/wretry.action/compare/v1.4.5...v1.4.6)

[Compare
Source](https://togithub.com/Wandalen/wretry.action/compare/v1.4.5...v1.4.6)

</details>

<details>
<summary>actions/cache (actions/cache)</summary>

### [`v4.0.1`](https://togithub.com/actions/cache/releases/tag/v4.0.1)

[Compare
Source](https://togithub.com/actions/cache/compare/v4.0.0...v4.0.1)

##### What's Changed

- Update README.md by
[@&open-telemetry#8203;yacaovsnc](https://togithub.com/yacaovsnc) in
[https://github.com/actions/cache/pull/1304](https://togithub.com/actions/cache/pull/1304)
- Update examples by [@&open-telemetry#8203;yacaovsnc](https://togithub.com/yacaovsnc)
in
[https://github.com/actions/cache/pull/1305](https://togithub.com/actions/cache/pull/1305)
- Update actions/cache publish flow by
[@&open-telemetry#8203;bethanyj28](https://togithub.com/bethanyj28) in
[https://github.com/actions/cache/pull/1340](https://togithub.com/actions/cache/pull/1340)
- Update [@&open-telemetry#8203;actions/cache](https://togithub.com/actions/cache) by
[@&open-telemetry#8203;bethanyj28](https://togithub.com/bethanyj28) in
[https://github.com/actions/cache/pull/1341](https://togithub.com/actions/cache/pull/1341)

##### New Contributors

- [@&open-telemetry#8203;yacaovsnc](https://togithub.com/yacaovsnc) made their first
contribution in
[https://github.com/actions/cache/pull/1304](https://togithub.com/actions/cache/pull/1304)

**Full Changelog**: actions/cache@v4...v4.0.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
**Description:** 
enable lifecycle test for otlpexporter

**Link to tracking Issue:** 
fix open-telemetry#9684

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
…ts. (open-telemetry#9635)

**Description:**
This implements support for calling `Unmarshal` on embedded structs of
structs being decoded.

**Link to tracking Issue:**
Fixes open-telemetry#6671

**Testing:**
Unit tests.

Contrib fix is open:
open-telemetry/opentelemetry-collector-contrib#31406
…metry#9740)

**Description:** 

Persistent queue size backup on reads should depend on readIndex, not
writeIndex.
Long story, but i'm working on updating the prometheus dependency:
open-telemetry/opentelemetry-collector-contrib#30934

As part of that update, we need to adapt to a change that makes the
prometheus servers' self-observability metrics independent. See
prometheus/prometheus#13507 and
prometheus/prometheus#13610

One way to adapt to this change is by adding a label to each receivers'
metrics to differentiate one Prometheus receiver from another. I've
tried taking that approach in
open-telemetry/opentelemetry-collector-contrib#30934,
but the current issue is that the NoOp components all have the same
name, which causes the self-observability metrics to collide.

I can work around this in the prometheus receiver's own tests, but I
can't work around the issue in the `generated_component_test.go` tests,
since those are generated.

This PR makes the ID returned by `NewNopCreateSettings` unique by giving
it a unique name.

**Link to tracking Issue:**

Part of
open-telemetry/opentelemetry-collector-contrib#30883

cc @Aneurysm9

---------

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github/codeql-action](https://togithub.com/github/codeql-action) |
action | patch | `v3.24.6` -> `v3.24.7` |

---

### Release Notes

<details>
<summary>github/codeql-action (github/codeql-action)</summary>

###
[`v3.24.7`](https://togithub.com/github/codeql-action/compare/v3.24.6...v3.24.7)

[Compare
Source](https://togithub.com/github/codeql-action/compare/v3.24.6...v3.24.7)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzguMSIsInVwZGF0ZWRJblZlciI6IjM3LjIzOC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
**Description:**

Add the nopexporter. This can be helpful if a user wants to start the
Collector with a dummy pipeline to only enable extensions. It could also
be used to test Collector pipeline throughput.

**Link to tracking Issue:**

Resolves
open-telemetry#7316

**Testing:**

Added lifecycle tests; the receiver doesn't do anything.

**Documentation:**

Added a readme for the component.

cc @djaglowski @tigrannajaryan
**Description:**

Add the nopreceiver. This can be helpful if a user wants to start the
Collector with a dummy pipeline to only enable extensions. It could also
be used to start a dynamically-configured Collector that starts with no
config and waits to receive its config from a confmap.Provider that
supports reloads.

**Link to tracking Issue:**

Works toward
open-telemetry#7316

**Testing:**

Added lifecycle tests; the receiver doesn't do anything.

**Documentation:**

Added a readme for the component.
dmitryax and others added 6 commits March 14, 2024 07:42
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
…fig.yml` (open-telemetry#9746)

This PR fixes an incorrect automatic replace made in the
`otel-config.yml` file in this [pull
request](https://github.com/open-telemetry/opentelemetry-collector/pull/9680/files#diff-c7c8156618a7f8126b25ca1bdfde3e172a0d2cb75c533d63a71617ae2a5c54ae)
by a bot. I've taken the previous value which seems right.

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
…ry#9730)

**Description:**  This test was out of place!

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
@tomasmota
Copy link
Contributor Author

@tomasmota is this ready for another review?

Yes, and sorry about the mess of commits, I messed it up and got too lazy to reset properly. guess you will just squash in the end anyways.

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great! Would you be up for writing some tests? You can write a function for testing like this:

func NewTestConverter() (confmap.Converter, observer.ObservedLogs) {
   core, logs := observer.New(zapcore.InfoLevel)
   conv := converter{ loggedDeprecations: make(map[string]struct{}), logger: zap.New(core)}
   return conv, logs
}

And then call it with some example confmap.Conf.

If this is too much, I am also happy to take over, please let me know :)

@tomasmota
Copy link
Contributor Author

I'll take a stab at it when I get the time :) thanks for the indications!

@tomasmota
Copy link
Contributor Author

Code looks great! Would you be up for writing some tests? You can write a function for testing like this:

func NewTestConverter() (confmap.Converter, observer.ObservedLogs) {
   core, logs := observer.New(zapcore.InfoLevel)
   conv := converter{ loggedDeprecations: make(map[string]struct{}), logger: zap.New(core)}
   return conv, logs
}

And then call it with some example confmap.Conf.

If this is too much, I am also happy to take over, please let me know :)

I have added some tests, feel free to review

confmap/converter/expandconverter/expand.go Outdated Show resolved Hide resolved
"test2": "127.0.0.1",
},
expectedWarnings: []string{"HOST"},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test the QuoteMeta change I commented above, we should add a test like $HOSTONAME${HOST.NAME} to check that we are properly escaping characters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added QuoteMeta because it makes sense, but in practice I'm not really understanding how it is useful or needed, because our regexp will never match ${HOST.NAME}, and if you attempt to have $HOST.NAME you will just end up with 127.0.0.1.NAME according to my testing. Same if you put other special characters after $HOST.

With that in mind, I couldn't think of a good test case, because the $VAR way, which is the only one we match, does not play well with special characters anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I mistakenly assumed that . would be a valid part of a naked environment variable name for os.Expand, but it does not seem like that is the case.

I guess a test that has both ${HOST.NAME} and $HOST_NAME should be a valid test, right? Taking a look at the implementation of os.Expand, it also seems like $? would be a valid thing to test, but I doubt anybody is using that in practice 😄

@tomasmota
Copy link
Contributor Author

@mx-psi i think you can review, I addressed your comments directly.

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I will skip the changelog on this PR and we can add it once we actually do the logging.

I left a comment on a testcase for regexp.QuoteMeta that I think should work, let's give it a try and add it if it works

"test2": "127.0.0.1",
},
expectedWarnings: []string{"HOST"},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I mistakenly assumed that . would be a valid part of a naked environment variable name for os.Expand, but it does not seem like that is the case.

I guess a test that has both ${HOST.NAME} and $HOST_NAME should be a valid test, right? Taking a look at the implementation of os.Expand, it also seems like $? would be a valid thing to test, but I doubt anybody is using that in practice 😄

@mx-psi mx-psi added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 19, 2024
@tomasmota
Copy link
Contributor Author

@mx-psi I added a test with what I understood you were asking for, not sure it was exactly that you meant 😅

@mx-psi
Copy link
Member

mx-psi commented Mar 26, 2024

Yeah, that's what I meant, thanks!

@mx-psi mx-psi merged commit 99b367c into open-telemetry:main Mar 26, 2024
47 checks passed
@github-actions github-actions bot added this to the next release milestone Mar 26, 2024
@tomasmota
Copy link
Contributor Author

Great, really appreciate your help and patience!

@tomasmota tomasmota deleted the dollar-warning branch March 27, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.