Skip to content

Commit

Permalink
rebase on braydonk-refresh-interval
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonk committed Dec 2, 2021
1 parent 0d2aa4e commit ae2815f
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 34 deletions.
2 changes: 1 addition & 1 deletion apps/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r MetricsReceiverApache) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "httpd",
Config: map[string]interface{}{
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"endpoint": r.ServerStatusURL,
},
},
Expand Down
14 changes: 9 additions & 5 deletions apps/builtinconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package apps

import cg "github.com/GoogleCloudPlatform/ops-agent/confgenerator"
import (
"time"

cg "github.com/GoogleCloudPlatform/ops-agent/confgenerator"
)

var (
BuiltInConfStructs = map[string]*cg.UnifiedConfig{
Expand All @@ -39,7 +43,7 @@ var (
Receivers: map[string]cg.MetricsReceiver{
"hostmetrics": &MetricsReceiverHostmetrics{
ConfigComponent: cg.ConfigComponent{Type: "hostmetrics"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: "60s"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: time.Second * 60},
},
},
Processors: map[string]cg.MetricsProcessor{
Expand Down Expand Up @@ -78,15 +82,15 @@ var (
Receivers: map[string]cg.MetricsReceiver{
"hostmetrics": &MetricsReceiverHostmetrics{
ConfigComponent: cg.ConfigComponent{Type: "hostmetrics"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: "60s"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: time.Second * 60},
},
"iis": &MetricsReceiverIis{
ConfigComponent: cg.ConfigComponent{Type: "iis"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: "60s"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: time.Second * 60},
},
"mssql": &MetricsReceiverMssql{
ConfigComponent: cg.ConfigComponent{Type: "mssql"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: "60s"},
MetricsReceiverShared: cg.MetricsReceiverShared{CollectionInterval: time.Second * 60},
},
},
Processors: map[string]cg.MetricsProcessor{
Expand Down
2 changes: 1 addition & 1 deletion apps/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r MetricsReceiverCassandra) Pipelines() []otel.Pipeline {

config := map[string]interface{}{
"target_system": targetSystem,
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"endpoint": r.Endpoint,
"jar_path": jarPath,
}
Expand Down
2 changes: 1 addition & 1 deletion apps/hostmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r MetricsReceiverHostmetrics) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "hostmetrics",
Config: map[string]interface{}{
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"scrapers": map[string]interface{}{
"cpu": struct{}{},
"load": struct{}{},
Expand Down
2 changes: 1 addition & 1 deletion apps/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r MetricsReceiverIis) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "windowsperfcounters",
Config: map[string]interface{}{
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"perfcounters": []map[string]interface{}{
{
"object": "Web Service",
Expand Down
2 changes: 1 addition & 1 deletion apps/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r MetricsReceiverJVM) Pipelines() []otel.Pipeline {

config := map[string]interface{}{
"target_system": "jvm",
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"endpoint": r.Endpoint,
"jar_path": jarPath,
}
Expand Down
2 changes: 1 addition & 1 deletion apps/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m MetricsReceiverMssql) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "windowsperfcounters",
Config: map[string]interface{}{
"collection_interval": m.CollectionIntervalString(),
"collection_interval": m.CollectionInterval,
"perfcounters": []map[string]interface{}{
{
"object": "SQLServer:General Statistics",
Expand Down
2 changes: 1 addition & 1 deletion apps/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r MetricsReceiverNginx) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "nginx",
Config: map[string]interface{}{
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"endpoint": r.StubStatusURL,
},
},
Expand Down
2 changes: 1 addition & 1 deletion apps/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r MetricsReceiverRedis) Pipelines() []otel.Pipeline {
Receiver: otel.Component{
Type: "redis",
Config: map[string]interface{}{
"collection_interval": r.CollectionIntervalString(),
"collection_interval": r.CollectionInterval,
"endpoint": r.Address,
"password": r.Password,
},
Expand Down
22 changes: 1 addition & 21 deletions confgenerator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ func newValidator() *validator.Validate {
v.RegisterValidationCtx("platform", func(ctx context.Context, fl validator.FieldLevel) bool {
return ctx.Value(platformKey) == fl.Param()
})
// duration validates that the value is a valid duration and >= the parameter
v.RegisterValidation("duration", func(fl validator.FieldLevel) bool {
t, err := time.ParseDuration(fl.Field().String())
if err != nil {
return false
}
tmin, err := time.ParseDuration(fl.Param())
if err != nil {
panic(err)
}
return t >= tmin
})
// multipleof_time validates that the value duration is a multiple of the parameter
v.RegisterValidation("multipleof_time", func(fl validator.FieldLevel) bool {
t, ok := fl.Field().Interface().(time.Duration)
Expand Down Expand Up @@ -372,15 +360,7 @@ type MetricsReceiver interface {
}

type MetricsReceiverShared struct {
CollectionInterval string `yaml:"collection_interval" validate:"required,duration=10s"` // time.Duration format
}

func (m MetricsReceiverShared) CollectionIntervalString() string {
// TODO: Remove when https://github.com/goccy/go-yaml/pull/246 is merged
if m.CollectionInterval != "" {
return m.CollectionInterval
}
return "60s"
CollectionInterval time.Duration `yaml:"collection_interval" validate:"required,min=10s"` // time.Duration format
}

var MetricsReceiverTypes = &componentTypeRegistry{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
logging:
receivers:
syslog:
type: files
include_paths:
- /var/log/messages
- /var/log/syslog
service:
pipelines:
default_pipeline:
receivers: [syslog]
metrics:
receivers:
hostmetrics:
type: hostmetrics
collection_interval: 1m0s
processors:
metrics_filter:
type: exclude_metrics
metrics_pattern: []
service:
pipelines:
default_pipeline:
receivers: [hostmetrics]
processors: [metrics_filter]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
logging:
receivers:
syslog:
type: files
include_paths:
- /var/log/messages
- /var/log/syslog
service:
pipelines:
default_pipeline:
receivers: [syslog]
metrics:
receivers:
hostmetrics:
type: hostmetrics
collection_interval: 1m0s
processors:
metrics_filter:
type: exclude_metrics
metrics_pattern: []
service:
pipelines:
default_pipeline:
receivers: [hostmetrics]
processors: [metrics_filter]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
logging:
receivers:
syslog:
type: files
include_paths:
- /var/log/messages
- /var/log/syslog
service:
pipelines:
default_pipeline:
receivers: [syslog]
metrics:
receivers:
hostmetrics:
type: hostmetrics
collection_interval: 1m0s
processors:
metrics_filter:
type: exclude_metrics
metrics_pattern: []
service:
pipelines:
default_pipeline:
receivers: [hostmetrics]
processors: [metrics_filter]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
logging:
receivers:
syslog:
type: files
include_paths:
- /var/log/messages
- /var/log/syslog
service:
pipelines:
default_pipeline:
receivers: [syslog]
metrics:
receivers:
hostmetrics:
type: hostmetrics
collection_interval: 1m0s
processors:
metrics_filter:
type: exclude_metrics
metrics_pattern: []
service:
pipelines:
default_pipeline:
receivers: [hostmetrics]
processors: [metrics_filter]

0 comments on commit ae2815f

Please sign in to comment.