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

Add registerAPIService option to external metrics feature to allow disabling external metrics endpoint registration #953

Conversation

adel121
Copy link
Contributor

@adel121 adel121 commented Oct 19, 2023

What does this PR do?

This PR allows the user to enable creating an external metrics server while still disabling registering the external metrics server as an APIService.

It allows this by adding the option registerAPIService to the externalMetrics feature to allow the user to disable registering external-metrics server as an APIService

Motivation

This allows the user to use other external-metrics providers (such as KEDA) in the cluster, but also use the datadog cluster-agent as a metrics proxy to datadog.

Additional Notes

registerAPIService is defaulted to true in externalMetrics feature for backward compatibility. By default we register the endpoint if the user enables external metrics server.

Describe your test plan

We can test this by deploying the agent using the operator on a kind cluster locally.

Steps:

  • Build and deploy the operator as described here:
    • Build the operator image make IMG=test/operator:test docker-build
    • Load the image into kind : kind load docker-image test/operator:test
    • Deploy the operator: make IMG=test/operator:test deploy
  • Deploy the agent and cluster agent as described here
    • Instead of using the Datadog definition in examples/datadogagent/v2alpha1/min.yaml by the following definition
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
  name: datadog
spec:
  features:
    externalMetricsServer:
      enabled: true
      useDatadogMetrics: false
      registerAPIService: true
  global:
    credentials:
      apiSecret:
        secretName: datadog-secret
        keyName: api-key
      appSecret:
        secretName: datadog-secret
        keyName: app-key
  override:
    clusterAgent:
      replicas: 2
    nodeAgent:
      tolerations:
        - operator: Exists
  • Check if the endpoint is registered or not by running kubectl get apiservices.apiregistration.k8s.io | grep external . It should produce an empty output if the endpoint is not registered. If it is registered, the output should show the endpoint name with status being True (Example: v1beta1.external.metrics.k8s.io system/datadog-cluster-agent-metrics-server True 12s )

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label

…user to disable external metrics registration
@adel121 adel121 added the enhancement New feature or request label Oct 19, 2023
@adel121 adel121 added this to the v1.3.0 milestone Oct 19, 2023
@adel121 adel121 requested review from a team as code owners October 19, 2023 15:34
@adel121 adel121 force-pushed the adelhajhassan/allow_disabling_external_metrics_endpoint_registration branch 2 times, most recently from cdd11ec to 88041cc Compare October 19, 2023 15:51
@adel121 adel121 force-pushed the adelhajhassan/allow_disabling_external_metrics_endpoint_registration branch from 88041cc to 8d7661c Compare October 19, 2023 15:54
@adel121 adel121 changed the title Add registerEndpoint option to external metrics feature to allow disabling external metrics endpoint registration Add registerAPIService option to external metrics feature to allow disabling external metrics endpoint registration Oct 19, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2023

Codecov Report

Merging #953 (9bb568a) into main (00979d6) will increase coverage by 0.01%.
The diff coverage is 59.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #953      +/-   ##
==========================================
+ Coverage   56.82%   56.83%   +0.01%     
==========================================
  Files         155      155              
  Lines       19279    19284       +5     
==========================================
+ Hits        10956    10961       +5     
  Misses       7675     7675              
  Partials      648      648              
Flag Coverage Δ
unittests 56.83% <59.45%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
apis/datadoghq/v2alpha1/datadogagent_default.go 87.42% <100.00%> (ø)
apis/datadoghq/v2alpha1/datadogagent_types.go 100.00% <ø> (ø)
...rs/datadogagent/feature/externalmetrics/feature.go 42.15% <58.33%> (+0.96%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00979d6...9bb568a. Read the comment docs.

Copy link
Contributor

@levan-m levan-m left a comment

Choose a reason for hiding this comment

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

Thanks for comprehensive test plan in PR description.

DDAv2: newV2Agent(true, true, false, secretV2),
DDAv2: newV2Agent(true, true, true, false, secretV2),
WantConfigure: true,
ClusterAgent: testDCAResources(true, false, true),
Copy link
Contributor

Choose a reason for hiding this comment

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

This and next test pass different values for registerAPIService but make same assertions usingtestDCAResources(true, false, true) which means testDCAResources is probably not covering resources what's inside if f.registerAPIService {... Could you please fix that?

@@ -535,6 +535,11 @@ type ExternalMetricsServerFeatureConfig struct {
// +optional
Enabled *bool `json:"enabled,omitempty"`

// RegisterAPIService registers the External Metrics endpoint as an APIService
// Default: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add default value to datadogagent_default.go and set it in the same file, see this example.

@@ -19,33 +19,33 @@ import (

func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"./apis/datadoghq/v2alpha1.CSPMHostBenchmarksConfig": schema__apis_datadoghq_v2alpha1_CSPMHostBenchmarksConfig(ref),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you check this please as well, diff shouldn't be this big. It also causes CI failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is automatically generated by running make generate manifests

For some reason, if $GOPATH is set, it results in a huge diff.

Setting $GOPATH to "/tmp" temporarily fixes the issue.

I am not sure why this is the case.

@adel121 adel121 requested a review from levan-m October 20, 2023 14:06
Name: "v2alpha1 external metrics enabled, secrets set, registerAPIService enabled",
DDAv2: newV2Agent(true, true, true, false, secretV2),
WantConfigure: true,
WantDependenciesFunc: func(t testing.TB, store dependencies.StoreClient) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for improving the test!

@adel121 adel121 merged commit 2e0fcc8 into main Oct 24, 2023
19 checks passed
@adel121 adel121 deleted the adelhajhassan/allow_disabling_external_metrics_endpoint_registration branch October 24, 2023 08:07
mftoure pushed a commit that referenced this pull request Oct 3, 2024
…sabling external metrics endpoint registration (#953)

* Add registerEndpoint option to external metrics feature to allow the user to disable external metrics registration

* generate manifests

* Rename field to registerAPIService

* fix generate manifests

* Add defaultRegisterAPIService in datadogagent_default.go

* Add unit tests for external metrics feature and for RegisterAPIService default value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants