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

Remove unused credentials from AzureMonitorMetricsReceiver #18

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions azure_monitor_metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ type AzureMonitorMetricsReceiver struct {
AzureClients *AzureClients

subscriptionID string
clientID string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all these creds were stored in struct field, but not used

clientSecret string
tenantID string
}

// Targets contains all targets types.
Expand Down Expand Up @@ -83,14 +80,11 @@ type MetricsClient interface {
}

// NewAzureMonitorMetricsReceiver lets you create a new receiver.
func NewAzureMonitorMetricsReceiver(subscriptionID string, clientID string, clientSecret string, tenantID string, targets *Targets, azureClients *AzureClients) (*AzureMonitorMetricsReceiver, error) {
func NewAzureMonitorMetricsReceiver(subscriptionID string, _, _, _ string, targets *Targets, azureClients *AzureClients) (*AzureMonitorMetricsReceiver, error) {
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 didn't want to change exported function signature to avoid semver bump

azureMonitorMetricsReceiver := &AzureMonitorMetricsReceiver{
Targets: targets,
AzureClients: azureClients,
subscriptionID: subscriptionID,
clientID: clientID,
clientSecret: clientSecret,
tenantID: tenantID,
}

if err := azureMonitorMetricsReceiver.checkValidation(); err != nil {
Expand Down
33 changes: 0 additions & 33 deletions collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ func TestCollectResourceTargetMetrics_AllDataWithValues(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

metrics, notCollectedMetrics, err := ammr.CollectResourceTargetMetrics(ammr.Targets.ResourceTargets[0])
Expand Down Expand Up @@ -81,9 +78,6 @@ func TestCollectResourceTargetMetrics_LastDataWithNoValue(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

metrics, notCollectedMetrics, err := ammr.CollectResourceTargetMetrics(ammr.Targets.ResourceTargets[0])
Expand Down Expand Up @@ -126,9 +120,6 @@ func TestCollectResourceTargetMetrics_AllDataWithNoValues(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

metrics, notCollectedMetrics, err := ammr.CollectResourceTargetMetrics(ammr.Targets.ResourceTargets[0])
Expand All @@ -151,9 +142,6 @@ func TestCollectResourceTargetMetrics_EmptyData(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

metrics, notCollectedMetrics, err := ammr.CollectResourceTargetMetrics(ammr.Targets.ResourceTargets[0])
Expand All @@ -176,9 +164,6 @@ func TestCollectResourceTargetMetrics_EmptyTimeseries(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

metrics, notCollectedMetrics, err := ammr.CollectResourceTargetMetrics(ammr.Targets.ResourceTargets[0])
Expand All @@ -201,9 +186,6 @@ func TestGetMetricName_Success(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand All @@ -227,9 +209,6 @@ func TestGetMetricFields_AllTimeseriesWithData(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand All @@ -256,9 +235,6 @@ func TestGetMetricFields_LastTimeseriesWithoutData(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand All @@ -285,9 +261,6 @@ func TestGetMetricFields_AllTimeseriesWithoutData(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand All @@ -308,9 +281,6 @@ func TestGetMetricFields_NoTimeseriesData(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand All @@ -331,9 +301,6 @@ func TestGetMetricTags_Success(t *testing.T) {
),
AzureClients: setMockAzureClients(),
subscriptionID: testSubscriptionID,
clientID: testClientID,
clientSecret: testClientSecret,
tenantID: testTenantID,
}

response, err := ammr.AzureClients.MetricsClient.List(ammr.AzureClients.Ctx, ammr.Targets.ResourceTargets[0].ResourceID, nil)
Expand Down
12 changes: 0 additions & 12 deletions initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ func (ammr *AzureMonitorMetricsReceiver) checkValidation() error {
return fmt.Errorf("subscription ID is empty or missing")
}

if ammr.clientID == "" {
return fmt.Errorf("client ID is empty or missing")
}

if ammr.clientSecret == "" {
return fmt.Errorf("client secret is empty or missing")
}

if ammr.tenantID == "" {
return fmt.Errorf("tenant ID is empty or missing")
}

if len(ammr.Targets.ResourceTargets) == 0 && len(ammr.Targets.resourceGroupTargets) == 0 && len(ammr.Targets.subscriptionTargets) == 0 {
return fmt.Errorf("no target to collect metrics from")
}
Expand Down
Loading
Loading