Skip to content

Commit

Permalink
Merge branch 'azm-no-secret' of https://github.com/redbaron/azure-mon…
Browse files Browse the repository at this point in the history
…itor-metrics-receiver into redbaron-azm-no-secret
  • Loading branch information
8naama committed Jul 22, 2024
2 parents 5b1dbc3 + 92c3e32 commit 0a65016
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 190 deletions.
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
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) {
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 @@ -72,18 +72,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

0 comments on commit 0a65016

Please sign in to comment.