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

[exporter/datadog] Add api.fail_on_invalid_key to fail fast if API Key is invalid #9426

Merged
merged 11 commits into from
May 5, 2022

Conversation

keisku
Copy link
Contributor

@keisku keisku commented Apr 25, 2022

Description:

Add api.fail_on_invalid_key to fail fast if API Key is invalid.

Link to tracking Issue:

#7402

Testing:

fail_on_invalid_key: false

1 ) Set the invalid API key and fail_on_invalid_key: false.
2 ) make run
3 ) Confirming error message
This behavior is same as before.

GO111MODULE=on go run --race ./cmd/otelcontribcol/... --config local/config.yaml
2022/04/28 06:42:12 proto: duplicate proto type registered: jaeger.api_v2.PostSpansRequest
2022/04/28 06:42:12 proto: duplicate proto type registered: jaeger.api_v2.PostSpansResponse
2022-04-28T06:42:12.532+0900    info    datadogexporter/factory.go:195  sanitizing Datadog traces exporter configuration        {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:12.532+0900    info    utils/api.go:37 Validating API key.     {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:13.262+0900    warn    utils/api.go:47 API Key validation failed       {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:13.263+0900    info    datadogexporter/factory.go:135  sanitizing Datadog metrics exporter configuration       {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:13.263+0900    info    utils/api.go:37 Validating API key.     {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:13.966+0900    warn    utils/api.go:47 API Key validation failed       {"kind": "exporter", "name": "datadog"}
2022-04-28T06:42:13.967+0900    info    builder/exporters_builder.go:255        Exporter was built.     {"kind": "exporter", "name": "datadog"}

fail_on_invalid_key: true

1 ) Set the invalid API key and fail_on_invalid_key: true.
2 ) make run
3 ) Confirming error message

GO111MODULE=on go run --race ./cmd/otelcontribcol/... --config local/config.yaml
2022/04/28 06:40:36 proto: duplicate proto type registered: jaeger.api_v2.PostSpansRequest
2022/04/28 06:40:36 proto: duplicate proto type registered: jaeger.api_v2.PostSpansResponse
2022-04-28T06:40:36.322+0900    info    datadogexporter/factory.go:195  sanitizing Datadog traces exporter configuration        {"kind": "exporter", "name": "datadog"}
2022-04-28T06:40:36.322+0900    info    utils/api.go:37 Validating API key.     {"kind": "exporter", "name": "datadog"}
2022-04-28T06:40:37.111+0900    warn    utils/api.go:47 API Key validation failed       {"kind": "exporter", "name": "datadog"}
Error: cannot build exporters: error creating datadog exporter: API Key validation failed
2022/04/28 06:40:37 collector server run finished with error: cannot build exporters: error creating datadog exporter: API Key validation failed
exit status 1
make: *** [run] Error 1

Documentation:

@keisku keisku marked this pull request as ready for review April 25, 2022 14:42
@keisku keisku requested a review from a team April 25, 2022 14:42
@keisku keisku requested a review from mx-psi as a code owner April 25, 2022 14:42
@keisku keisku changed the title [exporter/datadog] validate API Key by using Datadog API [exporter/datadog] Fail fast if API Key is invalid Apr 25, 2022
@keisku keisku marked this pull request as draft April 25, 2022 15:04
@keisku keisku force-pushed the keisku/validate-api-key branch 3 times, most recently from f95233b to 4e2d4cc Compare April 25, 2022 15:29
@keisku keisku marked this pull request as ready for review April 25, 2022 15:30
@keisku keisku changed the title [exporter/datadog] Fail fast if API Key is invalid [exporter/datadog] Add api.fail_on_invalid_key to fail fast if API Key is invalid. Apr 25, 2022
@keisku keisku changed the title [exporter/datadog] Add api.fail_on_invalid_key to fail fast if API Key is invalid. [exporter/datadog] Add api.fail_on_invalid_key to fail fast if API Key is invalid Apr 25, 2022
@keisku keisku force-pushed the keisku/validate-api-key branch from 4e2d4cc to 14f929f Compare April 25, 2022 15:33
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

I don't know if a config option is appropriate here. If configuration is invalid, the component should always fail IMO. If an exporter cannot be started as configured, it should return the error in its newMetricsExporter function, for example.

@mx-psi
Copy link
Member

mx-psi commented Apr 27, 2022

I don't know if a config option is appropriate here. If configuration is invalid, the component should always fail IMO. If an exporter cannot be started as configured, it should return the error in its newMetricsExporter function, for example.

I agree in principle, but there is some internal hesitancy to failing to start by default because of a feature that may be added to Datadog in the future related to API keys, so I think we want it behind a flag, even if I agree this looks odd from the outside

exporter/datadogexporter/internal/utils/api.go Outdated Show resolved Hide resolved
exporter/datadogexporter/internal/utils/api.go Outdated Show resolved Hide resolved
exporter/datadogexporter/example/config.yaml Outdated Show resolved Hide resolved
exporter/datadogexporter/config/config.go Outdated Show resolved Hide resolved
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 doing this! My main comment is that instead of panicking with logger.Fatal, we should return an error. I left some other comments inline

@keisku keisku requested a review from mx-psi April 27, 2022 22:54
@keisku keisku force-pushed the keisku/validate-api-key branch from 3f1f106 to e3c8cf2 Compare April 27, 2022 23:13
@keisku keisku requested a review from mx-psi April 28, 2022 11:09
mx-psi
mx-psi previously approved these changes Apr 28, 2022
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 great, thanks for addressing the comments! 🙇 Just two tiny nits, after those are addressed I will wait for David to ACK my comment and then mark as ready to merge

exporter/datadogexporter/factory_test.go Outdated Show resolved Hide resolved
exporter/datadogexporter/factory_test.go Outdated Show resolved Hide resolved
@mx-psi mx-psi dismissed their stale review April 28, 2022 12:03

Lint is failing

@mx-psi
Copy link
Member

mx-psi commented Apr 28, 2022

It looks like you also need to address some lint errors: https://github.com/open-telemetry/opentelemetry-collector-contrib/runs/6209762394?check_suite_focus=true

@keisku keisku requested a review from mx-psi April 28, 2022 13:57
@codeboten
Copy link
Contributor

Closing and re-opening PR to trigger the gotidy CI check

@codeboten codeboten closed this May 4, 2022
@codeboten codeboten reopened this May 4, 2022
@mx-psi
Copy link
Member

mx-psi commented May 5, 2022

Looks like it passed now

@codeboten codeboten merged commit 1d6b6fb into open-telemetry:main May 5, 2022
@@ -198,6 +198,7 @@ func (f *factory) createTracesExporter(
}

ctx, cancel := context.WithCancel(ctx)
defer cancel()
Copy link
Member

Choose a reason for hiding this comment

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

Actually this cancels the exporter prematurely after the function exits. The cancel is only meant to be called on shutdown (it is part of shutdown, so technically it does get called on all paths).

Copy link
Member

Choose a reason for hiding this comment

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

(it is part of shutdown, so technically it does get called on all paths).

the lint was failing because it was not called when the traces exporter fails to get created. I opened #9797 to fix this, thanks for spotting that!

djaglowski pushed a commit to djaglowski/opentelemetry-collector-contrib that referenced this pull request May 10, 2022
…Key is invalid (open-telemetry#9426)

* add new `fail_on_invalid_key` option

* improve the description of fail_on_invalid_key

* avoid failing when a transient network error

* remove unnecessary comment

* utils.ValidateAPI() returns error

* add tests

* not returning error when api failure

* fix test names

* fix lint

* fix go vet: prevent possible context leak

Co-authored-by: Alex Boten <[email protected]>
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.

[exporter/datadog] datadog exporter should fail fast if api key validation fail
6 participants