Skip to content

Commit

Permalink
Merge branch 'main' into khewonc/introspection-docs-update
Browse files Browse the repository at this point in the history
  • Loading branch information
khewonc committed Mar 28, 2024
2 parents 56b9859 + 7db14b9 commit bff96a0
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $(KUSTOMIZE): Makefile ## Download kustomize locally if necessary.

ENVTEST = bin/$(PLATFORM)/setup-envtest
$(ENVTEST): Makefile ## Download envtest-setup locally if necessary.
$(call go-get-tool,$@,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(call go-get-tool,$@,sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20240320141353-395cfc7486e6)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
10 changes: 10 additions & 0 deletions apis/datadoghq/v1alpha1/datadogmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type DatadogMonitorOptions struct {
EvaluationDelay *int64 `json:"evaluationDelay,omitempty"`
// A Boolean indicating whether notifications from this monitor automatically inserts its triggering tags into the title.
IncludeTags *bool `json:"includeTags,omitempty"`
// A Boolean indicating whether the log alert monitor triggers a single alert or multiple alerts when any group breaches a threshold.
GroupbySimpleMonitor *bool `json:"groupbySimpleMonitor,omitempty"`
// Whether or not the monitor is locked (only editable by creator and admins).
Locked *bool `json:"locked,omitempty"`
// Time (in seconds) to allow a host to boot and applications to fully start before starting the evaluation of
Expand All @@ -104,6 +106,12 @@ type DatadogMonitorOptions struct {
NotificationPresetName DatadogMonitorOptionsNotificationPreset `json:"notificationPresetName,omitempty"`
// A Boolean indicating whether tagged users are notified on changes to this monitor.
NotifyAudit *bool `json:"notifyAudit,omitempty"`
// A string indicating the granularity a monitor alerts on. Only available for monitors with groupings.
// For instance, a monitor grouped by cluster, namespace, and pod can be configured to only notify on each new
// cluster violating the alert conditions by setting notify_by to ["cluster"]. Tags mentioned in notify_by must
// be a subset of the grouping tags in the query. For example, a query grouped by cluster and namespace cannot
// notify on region. Setting notify_by to [*] configures the monitor to notify as a simple-alert.
NotifyBy []string `json:"notifyBy,omitempty"`
// A Boolean indicating whether this monitor notifies when data stops reporting.
NotifyNoData *bool `json:"notifyNoData,omitempty"`
// An enum that controls how groups or monitors are treated if an evaluation does not return data points.
Expand All @@ -115,6 +123,8 @@ type DatadogMonitorOptions struct {
// The number of minutes after the last notification before a monitor re-notifies on the current status.
// It only re-notifies if it’s not resolved.
RenotifyInterval *int64 `json:"renotifyInterval,omitempty"`
// The number of times re-notification messages should be sent on the current status at the provided re-notification interval.
RenotifyOccurrences *int64 `json:"renotifyOccurrences,omitempty"`
// A Boolean indicating whether this monitor needs a full window of data before it’s evaluated. We highly
// recommend you set this to false for sparse metrics, otherwise some evaluations are skipped. Default is false.
RequireFullWindow *bool `json:"requireFullWindow,omitempty"`
Expand Down
15 changes: 15 additions & 0 deletions apis/datadoghq/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions apis/datadoghq/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ spec:
description: Time (in seconds) to delay evaluation, as a non-negative integer. For example, if the value is set to 300 (5min), the timeframe is set to last_5m and the time is 7:00, the monitor evaluates data from 6:50 to 6:55. This is useful for AWS CloudWatch and other backfilled metrics to ensure the monitor always has data during evaluation.
format: int64
type: integer
groupbySimpleMonitor:
description: A Boolean indicating whether the log alert monitor triggers a single alert or multiple alerts when any group breaches a threshold.
type: boolean
includeTags:
description: A Boolean indicating whether notifications from this monitor automatically inserts its triggering tags into the title.
type: boolean
Expand All @@ -98,6 +101,11 @@ spec:
notifyAudit:
description: A Boolean indicating whether tagged users are notified on changes to this monitor.
type: boolean
notifyBy:
description: A string indicating the granularity a monitor alerts on. Only available for monitors with groupings. For instance, a monitor grouped by cluster, namespace, and pod can be configured to only notify on each new cluster violating the alert conditions by setting notify_by to ["cluster"]. Tags mentioned in notify_by must be a subset of the grouping tags in the query. For example, a query grouped by cluster and namespace cannot notify on region. Setting notify_by to [*] configures the monitor to notify as a simple-alert.
items:
type: string
type: array
notifyNoData:
description: A Boolean indicating whether this monitor notifies when data stops reporting.
type: boolean
Expand All @@ -108,6 +116,10 @@ spec:
description: The number of minutes after the last notification before a monitor re-notifies on the current status. It only re-notifies if it’s not resolved.
format: int64
type: integer
renotifyOccurrences:
description: The number of times re-notification messages should be sent on the current status at the provided re-notification interval.
format: int64
type: integer
requireFullWindow:
description: A Boolean indicating whether this monitor needs a full window of data before it’s evaluated. We highly recommend you set this to false for sparse metrics, otherwise some evaluations are skipped. Default is false.
type: boolean
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/v1beta1/datadoghq.com_datadogmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
description: Time (in seconds) to delay evaluation, as a non-negative integer. For example, if the value is set to 300 (5min), the timeframe is set to last_5m and the time is 7:00, the monitor evaluates data from 6:50 to 6:55. This is useful for AWS CloudWatch and other backfilled metrics to ensure the monitor always has data during evaluation.
format: int64
type: integer
groupbySimpleMonitor:
description: A Boolean indicating whether the log alert monitor triggers a single alert or multiple alerts when any group breaches a threshold.
type: boolean
includeTags:
description: A Boolean indicating whether notifications from this monitor automatically inserts its triggering tags into the title.
type: boolean
Expand All @@ -99,6 +102,11 @@ spec:
notifyAudit:
description: A Boolean indicating whether tagged users are notified on changes to this monitor.
type: boolean
notifyBy:
description: A string indicating the granularity a monitor alerts on. Only available for monitors with groupings. For instance, a monitor grouped by cluster, namespace, and pod can be configured to only notify on each new cluster violating the alert conditions by setting notify_by to ["cluster"]. Tags mentioned in notify_by must be a subset of the grouping tags in the query. For example, a query grouped by cluster and namespace cannot notify on region. Setting notify_by to [*] configures the monitor to notify as a simple-alert.
items:
type: string
type: array
notifyNoData:
description: A Boolean indicating whether this monitor notifies when data stops reporting.
type: boolean
Expand All @@ -109,6 +117,10 @@ spec:
description: The number of minutes after the last notification before a monitor re-notifies on the current status. It only re-notifies if it’s not resolved.
format: int64
type: integer
renotifyOccurrences:
description: The number of times re-notification messages should be sent on the current status at the provided re-notification interval.
format: int64
type: integer
requireFullWindow:
description: A Boolean indicating whether this monitor needs a full window of data before it’s evaluated. We highly recommend you set this to false for sparse metrics, otherwise some evaluations are skipped. Default is false.
type: boolean
Expand Down
23 changes: 21 additions & 2 deletions controllers/datadogagent/feature/orchestratorexplorer/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/pkg/controller/utils/comparison"
"github.com/DataDog/datadog-operator/pkg/kubernetes"
"github.com/DataDog/datadog-operator/pkg/utils"
"github.com/go-logr/logr"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
common "github.com/DataDog/datadog-operator/controllers/datadogagent/common"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/volume"
Expand Down Expand Up @@ -60,8 +62,12 @@ type orchestratorExplorerFeature struct {
logger logr.Logger
customConfigAnnotationKey string
customConfigAnnotationValue string

processAgentRequired bool
}

const NoProcessAgentMinVersion = "7.51.0"

// ID returns the ID of the Feature
func (f *orchestratorExplorerFeature) ID() feature.IDType {
return feature.OrchestratorExplorerIDType
Expand All @@ -74,9 +80,19 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req

if orchestratorExplorer != nil && apiutils.BoolValue(orchestratorExplorer.Enabled) {
reqComp.ClusterAgent.IsRequired = apiutils.NewBoolPointer(true)
reqContainers := []apicommonv1.AgentContainerName{apicommonv1.CoreAgentContainerName}

// Process Agent is not required as of agent version 7.51.0
if nodeAgent, ok := dda.Spec.Override[v2alpha1.NodeAgentComponentName]; ok {
if nodeAgent.Image != nil && !utils.IsAboveMinVersion(component.GetAgentVersionFromImage(*nodeAgent.Image), NoProcessAgentMinVersion) {
f.processAgentRequired = true
reqContainers = append(reqContainers, apicommonv1.ProcessAgentContainerName)
}
}

reqComp.Agent = feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommonv1.AgentContainerName{apicommonv1.CoreAgentContainerName, apicommonv1.ProcessAgentContainerName},
Containers: reqContainers,
}

if orchestratorExplorer.Conf != nil {
Expand Down Expand Up @@ -116,6 +132,7 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req
func (f *orchestratorExplorerFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) (reqComp feature.RequiredComponents) {
f.owner = dda
orchestratorExplorer := dda.Spec.Features.OrchestratorExplorer
f.processAgentRequired = true

if orchestratorExplorer != nil && apiutils.BoolValue(orchestratorExplorer.Enabled) {
reqComp.ClusterAgent.IsRequired = apiutils.NewBoolPointer(true)
Expand Down Expand Up @@ -231,7 +248,9 @@ func (f *orchestratorExplorerFeature) ManageSingleContainerNodeAgent(managers fe
// It should do nothing if the feature doesn't need to configure it.
func (f *orchestratorExplorerFeature) ManageNodeAgent(managers feature.PodTemplateManagers, provider string) error {
for _, env := range f.getEnvVars() {
managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, env)
if f.processAgentRequired {
managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, env)
}
managers.EnvVar().AddEnvVarToContainer(apicommonv1.CoreAgentContainerName, env)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
v2alpha1test "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1/test"

apiutils "github.com/DataDog/datadog-operator/apis/utils"
Expand Down Expand Up @@ -67,10 +68,11 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) {
WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}).
WithOrchestratorExplorerDDUrl("https://foo.bar").
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.51.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentNoProcessAgentWantFunc),
},
{
Name: "v2alpha1 orchestrator explorer enabled and runs on cluster checks runner",
Expand All @@ -82,12 +84,27 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) {
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithClusterChecksEnabled(true).
WithClusterChecksUseCLCEnabled(true).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.51.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentNoProcessAgentWantFunc),
ClusterChecksRunner: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerClusterChecksRunnerWantFunc),
},
{
Name: "v2alpha1 orchestrator explorer enabled on version requiring process agent",
DDAv2: v2alpha1test.NewDatadogAgentBuilder().
WithOrchestratorExplorerEnabled(true).
WithOrchestratorExplorerScrubContainers(true).
WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}).
WithOrchestratorExplorerDDUrl("https://foo.bar").
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.50.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
},
}

tests.Run(t, buildOrchestratorExplorerFeature)
Expand All @@ -97,6 +114,16 @@ func orchestratorExplorerNodeAgentWantFunc(t testing.TB, mgrInterface feature.Po
mgr := mgrInterface.(*fake.PodTemplateManagers)
agentEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommonv1.ProcessAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Process agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
agentEnvVars = mgr.EnvVarMgr.EnvVarsByC[apicommonv1.CoreAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Core agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
}

func orchestratorExplorerNodeAgentNoProcessAgentWantFunc(t testing.TB, mgrInterface feature.PodTemplateManagers) {
mgr := mgrInterface.(*fake.PodTemplateManagers)
agentEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommonv1.ProcessAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, nil), "Process agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
agentEnvVars = mgr.EnvVarMgr.EnvVarsByC[apicommonv1.CoreAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Core agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
}

func orchestratorExplorerClusterChecksRunnerWantFunc(t testing.TB, mgrInterface feature.PodTemplateManagers) {
Expand Down
Loading

0 comments on commit bff96a0

Please sign in to comment.