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

[cleanup] rm v2 from function names in metrics forwarder #1313

Merged
merged 1 commit into from
Jul 24, 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
20 changes: 10 additions & 10 deletions pkg/controller/utils/datadog/metrics_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ func (mf *metricsForwarder) setStatus(newStatus *ConditionCommon) {
mf.status = newStatus
}

func (mf *metricsForwarder) setupV2() error {
func (mf *metricsForwarder) setup() error {
// get dda
dda, err := mf.getDatadogAgentV2()
dda, err := mf.getDatadogAgent()
if err != nil {
mf.logger.Error(err, "cannot retrieve DatadogAgent to get Datadog credentials, will retry later...")
return err
}

mf.baseURL = getbaseURLV2(dda)
mf.baseURL = getbaseURL(dda)
mf.logger.V(1).Info("Got API URL for DatadogAgent", "site", mf.baseURL)

if dda.Spec.Global != nil && dda.Spec.Global.ClusterName != nil {
Expand All @@ -258,7 +258,7 @@ func (mf *metricsForwarder) setupV2() error {
mf.ccrStatus = status.ClusterChecksRunner

// set apiKey
apiKey, err := mf.getCredentialsV2(dda)
apiKey, err := mf.getCredentials(dda)
if err != nil {
return err
}
Expand All @@ -270,7 +270,7 @@ func (mf *metricsForwarder) setupV2() error {
// implements wait.ConditionFunc and never returns error to keep retrying
func (mf *metricsForwarder) connectToDatadogAPI() (bool, error) {
var err error
err = mf.setupV2()
err = mf.setup()

defer mf.updateStatusIfNeeded(err)
if err != nil {
Expand All @@ -291,7 +291,7 @@ func (mf *metricsForwarder) connectToDatadogAPI() (bool, error) {
// related to Datadog metrics forwarding by calling updateStatusIfNeeded
func (mf *metricsForwarder) forwardMetrics() error {
var err error
err = mf.setupV2()
err = mf.setup()

defer mf.updateStatusIfNeeded(err)
if err != nil {
Expand Down Expand Up @@ -557,15 +557,15 @@ func (mf *metricsForwarder) initGlobalTags() {
}

// getDatadogAgent retrieves the DatadogAgent using Get client method
func (mf *metricsForwarder) getDatadogAgentV2() (*v2alpha1.DatadogAgent, error) {
func (mf *metricsForwarder) getDatadogAgent() (*v2alpha1.DatadogAgent, error) {
dda := &v2alpha1.DatadogAgent{}
err := mf.k8sClient.Get(context.TODO(), mf.namespacedName, dda)

return dda, err
}

// getCredentialsV2 retrieves the api key configured in the DatadogAgent
func (mf *metricsForwarder) getCredentialsV2(dda *v2alpha1.DatadogAgent) (string, error) {
// getCredentials retrieves the api key configured in the DatadogAgent
func (mf *metricsForwarder) getCredentials(dda *v2alpha1.DatadogAgent) (string, error) {
if dda.Spec.Global == nil || dda.Spec.Global.Credentials == nil {
return "", fmt.Errorf("credentials not configured in the DatadogAgent")
}
Expand Down Expand Up @@ -757,7 +757,7 @@ func (mf *metricsForwarder) isEventChanFull() bool {
return len(mf.eventChan) == cap(mf.eventChan)
}

func getbaseURLV2(dda *v2alpha1.DatadogAgent) string {
func getbaseURL(dda *v2alpha1.DatadogAgent) string {
if dda.Spec.Global != nil && dda.Spec.Global.Endpoint != nil && dda.Spec.Global.Endpoint.URL != nil {
return *dda.Spec.Global.Endpoint.URL
} else if dda.Spec.Global != nil && dda.Spec.Global.Site != nil && *dda.Spec.Global.Site != "" {
Expand Down
34 changes: 17 additions & 17 deletions pkg/controller/utils/datadog/metrics_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
datadoghqv2alpha1 "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
testV2 "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1/test"
test "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1/test"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/pkg/kubernetes"
"github.com/DataDog/datadog-operator/pkg/secrets"
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestMetricsForwarder_updateCredsIfNeeded(t *testing.T) {
}
}

func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
func TestReconcileDatadogAgent_getCredentials(t *testing.T) {
apiKey := "foundAPIKey"

encAPIKey := "ENC[APIKey]"
Expand All @@ -177,7 +177,7 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
client: fake.NewFakeClient(),
},
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Credentials: &datadoghqv2alpha1.DatadogCredentials{
APIKey: apiutils.NewStringPointer(apiKey),
},
Expand All @@ -192,7 +192,7 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
client: fake.NewFakeClient(),
},
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Credentials: &datadoghqv2alpha1.DatadogCredentials{
APISecret: &commonv1.SecretConfig{
SecretName: "datadog-creds-api",
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
client: fake.NewFakeClient(),
},
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Credentials: &datadoghqv2alpha1.DatadogCredentials{
APIKey: apiutils.NewStringPointer(encAPIKey),
},
Expand All @@ -248,7 +248,7 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
client: fake.NewFakeClient(),
},
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Credentials: &datadoghqv2alpha1.DatadogCredentials{
APIKey: apiutils.NewStringPointer(encAPIKey),
},
Expand All @@ -275,7 +275,7 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
client: fake.NewFakeClient(),
},
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{}),
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{}),
},
wantErr: true,
},
Expand All @@ -291,17 +291,17 @@ func TestReconcileDatadogAgent_getCredentialsV2(t *testing.T) {
if tt.args.loadFunc != nil {
tt.args.loadFunc(mf, d)
}
apiKey, err := mf.getCredentialsV2(tt.args.dda)
apiKey, err := mf.getCredentials(tt.args.dda)
if (err != nil) != tt.wantErr {
t.Errorf("metricsForwarder.getCredentialsV2() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("metricsForwarder.getCredentials() error = %v, wantErr %v", err, tt.wantErr)
return
}
if apiKey != tt.wantAPIKey {
t.Errorf("metricsForwarder.getCredentialsV2() apiKey = %v, want %v", apiKey, tt.wantAPIKey)
t.Errorf("metricsForwarder.getCredentials() apiKey = %v, want %v", apiKey, tt.wantAPIKey)
}
if tt.wantFunc != nil {
if err := tt.wantFunc(mf, d); err != nil {
t.Errorf("metricsForwarder.getCredentialsV2() wantFunc validation error: %v", err)
t.Errorf("metricsForwarder.getCredentials() wantFunc validation error: %v", err)
}
}
})
Expand Down Expand Up @@ -654,7 +654,7 @@ func Test_metricsForwarder_getSecretsFromCache(t *testing.T) {
}
}

func Test_getbaseURLV2(t *testing.T) {
func Test_getbaseURL(t *testing.T) {
euSite := "datadoghq.eu"

type args struct {
Expand All @@ -668,14 +668,14 @@ func Test_getbaseURLV2(t *testing.T) {
{
name: "Get default baseURL",
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", nil),
dda: test.NewDatadogAgent("foo", "bar", nil),
},
want: "https://api.datadoghq.com",
},
{
name: "Compute baseURL from site when passing Site",
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Site: &euSite,
}),
},
Expand All @@ -684,7 +684,7 @@ func Test_getbaseURLV2(t *testing.T) {
{
name: "Compute baseURL from endpoint.URL when Site is not defined",
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Endpoint: &datadoghqv2alpha1.Endpoint{
URL: apiutils.NewStringPointer("https://test.url.com"),
},
Expand All @@ -695,7 +695,7 @@ func Test_getbaseURLV2(t *testing.T) {
{
name: "Test that DDUrl takes precedence over Site",
args: args{
dda: testV2.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
dda: test.NewDatadogAgent("foo", "bar", &datadoghqv2alpha1.GlobalConfig{
Site: &euSite,
Endpoint: &datadoghqv2alpha1.Endpoint{
URL: apiutils.NewStringPointer("https://test.url.com"),
Expand All @@ -707,7 +707,7 @@ func Test_getbaseURLV2(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getbaseURLV2(tt.args.dda); got != tt.want {
if got := getbaseURL(tt.args.dda); got != tt.want {
t.Errorf("getbaseURL() = %v, want %v", got, tt.want)
}
})
Expand Down
Loading