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

feat: add labels defined in harvest config to metadata metrics #2456

Merged
merged 4 commits into from
Nov 8, 2023
Merged
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
6 changes: 6 additions & 0 deletions cmd/poller/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func Init(c Collector) error {
md.SetGlobalLabel("object", object)
md.SetGlobalLabel("datacenter", params.GetChildContentS("datacenter"))

if params.HasChildS("labels") {
for _, l := range params.GetChildS("labels").GetChildren() {
md.SetGlobalLabel(l.GetNameS(), l.GetContentS())
}
}

_, _ = md.NewMetricInt64("poll_time")
_, _ = md.NewMetricInt64("task_time")
_, _ = md.NewMetricInt64("api_time")
Expand Down
10 changes: 8 additions & 2 deletions cmd/poller/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
type Exporter interface {
Init() error // initialize exporter
GetClass() string // the class of the exporter, e.g. Prometheus, InfluxDB
GetName() string // the name of the exporter instance
// Name is different from Class, since we can have multiple instances of the same Class
// GetName is different from Class, since we can have multiple instances of the same Class
GetName() string // the name of the exporter instance
GetExportCount() uint64 // return and reset number of exported data points, used by Poller to keep stats
AddExportCount(uint64) // add count to the export count, called by the exporter itself
GetStatus() (uint8, string, string) // return current state of the exporter
Expand Down Expand Up @@ -72,6 +72,12 @@ func New(c, n string, o *options.Options, p conf.Exporter, params *conf.Poller)
}
if params != nil {
abc.Metadata.SetGlobalLabel("datacenter", params.Datacenter)
labels := params.Labels
if labels != nil {
for _, labelPtr := range *labels {
rahulguptajss marked this conversation as resolved.
Show resolved Hide resolved
abc.Metadata.SetGlobalLabels(labelPtr)
}
}
}
return &abc
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,13 @@ func (p *Poller) loadMetadata() {
if p.options.PromPort != 0 {
p.status.SetGlobalLabel("promport", strconv.Itoa(p.options.PromPort))
}
labels := p.params.Labels
if labels != nil {
for _, labelPtr := range *labels {
p.metadata.SetGlobalLabels(labelPtr)
p.status.SetGlobalLabels(labelPtr)
}
}
p.status.SetExportOptions(matrix.DefaultExportOptions())
}

Expand Down
52 changes: 26 additions & 26 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,32 +421,32 @@ type CertificateScript struct {
}

type Poller struct {
Addr string `yaml:"addr,omitempty"`
APIVersion string `yaml:"api_version,omitempty"`
APIVfiler string `yaml:"api_vfiler,omitempty"`
AuthStyle string `yaml:"auth_style,omitempty"`
CaCertPath string `yaml:"ca_cert,omitempty"`
ClientTimeout string `yaml:"client_timeout,omitempty"`
Collectors []Collector `yaml:"collectors,omitempty"`
CredentialsFile string `yaml:"credentials_file,omitempty"`
CredentialsScript CredentialsScript `yaml:"credentials_script,omitempty"`
CertificateScript CertificateScript `yaml:"certificate_script,omitempty"`
Datacenter string `yaml:"datacenter,omitempty"`
Exporters []string `yaml:"exporters,omitempty"`
IsKfs bool `yaml:"is_kfs,omitempty"`
Labels *[]*map[string]string `yaml:"labels,omitempty"`
LogMaxBytes int64 `yaml:"log_max_bytes,omitempty"`
LogMaxFiles int `yaml:"log_max_files,omitempty"`
LogSet *[]string `yaml:"log,omitempty"`
Password string `yaml:"password,omitempty"`
PollerSchedule string `yaml:"poller_schedule,omitempty"`
SslCert string `yaml:"ssl_cert,omitempty"`
SslKey string `yaml:"ssl_key,omitempty"`
TLSMinVersion string `yaml:"tls_min_version,omitempty"`
UseInsecureTLS *bool `yaml:"use_insecure_tls,omitempty"`
Username string `yaml:"username,omitempty"`
PreferZAPI bool `yaml:"prefer_zapi,omitempty"`
ConfPath string `yaml:"conf_path,omitempty"`
Addr string `yaml:"addr,omitempty"`
APIVersion string `yaml:"api_version,omitempty"`
APIVfiler string `yaml:"api_vfiler,omitempty"`
AuthStyle string `yaml:"auth_style,omitempty"`
CaCertPath string `yaml:"ca_cert,omitempty"`
ClientTimeout string `yaml:"client_timeout,omitempty"`
Collectors []Collector `yaml:"collectors,omitempty"`
CredentialsFile string `yaml:"credentials_file,omitempty"`
CredentialsScript CredentialsScript `yaml:"credentials_script,omitempty"`
CertificateScript CertificateScript `yaml:"certificate_script,omitempty"`
Datacenter string `yaml:"datacenter,omitempty"`
Exporters []string `yaml:"exporters,omitempty"`
IsKfs bool `yaml:"is_kfs,omitempty"`
Labels *[]map[string]string `yaml:"labels,omitempty"`
LogMaxBytes int64 `yaml:"log_max_bytes,omitempty"`
LogMaxFiles int `yaml:"log_max_files,omitempty"`
LogSet *[]string `yaml:"log,omitempty"`
Password string `yaml:"password,omitempty"`
PollerSchedule string `yaml:"poller_schedule,omitempty"`
SslCert string `yaml:"ssl_cert,omitempty"`
SslKey string `yaml:"ssl_key,omitempty"`
TLSMinVersion string `yaml:"tls_min_version,omitempty"`
UseInsecureTLS *bool `yaml:"use_insecure_tls,omitempty"`
Username string `yaml:"username,omitempty"`
PreferZAPI bool `yaml:"prefer_zapi,omitempty"`
ConfPath string `yaml:"conf_path,omitempty"`
promIndex int
Name string
}
Expand Down
Loading