Skip to content

Commit

Permalink
Remove pkg/collector/check dependency from the pkg/aggregator (DataDo…
Browse files Browse the repository at this point in the history
…g#17929)

* Move check.ID to its own package

* Remove pkg/collector/check from pkg/aggregator
Move files: pkg/collector/check/stats.go -> pkg/collector/check/stats/stats.go
pkg/collector/check/stats_test.go -> pkg/collector/check/stats/stats_test.go
pkg/collector/check/stub.go -> pkg/collector/check/stats/stub.go

* Move Sender interface from pkg/aggregator/sender.go to pkg/aggregator/sender/sender.go

* Move Event struct to the package metrics/event
Goal: Be able to use Event without requiring tagger package.

* Move ServiceCheck struct to the package metrics/servicecheck
Goal: Be able to use ServiceCheck without requiring tagger package.

* Remove pkg/serializer from pkg/aggregator/sender

* Fix gofmt

* Use correct type in OrchestratorMetadata.
ProcessMessageBody is a type alias that depends on orchestrator build flag.

* Fix compilation for files with build tags not enabled by default

* Fix compilation for test/integration

* Use checkid when importing pkg/collector/check/id
  • Loading branch information
ogaca-dd authored Jul 5, 2023
1 parent 8bf830e commit cf80248
Show file tree
Hide file tree
Showing 172 changed files with 1,255 additions and 1,137 deletions.
6 changes: 3 additions & 3 deletions cmd/agent/gui/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/DataDog/datadog-agent/cmd/agent/common/path"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/collector"
"github.com/DataDog/datadog-agent/pkg/collector/check"
checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
Expand Down Expand Up @@ -105,9 +105,9 @@ func runCheckOnce(w http.ResponseWriter, r *http.Request) {
}

// Run the check intance(s) once, as a test
stats := []*check.Stats{}
stats := []*checkstats.Stats{}
for _, ch := range instances {
s := check.NewStats(ch)
s := checkstats.NewStats(ch)

t0 := time.Now()
err := ch.Run()
Expand Down
6 changes: 3 additions & 3 deletions cmd/agent/gui/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/DataDog/datadog-agent/pkg/autodiscovery"
"github.com/DataDog/datadog-agent/pkg/collector"
"github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/collector/check/stats"
"github.com/DataDog/datadog-agent/pkg/status"
)

Expand All @@ -34,7 +34,7 @@ type Data struct {
LoaderErrs map[string]map[string]string
ConfigErrs map[string]string
Stats map[string]interface{}
CheckStats []*check.Stats
CheckStats []*stats.Stats
}

func renderStatus(rawData []byte, request string) (string, error) {
Expand Down Expand Up @@ -71,7 +71,7 @@ func renderRunningChecks() (string, error) {
return b.String(), nil
}

func renderCheck(name string, stats []*check.Stats) (string, error) {
func renderCheck(name string, stats []*stats.Stats) (string, error) {
var b = new(bytes.Buffer)

data := Data{Name: name, CheckStats: stats}
Expand Down
22 changes: 12 additions & 10 deletions comp/dogstatsd/server/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/aggregator/ckey"
"github.com/DataDog/datadog-agent/pkg/metrics"
"github.com/DataDog/datadog-agent/pkg/metrics/event"
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
"github.com/DataDog/datadog-agent/pkg/tagset"
)

Expand All @@ -31,12 +33,12 @@ type batcher struct {
// with timestamp currently stored)
samplesWithTsCount int

events []*metrics.Event
serviceChecks []*metrics.ServiceCheck
events []*event.Event
serviceChecks []*servicecheck.ServiceCheck

// output channels
choutEvents chan<- []*metrics.Event
choutServiceChecks chan<- []*metrics.ServiceCheck
choutEvents chan<- []*event.Event
choutServiceChecks chan<- []*servicecheck.ServiceCheck

metricSamplePool *metrics.MetricSamplePool

Expand Down Expand Up @@ -71,8 +73,8 @@ func fastrange(key ckey.ContextKey, pipelineCount int) uint32 {
func newBatcher(demux aggregator.DemultiplexerWithAggregator) *batcher {
_, pipelineCount := aggregator.GetDogStatsDWorkerAndPipelineCount()

var e chan []*metrics.Event
var sc chan []*metrics.ServiceCheck
var e chan []*event.Event
var sc chan []*servicecheck.ServiceCheck

// the Serverless Agent doesn't have to support service checks nor events so
// it doesn't run an Aggregator.
Expand Down Expand Up @@ -159,11 +161,11 @@ func (b *batcher) appendSample(sample metrics.MetricSample) {
b.samplesCount[shardKey]++
}

func (b *batcher) appendEvent(event *metrics.Event) {
func (b *batcher) appendEvent(event *event.Event) {
b.events = append(b.events, event)
}

func (b *batcher) appendServiceCheck(serviceCheck *metrics.ServiceCheck) {
func (b *batcher) appendServiceCheck(serviceCheck *servicecheck.ServiceCheck) {
b.serviceChecks = append(b.serviceChecks, serviceCheck)
}

Expand Down Expand Up @@ -227,7 +229,7 @@ func (b *batcher) flush() {
t2 := time.Now()
tlmChannel.Observe(float64(t2.Sub(t1).Nanoseconds()), "events")

b.events = []*metrics.Event{}
b.events = []*event.Event{}
}

// flush service checks
Expand All @@ -237,6 +239,6 @@ func (b *batcher) flush() {
t2 := time.Now()
tlmChannel.Observe(float64(t2.Sub(t1).Nanoseconds()), "service_checks")

b.serviceChecks = []*metrics.ServiceCheck{}
b.serviceChecks = []*servicecheck.ServiceCheck{}
}
}
42 changes: 22 additions & 20 deletions comp/dogstatsd/server/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/metrics"
metricsevent "github.com/DataDog/datadog-agent/pkg/metrics/event"
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
"github.com/DataDog/datadog-agent/pkg/util/containers"
"github.com/DataDog/datadog-agent/pkg/util/kubernetes/kubelet"
)
Expand Down Expand Up @@ -210,34 +212,34 @@ func enrichMetricSample(dest []metrics.MetricSample, ddSample dogstatsdMetricSam
})
}

func enrichEventPriority(priority eventPriority) metrics.EventPriority {
func enrichEventPriority(priority eventPriority) metricsevent.EventPriority {
switch priority {
case priorityNormal:
return metrics.EventPriorityNormal
return metricsevent.EventPriorityNormal
case priorityLow:
return metrics.EventPriorityLow
return metricsevent.EventPriorityLow
}
return metrics.EventPriorityNormal
return metricsevent.EventPriorityNormal
}

func enrichEventAlertType(dogstatsdAlertType alertType) metrics.EventAlertType {
func enrichEventAlertType(dogstatsdAlertType alertType) metricsevent.EventAlertType {
switch dogstatsdAlertType {
case alertTypeSuccess:
return metrics.EventAlertTypeSuccess
return metricsevent.EventAlertTypeSuccess
case alertTypeInfo:
return metrics.EventAlertTypeInfo
return metricsevent.EventAlertTypeInfo
case alertTypeWarning:
return metrics.EventAlertTypeWarning
return metricsevent.EventAlertTypeWarning
case alertTypeError:
return metrics.EventAlertTypeError
return metricsevent.EventAlertTypeError
}
return metrics.EventAlertTypeSuccess
return metricsevent.EventAlertTypeSuccess
}

func enrichEvent(event dogstatsdEvent, origin string, conf enrichConfig) *metrics.Event {
func enrichEvent(event dogstatsdEvent, origin string, conf enrichConfig) *metricsevent.Event {
tags, hostnameFromTags, udsOrigin, clientOrigin, cardinality := extractTagsMetadata(event.tags, origin, event.containerID, conf)

enrichedEvent := &metrics.Event{
enrichedEvent := &metricsevent.Event{
Title: event.title,
Text: event.text,
Ts: event.timestamp,
Expand All @@ -259,24 +261,24 @@ func enrichEvent(event dogstatsdEvent, origin string, conf enrichConfig) *metric
return enrichedEvent
}

func enrichServiceCheckStatus(status serviceCheckStatus) metrics.ServiceCheckStatus {
func enrichServiceCheckStatus(status serviceCheckStatus) servicecheck.ServiceCheckStatus {
switch status {
case serviceCheckStatusUnknown:
return metrics.ServiceCheckUnknown
return servicecheck.ServiceCheckUnknown
case serviceCheckStatusOk:
return metrics.ServiceCheckOK
return servicecheck.ServiceCheckOK
case serviceCheckStatusWarning:
return metrics.ServiceCheckWarning
return servicecheck.ServiceCheckWarning
case serviceCheckStatusCritical:
return metrics.ServiceCheckCritical
return servicecheck.ServiceCheckCritical
}
return metrics.ServiceCheckUnknown
return servicecheck.ServiceCheckUnknown
}

func enrichServiceCheck(serviceCheck dogstatsdServiceCheck, origin string, conf enrichConfig) *metrics.ServiceCheck {
func enrichServiceCheck(serviceCheck dogstatsdServiceCheck, origin string, conf enrichConfig) *servicecheck.ServiceCheck {
tags, hostnameFromTags, udsOrigin, clientOrigin, cardinality := extractTagsMetadata(serviceCheck.tags, origin, serviceCheck.containerID, conf)

enrichedServiceCheck := &metrics.ServiceCheck{
enrichedServiceCheck := &servicecheck.ServiceCheck{
CheckName: serviceCheck.name,
Ts: serviceCheck.timestamp,
Status: enrichServiceCheckStatus(serviceCheck.status),
Expand Down
Loading

0 comments on commit cf80248

Please sign in to comment.