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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions pkg/collector/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Check interface {
Cancel()
// String provides a printable version of the check name
String() string
// Loader returns the name of the check loader
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 (c *StubCheck) Loader() string { return "StubLoader" }

// 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 (c *CheckBase) Loader() string {
return "Go"
Copy link
Contributor

Choose a reason for hiding this comment

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

@pgimalac Drive-by note: Should we make sure that these are all lowercase to avoid issues with capitalization/filtering on the backend?

}

// InitConfig returns the init_config configuration for the check.
func (c *CheckBase) InitConfig() string {
return c.initConfig
Expand Down
6 changes: 6 additions & 0 deletions pkg/collector/corechecks/embed/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (c *APMCheck) ConfigSource() string {
return c.source
}

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

// Run executes the check with retries
func (c *APMCheck) Run() error {
c.running.Store(true)
Expand Down
6 changes: 6 additions & 0 deletions pkg/collector/corechecks/embed/process/process_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (c *ProcessAgentCheck) ConfigSource() string {
return c.source
}

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

// InitConfig returns the init configuration
func (c *ProcessAgentCheck) InitConfig() string {
return c.initConfig
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 (c *PythonCheck) Loader() string {
return "Python"
}

// InitConfig returns the init_config configuration for the check.
func (c *PythonCheck) InitConfig() string {
return c.initConfig
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