Robert Lankford 93d2b4277a add host info processor (#4698)
* add host info processor implementation

Signed-off-by: Robbie Lankford <robert.lankford@grafana.com>

* fix lint

* remove gauge custom expiration logic

* make generate-manifest

* add config validation; remove stale duration crud

* refactor and clean up

---------

Signed-off-by: Robbie Lankford <robert.lankford@grafana.com>
2025-03-13 17:47:04 -04:00

38 lines
947 B
Go

package hostinfo
import (
"errors"
"flag"
"github.com/prometheus/common/model"
)
const (
defaultHostInfoMetric = "traces_host_info"
)
type Config struct {
// HostIdentifiers defines the list of resource attributes used to derive
// a unique `grafana.host.id` value. In most cases, this should be [ "host.id" ]
HostIdentifiers []string `yaml:"host_identifiers"`
// MetricName defines the name of the metric that will be generated
MetricName string `yaml:"metric_name"`
}
func (cfg *Config) RegisterFlagsAndApplyDefaults(string, *flag.FlagSet) {
cfg.HostIdentifiers = []string{"k8s.node.name", "host.id"}
cfg.MetricName = defaultHostInfoMetric
}
func (cfg *Config) Validate() error {
if len(cfg.HostIdentifiers) == 0 {
return errors.New("at least one value must be provided in host_identifiers")
}
if !model.IsValidMetricName(model.LabelValue(cfg.MetricName)) {
return errors.New("metric_name is invalid")
}
return nil
}