mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Switch `scraper/scraperhelper` `ControllerConfig` to schema-based generated configuration. This adds metadata-driven config generation for the scraper controller settings, publishes the reusable `controller_config` schema from `pkg/scraperhelper`, and updates the mdatagen sample scraper to embed that exported config via schema reference. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #15258 <!--Describe what testing was performed and which tests were added.--> #### Testing Added usage example to `samplescraper` test component. --------- Co-authored-by: Dmitry Anoshin <[email protected]>
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
// Code generated by mdatagen. DO NOT EDIT.
|
|
|
|
package controller
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// ControllerConfig ControllerConfig defines common settings for a scraper controller configuration. Scraper controller receivers can embed this struct, instead of receiver.Settings, and extend it with more fields if needed.
|
|
type ControllerConfig struct {
|
|
// CollectionInterval sets how frequently the scraper should be called and used as the context timeout to ensure that scrapers don't exceed the interval.
|
|
CollectionInterval time.Duration `mapstructure:"collection_interval"`
|
|
// InitialDelay sets the initial start delay for the scraper, any non positive value is assumed to be immediately.
|
|
InitialDelay time.Duration `mapstructure:"initial_delay"`
|
|
// Timeout is an optional value used to set scraper's context deadline.
|
|
Timeout time.Duration `mapstructure:"timeout"`
|
|
// prevent unkeyed literal initialization
|
|
_ struct{}
|
|
}
|
|
|
|
// Validate validates the ControllerConfig fields according to schema annotations.
|
|
func (c *ControllerConfig) Validate() error {
|
|
var err error
|
|
|
|
if inner_err := validateControllerConfig(c); inner_err != nil {
|
|
err = errors.Join(err, inner_err)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// NewDefaultControllerConfig returns a new ControllerConfig with default values consistent with the annotations in the schema.
|
|
func NewDefaultControllerConfig() ControllerConfig {
|
|
return ControllerConfig{
|
|
CollectionInterval: 1 * time.Minute,
|
|
InitialDelay: 1 * time.Second,
|
|
Timeout: 0,
|
|
}
|
|
}
|