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

[ASCII-2671] Add check loader name tag on checks.execution_time metric #33075

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (c *CheckWrapper) ConfigSource() string {
return c.inner.ConfigSource()
}

// Loader returns the name of the check loader
func (c *CheckWrapper) Loader() string {
return c.inner.Loader()
}

// IsTelemetryEnabled implements Check#IsTelemetryEnabled
func (c *CheckWrapper) IsTelemetryEnabled() bool {
return c.inner.IsTelemetryEnabled()
Expand Down
1 change: 1 addition & 0 deletions comp/core/agenttelemetry/impl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ var defaultProfiles = `
- name: checks.execution_time
aggregate_tags:
- check_name
- check_loader
- name: pymem.inuse
schedule:
start_after: 30
Expand Down
3 changes: 3 additions & 0 deletions pkg/collector/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Check interface {
Cancel()
// String provides a printable version of the check name
String() string
// Loader returns the name of the check loader
// This is used in tags so should match the tag value format constraints (eg. lowercase, no spaces)
Loader() string
// Configure configures the check
Configure(senderManger sender.SenderManager, integrationConfigDigest uint64, config, initConfig integration.Data, source string) error
// Interval returns the interval time for the check
Expand Down
4 changes: 4 additions & 0 deletions pkg/collector/check/check_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// MockInfo is a mock for test using check.Info interface
type MockInfo struct {
Name string
LoaderName string
CheckID checkid.ID
Source string
InitConf string
Expand All @@ -35,6 +36,9 @@ func (m MockInfo) Version() string { return "" }
// ConfigSource returns the source of the check
func (m MockInfo) ConfigSource() string { return m.Source }

// Loader returns the name of the check loader
func (m MockInfo) Loader() string { return m.LoaderName }

// InitConfig returns the init_config of the check
func (m MockInfo) InitConfig() string { return m.InitConf }

Expand Down
8 changes: 6 additions & 2 deletions pkg/collector/check/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
tlmHistogramBuckets = telemetry.NewCounter("checks", "histogram_buckets",
[]string{"check_name"}, "Histogram buckets count")
tlmExecutionTime = telemetry.NewGauge("checks", "execution_time",
[]string{"check_name"}, "Check execution time")
[]string{"check_name", "check_loader"}, "Check execution time")
tlmCheckDelay = telemetry.NewGauge("checks",
"delay",
[]string{"check_name"},
Expand Down Expand Up @@ -92,6 +92,7 @@ type Stats struct {
CheckName string
CheckVersion string
CheckConfigSource string
CheckLoader string
CheckID checkid.ID
Interval time.Duration
// LongRunning is true if the check is a long running check
Expand Down Expand Up @@ -135,13 +136,16 @@ type StatsCheck interface {
Interval() time.Duration
// ConfigSource returns the configuration source of the check
ConfigSource() string
// Loader returns the name of the check loader
Loader() string
}

// NewStats returns a new check stats instance
func NewStats(c StatsCheck) *Stats {
stats := Stats{
CheckID: c.ID(),
CheckName: c.String(),
CheckLoader: c.Loader(),
CheckVersion: c.Version(),
CheckConfigSource: c.ConfigSource(),
Interval: c.Interval(),
Expand Down Expand Up @@ -177,7 +181,7 @@ func (cs *Stats) Add(t time.Duration, err error, warnings []error, metricStats S
cs.ExecutionTimes[cs.TotalRuns%uint64(len(cs.ExecutionTimes))] = tms
cs.TotalRuns++
if cs.Telemetry {
tlmExecutionTime.Set(float64(tms), cs.CheckName)
tlmExecutionTime.Set(float64(tms), cs.CheckName, cs.CheckLoader)
}
var totalExecutionTime int64
ringSize := cs.TotalRuns
Expand Down
35 changes: 20 additions & 15 deletions pkg/collector/check/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,41 @@ import (

// Mock Check implementation used for testing
type mockCheck struct {
cfgSource string
id checkid.ID
stringVal string
version string
interval time.Duration
cfgSource string
loaderName string
id checkid.ID
stringVal string
version string
interval time.Duration
}

// Mock Check interface implementation
func (mc *mockCheck) ConfigSource() string { return mc.cfgSource }
func (mc *mockCheck) Loader() string { return mc.loaderName }
func (mc *mockCheck) ID() checkid.ID { return mc.id }
func (mc *mockCheck) String() string { return mc.stringVal }
func (mc *mockCheck) Version() string { return mc.version }
func (mc *mockCheck) Interval() time.Duration { return mc.interval }

func newMockCheck() StatsCheck {
return &mockCheck{
cfgSource: "checkConfigSrc",
id: "checkID",
stringVal: "checkString",
version: "checkVersion",
interval: 15 * time.Second,
cfgSource: "checkConfigSrc",
id: "checkID",
stringVal: "checkString",
loaderName: "mockLoader",
version: "checkVersion",
interval: 15 * time.Second,
}
}

func newMockCheckWithInterval(interval time.Duration) StatsCheck {
return &mockCheck{
cfgSource: "checkConfigSrc",
id: "checkID",
stringVal: "checkString",
version: "checkVersion",
interval: interval,
cfgSource: "checkConfigSrc",
id: "checkID",
stringVal: "checkString",
loaderName: "mockloader",
version: "checkVersion",
interval: interval,
}
}

Expand All @@ -71,6 +75,7 @@ func TestNewStats(t *testing.T) {

assert.Equal(t, stats.CheckID, checkid.ID("checkID"))
assert.Equal(t, stats.CheckName, "checkString")
assert.Equal(t, stats.CheckLoader, "mockLoader")
assert.Equal(t, stats.CheckVersion, "checkVersion")
assert.Equal(t, stats.CheckVersion, "checkVersion")
assert.Equal(t, stats.CheckConfigSource, "checkConfigSrc")
Expand Down
3 changes: 3 additions & 0 deletions pkg/collector/check/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (c *StubCheck) Version() string { return "" }
// ConfigSource returns the empty string
func (c *StubCheck) ConfigSource() string { return "" }

// Loader returns a stubbed loader name
func (*StubCheck) Loader() string { return "stub" }

// Stop is a noop
func (c *StubCheck) Stop() {}

Expand Down
4 changes: 4 additions & 0 deletions pkg/collector/corechecks/checkbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (c *CheckBase) ConfigSource() string {
return c.source
}

func (*CheckBase) Loader() string {
return GoCheckLoaderName
}

// InitConfig returns the init_config configuration for the check.
func (c *CheckBase) InitConfig() string {
return c.initConfig
Expand Down
7 changes: 7 additions & 0 deletions pkg/collector/corechecks/embed/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/check"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
"github.com/DataDog/datadog-agent/pkg/collector/check/stats"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/embed/common"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/config/utils"
Expand Down Expand Up @@ -70,6 +71,12 @@ func (c *APMCheck) ConfigSource() string {
return c.source
}

// Loader returns the check loader
func (*APMCheck) Loader() string {
// the apm check is scheduled by the Go loader
return corechecks.GoCheckLoaderName
}

// Run executes the check with retries
func (c *APMCheck) Run() error {
c.running.Store(true)
Expand Down
7 changes: 7 additions & 0 deletions pkg/collector/corechecks/embed/process/process_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/check"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
"github.com/DataDog/datadog-agent/pkg/collector/check/stats"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/embed/common"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/config/utils"
Expand Down Expand Up @@ -70,6 +71,12 @@ func (c *ProcessAgentCheck) ConfigSource() string {
return c.source
}

// Loader returns the check loader
func (*ProcessAgentCheck) Loader() string {
// the process check is scheduled by the Go loader
return corechecks.GoCheckLoaderName
}

// InitConfig returns the init configuration
func (c *ProcessAgentCheck) InitConfig() string {
return c.initConfig
Expand Down
7 changes: 5 additions & 2 deletions pkg/collector/corechecks/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type CheckFactory func() check.Check
// Catalog keeps track of Go checks by name
var catalog = make(map[string]CheckFactory)

// GoCheckLoaderName is the name of the Go loader
const GoCheckLoaderName string = "core"

// RegisterCheck adds a check to the catalog
func RegisterCheck(name string, checkFactory option.Option[func() check.Check]) {
if v, ok := checkFactory.Get(); ok {
Expand All @@ -51,8 +54,8 @@ func NewGoCheckLoader() (*GoCheckLoader, error) {
}

// Name return returns Go loader name
func (gl *GoCheckLoader) Name() string {
return "core"
func (*GoCheckLoader) Name() string {
return GoCheckLoaderName
}

// Load returns a Go check
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/longrunning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func (m *mockLongRunningCheck) GetSender() (sender.Sender, error) {
return s.(sender.Sender), args.Error(1)
}

func (m *mockLongRunningCheck) Loader() string {
args := m.Called()
return args.String(0)
}

func newMockLongRunningCheck() *mockLongRunningCheck {
return &mockLongRunningCheck{
stopCh: make(chan struct{}),
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/python/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (c *PythonCheck) ConfigSource() string {
return c.source
}

// Loader returns the check loader
func (*PythonCheck) Loader() string {
return PythonCheckLoaderName
}

// InitConfig returns the init_config configuration for the check.
func (c *PythonCheck) InitConfig() string {
return c.initConfig
Expand Down
11 changes: 6 additions & 5 deletions pkg/collector/python/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const (
a7TagPython3 = "python3" // Already running on python3, linting is disabled
)

// PythonCheckLoaderName is the name of the Python check loader
const PythonCheckLoaderName string = "python"

func init() {
factory := func(senderManager sender.SenderManager, logReceiver option.Option[integrations.Component], tagger tagger.Component) (check.Loader, error) {
return NewPythonCheckLoader(senderManager, logReceiver, tagger)
Expand Down Expand Up @@ -105,11 +108,9 @@ func getRtLoaderError() error {
return nil
}

// Load returns Python loader name
//
//nolint:revive // TODO(AML) Fix revive linter
func (cl *PythonCheckLoader) Name() string {
return "python"
// Name returns Python loader name
func (*PythonCheckLoader) Name() string {
return PythonCheckLoaderName
}

// Load tries to import a Python module with the same name found in config.Name, searches for
Expand Down
14 changes: 9 additions & 5 deletions pkg/collector/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ import (

type MockCheck struct {
core.CheckBase
Name string
Loader string
Name string
LoaderName string
}

func (m MockCheck) Run() error {
// not used in test
panic("implement me")
}

func (m MockCheck) Loader() string {
return m.LoaderName
}

func (m MockCheck) String() string {
return fmt.Sprintf("Loader: %s, Check: %s", m.Loader, m.Name)
return fmt.Sprintf("Loader: %s, Check: %s", m.LoaderName, m.Name)
}

type MockCoreLoader struct{}
Expand All @@ -41,7 +45,7 @@ func (l *MockCoreLoader) Name() string {

//nolint:revive // TODO(AML) Fix revive linter
func (l *MockCoreLoader) Load(_ sender.SenderManager, config integration.Config, _ integration.Data) (check.Check, error) {
mockCheck := MockCheck{Name: config.Name, Loader: l.Name()}
mockCheck := MockCheck{Name: config.Name, LoaderName: l.Name()}
return &mockCheck, nil
}

Expand All @@ -53,7 +57,7 @@ func (l *MockPythonLoader) Name() string {

//nolint:revive // TODO(AML) Fix revive linter
func (l *MockPythonLoader) Load(_ sender.SenderManager, config integration.Config, _ integration.Data) (check.Check, error) {
mockCheck := MockCheck{Name: config.Name, Loader: l.Name()}
mockCheck := MockCheck{Name: config.Name, LoaderName: l.Name()}
return &mockCheck, nil
}

Expand Down
Loading