-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[receiver/azuremonitor] Add support for azureauthextension #39658
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
[receiver/azuremonitor] Add support for azureauthextension #39658
Conversation
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.
Thank you for that effort! I will later probably remove the old one but that's ok to have both for a while.
I let you rule the red pipeline and answer my different comments.
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azuremonitorreceiver/internal/metadata" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { |
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.
Thanks for that! So cool to see some tests of this quality for the config :)
@@ -23,7 +23,9 @@ The following settings are required: | |||
|
|||
The following settings are optional: | |||
|
|||
- `auth` (default = service_principal): Specifies the used authentication method. Supported values are `service_principal`, `workload_identity`, `managed_identity`, `default_credentials`. | |||
- `token_provider` or `auth` (default = service_principal): Specifies the used authentication method: |
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.
I think it can be clearer if you keep token_provider and auth separated bullet points. You can have a little duplication here no problem as I think I will remove auth later on.
Can you also put a deprecated flag on the auth one?
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.
Yes, I have added it in the README, and also added a warning in the code:
s.settings.Logger.Warn("'auth' is deprecated, use 'credentials' instead") |
receivers: | ||
azuremonitor: | ||
subscription_ids: ["${subscription_id}"] | ||
token_provider: azureauth |
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.
I'm not sure that token_provider is the right term knowing that it does not generate token behind the scene. If you put that in others component though, I'm ok to keep same for consistency.
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.
So far it is not use in any other components. Do you have a field name that you prefer?
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.
I have changed to credentials
. Is it better?
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.
I'm discovering a bit, but it looks like there is a recurring pattern.
auth:
authenticator: <name of the extension>
There is a common structure for this in the collector https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configauth/configauth.go, it's used for all authentications.
That said this structure is dedicated to create http/grpc clients so what I would propose would be to create something like this:
- In the azure auth extension, copy this structure, with the same logic, and with a getter to obtain the creds.
// Authentication defines the auth settings for the azure receiver.
type Authentication struct {
// AuthenticatorID specifies the name of the azure extension to use in order to authenticate the incoming data point.
AuthenticatorID component.ID `mapstructure:"authenticator,omitempty"`
}
// GetAzureTokenCredential attempts to select the credential of the appropriate azure extension from the list of extensions,
// based on the requested extension name. If an authenticator is not found, an error is returned.
func (a Authentication) GetAzureTokenCredential(_ context.Context, extensions map[component.ID]component.Component) (*azcore.TokenCredential, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if cred, ok := ext.(azcore.TokenCredential); ok {
return &cred, nil
}
return nil, errNotServer
}
return nil, fmt.Errorf("failed to resolve authenticator %q: %w", a.AuthenticatorID, errAuthenticatorNotFound)
}
- In the azure monitor receiver, add a field in config with that type, with a
azureauth
name (to avoid breaking change and it tells well what it is)
azureauth:
authenticator: azureauth/prd
WDYT?
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 azureauth
extension has the support for authenticator
if the receiver requires client/server config (see this).
For this receiver, we actually need to use azcore.TokenCredential
, which then implements this function.
So the easiest way would be to just replace the name credentials
with authenticator
in the receiver config (here). But I don't know if authenticator
would be the best name, as we are not really using it as a client/server. Especially with authenticator
being out of auth
, which as you pointed out, is the common schema.
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.
Renaming could work, thanks!
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.
I'm on it
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.
Here it is #39738
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.
They already merged it <3
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.
Thanks @celian-garcia . I updated the PR now to use auth.authenticator
.
… azuremonitor-authextension
…als` (#39738) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Doing this breaking change to prepare usage of azure auth extension and be able to set the auth config like it's usually done for the different authentication by extensions ```yaml auth: authenticator: 'azureauth/prd' ``` <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Unblocks #39658 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Célian Garcia <[email protected]>
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.
Great! just some nits and we should be good!
Thank you @constanca-m, I can't wait to remove all that crap 😈
@@ -242,11 +243,6 @@ type Config struct { | |||
Cloud string `mapstructure:"cloud"` | |||
SubscriptionIDs []string `mapstructure:"subscription_ids"` | |||
DiscoverSubscriptions bool `mapstructure:"discover_subscriptions"` | |||
Credentials string `mapstructure:"credentials"` | |||
TenantID string `mapstructure:"tenant_id"` |
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.
Can you keep just TenantID at this place? Just a nit but this will be clearer when we'll remove the deprecated part
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.
Of course
Co-authored-by: Célian GARCIA <[email protected]>
Please resolve conflicts and mark ready for review again. |
… azuremonitor-authextension # Conflicts: # receiver/azuremonitorreceiver/go.mod # receiver/azuremonitorreceiver/go.sum
…metry#39658) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for extension `azureauth` for authentication. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#39048. <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests added. <!--Describe the documentation added.--> #### Documentation README updated. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Célian GARCIA <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
…als` (open-telemetry#39738) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Doing this breaking change to prepare usage of azure auth extension and be able to set the auth config like it's usually done for the different authentication by extensions ```yaml auth: authenticator: 'azureauth/prd' ``` <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Unblocks open-telemetry#39658 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Célian Garcia <[email protected]>
…metry#39658) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for extension `azureauth` for authentication. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#39048. <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests added. <!--Describe the documentation added.--> #### Documentation README updated. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Célian GARCIA <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
…metry#39658) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for extension `azureauth` for authentication. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#39048. <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests added. <!--Describe the documentation added.--> #### Documentation README updated. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Célian GARCIA <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
…metry#39658) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for extension `azureauth` for authentication. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#39048. <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests added. <!--Describe the documentation added.--> #### Documentation README updated. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Célian GARCIA <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
…metry#39658) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for extension `azureauth` for authentication. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#39048. <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests added. <!--Describe the documentation added.--> #### Documentation README updated. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Célian GARCIA <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
Description
Add support for extension
azureauth
for authentication.Link to tracking issue
Fixes #39048.
Testing
Unit tests added.
Documentation
README updated.