Azure SD: Set Prometheus user agent (#10209)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
d53324825b
commit
18d737de3e
|
@ -32,6 +32,7 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
config_util "github.com/prometheus/common/config"
|
config_util "github.com/prometheus/common/config"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
"github.com/prometheus/common/version"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/discovery"
|
"github.com/prometheus/prometheus/discovery"
|
||||||
"github.com/prometheus/prometheus/discovery/refresh"
|
"github.com/prometheus/prometheus/discovery/refresh"
|
||||||
|
@ -58,14 +59,18 @@ const (
|
||||||
authMethodManagedIdentity = "ManagedIdentity"
|
authMethodManagedIdentity = "ManagedIdentity"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultSDConfig is the default Azure SD configuration.
|
var (
|
||||||
var DefaultSDConfig = SDConfig{
|
userAgent = fmt.Sprintf("Prometheus/%s", version.Version)
|
||||||
|
|
||||||
|
// DefaultSDConfig is the default Azure SD configuration.
|
||||||
|
DefaultSDConfig = SDConfig{
|
||||||
Port: 80,
|
Port: 80,
|
||||||
RefreshInterval: model.Duration(5 * time.Minute),
|
RefreshInterval: model.Duration(5 * time.Minute),
|
||||||
Environment: azure.PublicCloud.Name,
|
Environment: azure.PublicCloud.Name,
|
||||||
AuthenticationMethod: authMethodOAuth,
|
AuthenticationMethod: authMethodOAuth,
|
||||||
HTTPClientConfig: config_util.DefaultHTTPClientConfig,
|
HTTPClientConfig: config_util.DefaultHTTPClientConfig,
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
discovery.RegisterConfig(&SDConfig{})
|
discovery.RegisterConfig(&SDConfig{})
|
||||||
|
@ -208,24 +213,29 @@ func createAzureClient(cfg SDConfig) (azureClient, error) {
|
||||||
return azureClient{}, err
|
return azureClient{}, err
|
||||||
}
|
}
|
||||||
sender := autorest.DecorateSender(client)
|
sender := autorest.DecorateSender(client)
|
||||||
|
preparer := autorest.WithUserAgent(userAgent)
|
||||||
|
|
||||||
bearerAuthorizer := autorest.NewBearerAuthorizer(spt)
|
bearerAuthorizer := autorest.NewBearerAuthorizer(spt)
|
||||||
|
|
||||||
c.vm = compute.NewVirtualMachinesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
c.vm = compute.NewVirtualMachinesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
||||||
c.vm.Authorizer = bearerAuthorizer
|
c.vm.Authorizer = bearerAuthorizer
|
||||||
c.vm.Sender = sender
|
c.vm.Sender = sender
|
||||||
|
c.vm.RequestInspector = preparer
|
||||||
|
|
||||||
c.nic = network.NewInterfacesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
c.nic = network.NewInterfacesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
||||||
c.nic.Authorizer = bearerAuthorizer
|
c.nic.Authorizer = bearerAuthorizer
|
||||||
c.nic.Sender = sender
|
c.nic.Sender = sender
|
||||||
|
c.nic.RequestInspector = preparer
|
||||||
|
|
||||||
c.vmss = compute.NewVirtualMachineScaleSetsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
c.vmss = compute.NewVirtualMachineScaleSetsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
||||||
c.vmss.Authorizer = bearerAuthorizer
|
c.vmss.Authorizer = bearerAuthorizer
|
||||||
c.vm.Sender = sender
|
c.vmss.Sender = sender
|
||||||
|
c.vmss.RequestInspector = preparer
|
||||||
|
|
||||||
c.vmssvm = compute.NewVirtualMachineScaleSetVMsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
c.vmssvm = compute.NewVirtualMachineScaleSetVMsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID)
|
||||||
c.vmssvm.Authorizer = bearerAuthorizer
|
c.vmssvm.Authorizer = bearerAuthorizer
|
||||||
c.vmssvm.Sender = sender
|
c.vmssvm.Sender = sender
|
||||||
|
c.vmssvm.RequestInspector = preparer
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -537,7 +547,8 @@ func (client *azureClient) getNetworkInterfaceByID(ctx context.Context, networkI
|
||||||
autorest.AsGet(),
|
autorest.AsGet(),
|
||||||
autorest.WithBaseURL(client.nic.BaseURI),
|
autorest.WithBaseURL(client.nic.BaseURI),
|
||||||
autorest.WithPath(networkInterfaceID),
|
autorest.WithPath(networkInterfaceID),
|
||||||
autorest.WithQueryParameters(queryParameters))
|
autorest.WithQueryParameters(queryParameters),
|
||||||
|
autorest.WithUserAgent(userAgent))
|
||||||
req, err := preparer.Prepare((&http.Request{}).WithContext(ctx))
|
req, err := preparer.Prepare((&http.Request{}).WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, autorest.NewErrorWithError(err, "network.InterfacesClient", "Get", nil, "Failure preparing request")
|
return nil, autorest.NewErrorWithError(err, "network.InterfacesClient", "Get", nil, "Failure preparing request")
|
||||||
|
|
Loading…
Reference in New Issue