From 8ba168f3be7b590913c76c35df243561b7c1f795 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 13 Nov 2020 17:17:03 +0300 Subject: [PATCH] Add omitempty for DisableCompression and DisableKeepAlive fields in ScrapeConfig (#796) * Add omitempty for DisableCompression and DisableKeepAlive fields in ScrapeConfig * Add omitempty annotation to all the default/optional values * Fix annotations after review --- lib/promauth/config.go | 14 ++--- lib/promrelabel/config.go | 14 ++--- lib/promscrape/config.go | 60 +++++++++---------- lib/promscrape/discovery/consul/consul.go | 16 ++--- lib/promscrape/discovery/dns/dns.go | 4 +- .../discovery/dockerswarm/dockerswarm.go | 10 ++-- lib/promscrape/discovery/ec2/ec2.go | 16 ++--- lib/promscrape/discovery/gce/gce.go | 6 +- .../discovery/kubernetes/kubernetes.go | 14 ++--- .../discovery/openstack/openstack.go | 30 +++++----- 10 files changed, 92 insertions(+), 92 deletions(-) diff --git a/lib/promauth/config.go b/lib/promauth/config.go index 838b42be6..184f872bf 100644 --- a/lib/promauth/config.go +++ b/lib/promauth/config.go @@ -13,18 +13,18 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tls_config type TLSConfig struct { - CAFile string `yaml:"ca_file"` - CertFile string `yaml:"cert_file"` - KeyFile string `yaml:"key_file"` - ServerName string `yaml:"server_name"` - InsecureSkipVerify bool `yaml:"insecure_skip_verify"` + CAFile string `yaml:"ca_file,omitempty"` + CertFile string `yaml:"cert_file,omitempty"` + KeyFile string `yaml:"key_file,omitempty"` + ServerName string `yaml:"server_name,omitempty"` + InsecureSkipVerify bool `yaml:"insecure_skip_verify,omitempty"` } // BasicAuthConfig represents basic auth config. type BasicAuthConfig struct { Username string `yaml:"username"` - Password string `yaml:"password"` - PasswordFile string `yaml:"password_file"` + Password string `yaml:"password,omitempty"` + PasswordFile string `yaml:"password_file,omitempty"` } // Config is auth config. diff --git a/lib/promrelabel/config.go b/lib/promrelabel/config.go index 911eea2a3..abd9419a4 100644 --- a/lib/promrelabel/config.go +++ b/lib/promrelabel/config.go @@ -14,13 +14,13 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config type RelabelConfig struct { - SourceLabels []string `yaml:"source_labels"` - Separator *string `yaml:"separator"` - TargetLabel string `yaml:"target_label"` - Regex *string `yaml:"regex"` - Modulus uint64 `yaml:"modulus"` - Replacement *string `yaml:"replacement"` - Action string `yaml:"action"` + SourceLabels []string `yaml:"source_labels,flow,omitempty"` + Separator *string `yaml:"separator,omitempty"` + TargetLabel string `yaml:"target_label,omitempty"` + Regex *string `yaml:"regex,omitempty"` + Modulus uint64 `yaml:"modulus,omitempty"` + Replacement *string `yaml:"replacement,omitempty"` + Action string `yaml:"action,omitempty"` } // LoadRelabelConfigs loads relabel configs from the given path. diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 8c159a7fd..9ada106c6 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -50,9 +50,9 @@ type Config struct { // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/ type GlobalConfig struct { - ScrapeInterval time.Duration `yaml:"scrape_interval"` - ScrapeTimeout time.Duration `yaml:"scrape_timeout"` - ExternalLabels map[string]string `yaml:"external_labels"` + ScrapeInterval time.Duration `yaml:"scrape_interval,omitempty"` + ScrapeTimeout time.Duration `yaml:"scrape_timeout,omitempty"` + ExternalLabels map[string]string `yaml:"external_labels,omitempty"` } // ScrapeConfig represents essential parts for `scrape_config` section of Prometheus config. @@ -60,34 +60,34 @@ type GlobalConfig struct { // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config type ScrapeConfig struct { JobName string `yaml:"job_name"` - ScrapeInterval time.Duration `yaml:"scrape_interval"` - ScrapeTimeout time.Duration `yaml:"scrape_timeout"` - MetricsPath string `yaml:"metrics_path"` - HonorLabels bool `yaml:"honor_labels"` - HonorTimestamps bool `yaml:"honor_timestamps"` - Scheme string `yaml:"scheme"` - Params map[string][]string `yaml:"params"` - BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth"` - BearerToken string `yaml:"bearer_token"` - BearerTokenFile string `yaml:"bearer_token_file"` - TLSConfig *promauth.TLSConfig `yaml:"tls_config"` - StaticConfigs []StaticConfig `yaml:"static_configs"` - FileSDConfigs []FileSDConfig `yaml:"file_sd_configs"` - KubernetesSDConfigs []kubernetes.SDConfig `yaml:"kubernetes_sd_configs"` - OpenStackSDConfigs []openstack.SDConfig `yaml:"openstack_sd_configs"` - ConsulSDConfigs []consul.SDConfig `yaml:"consul_sd_configs"` - DockerSwarmConfigs []dockerswarm.SDConfig `yaml:"dockerswarm_sd_configs"` - DNSSDConfigs []dns.SDConfig `yaml:"dns_sd_configs"` - EC2SDConfigs []ec2.SDConfig `yaml:"ec2_sd_configs"` - GCESDConfigs []gce.SDConfig `yaml:"gce_sd_configs"` - RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs"` - MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs"` - SampleLimit int `yaml:"sample_limit"` + ScrapeInterval time.Duration `yaml:"scrape_interval,omitempty"` + ScrapeTimeout time.Duration `yaml:"scrape_timeout,omitempty"` + MetricsPath string `yaml:"metrics_path,omitempty"` + HonorLabels bool `yaml:"honor_labels,omitempty"` + HonorTimestamps bool `yaml:"honor_timestamps,omitempty"` + Scheme string `yaml:"scheme,omitempty"` + Params map[string][]string `yaml:"params,omitempty"` + BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth,omitempty"` + BearerToken string `yaml:"bearer_token,omitempty"` + BearerTokenFile string `yaml:"bearer_token_file,omitempty"` + TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` + StaticConfigs []StaticConfig `yaml:"static_configs,omitempty"` + FileSDConfigs []FileSDConfig `yaml:"file_sd_configs,omitempty"` + KubernetesSDConfigs []kubernetes.SDConfig `yaml:"kubernetes_sd_configs,omitempty"` + OpenStackSDConfigs []openstack.SDConfig `yaml:"openstack_sd_configs,omitempty"` + ConsulSDConfigs []consul.SDConfig `yaml:"consul_sd_configs,omitempty"` + DockerSwarmConfigs []dockerswarm.SDConfig `yaml:"dockerswarm_sd_configs,omitempty"` + DNSSDConfigs []dns.SDConfig `yaml:"dns_sd_configs,omitempty"` + EC2SDConfigs []ec2.SDConfig `yaml:"ec2_sd_configs,omitempty"` + GCESDConfigs []gce.SDConfig `yaml:"gce_sd_configs,omitempty"` + RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs,omitempty"` + MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs,omitempty"` + SampleLimit int `yaml:"sample_limit,omitempty"` // These options are supported only by lib/promscrape. - DisableCompression bool `yaml:"disable_compression"` - DisableKeepAlive bool `yaml:"disable_keepalive"` - StreamParse bool `yaml:"stream_parse"` + DisableCompression bool `yaml:"disable_compression,omitempty"` + DisableKeepAlive bool `yaml:"disable_keepalive,omitempty"` + StreamParse bool `yaml:"stream_parse,omitempty"` // This is set in loadConfig swc *scrapeWorkConfig @@ -106,7 +106,7 @@ type FileSDConfig struct { // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#static_config type StaticConfig struct { Targets []string `yaml:"targets"` - Labels map[string]string `yaml:"labels"` + Labels map[string]string `yaml:"labels,omitempty"` } func loadStaticConfigs(path string) ([]StaticConfig, error) { diff --git a/lib/promscrape/discovery/consul/consul.go b/lib/promscrape/discovery/consul/consul.go index 25b8c501a..735190839 100644 --- a/lib/promscrape/discovery/consul/consul.go +++ b/lib/promscrape/discovery/consul/consul.go @@ -10,18 +10,18 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#consul_sd_config type SDConfig struct { - Server string `yaml:"server"` + Server string `yaml:"server,omitempty"` Token *string `yaml:"token"` Datacenter string `yaml:"datacenter"` - Scheme string `yaml:"scheme"` + Scheme string `yaml:"scheme,omitempty"` Username string `yaml:"username"` Password string `yaml:"password"` - TLSConfig *promauth.TLSConfig `yaml:"tls_config"` - Services []string `yaml:"services"` - Tags []string `yaml:"tags"` - NodeMeta map[string]string `yaml:"node_meta"` - TagSeparator *string `yaml:"tag_separator"` - AllowStale bool `yaml:"allow_stale"` + TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` + Services []string `yaml:"services,omitempty"` + Tags []string `yaml:"tags,omitempty"` + NodeMeta map[string]string `yaml:"node_meta,omitempty"` + TagSeparator *string `yaml:"tag_separator,omitempty"` + AllowStale bool `yaml:"allow_stale,omitempty"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.consulSDCheckInterval` command-line option. } diff --git a/lib/promscrape/discovery/dns/dns.go b/lib/promscrape/discovery/dns/dns.go index 03615b3c0..40d8c580d 100644 --- a/lib/promscrape/discovery/dns/dns.go +++ b/lib/promscrape/discovery/dns/dns.go @@ -17,8 +17,8 @@ import ( // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#dns_sd_config type SDConfig struct { Names []string `yaml:"names"` - Type string `yaml:"type"` - Port *int `yaml:"port"` + Type string `yaml:"type,omitempty"` + Port *int `yaml:"port,omitempty"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.dnsSDCheckInterval` command-line option. } diff --git a/lib/promscrape/discovery/dockerswarm/dockerswarm.go b/lib/promscrape/discovery/dockerswarm/dockerswarm.go index 59baecbe9..3d49365a3 100644 --- a/lib/promscrape/discovery/dockerswarm/dockerswarm.go +++ b/lib/promscrape/discovery/dockerswarm/dockerswarm.go @@ -12,13 +12,13 @@ import ( type SDConfig struct { Host string `yaml:"host"` // TODO: add support for proxy_url - TLSConfig *promauth.TLSConfig `yaml:"tls_config"` + TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` Role string `yaml:"role"` - Port int `yaml:"port"` + Port int `yaml:"port,omitempty"` // refresh_interval is obtained from `-promscrape.dockerswarmSDCheckInterval` command-line option - BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth"` - BearerToken string `yaml:"bearer_token"` - BearerTokenFile string `yaml:"bearer_token_file"` + BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth,omitempty"` + BearerToken string `yaml:"bearer_token,omitempty"` + BearerTokenFile string `yaml:"bearer_token_file,omitempty"` } // GetLabels returns dockerswarm labels according to sdc. diff --git a/lib/promscrape/discovery/ec2/ec2.go b/lib/promscrape/discovery/ec2/ec2.go index c81d790b0..8ffa1697e 100644 --- a/lib/promscrape/discovery/ec2/ec2.go +++ b/lib/promscrape/discovery/ec2/ec2.go @@ -8,17 +8,17 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config type SDConfig struct { - Region string `yaml:"region"` - Endpoint string `yaml:"endpoint"` - AccessKey string `yaml:"access_key"` - SecretKey string `yaml:"secret_key"` + Region string `yaml:"region,omitempty"` + Endpoint string `yaml:"endpoint,omitempty"` + AccessKey string `yaml:"access_key,omitempty"` + SecretKey string `yaml:"secret_key,omitempty"` // TODO add support for Profile, not working atm - Profile string `yaml:"profile"` - RoleARN string `yaml:"role_arn"` + Profile string `yaml:"profile,omitempty"` + RoleARN string `yaml:"role_arn,omitempty"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option. - Port *int `yaml:"port"` - Filters []Filter `yaml:"filters"` + Port *int `yaml:"port,omitempty"` + Filters []Filter `yaml:"filters,omitempty"` } // Filter is ec2 filter. diff --git a/lib/promscrape/discovery/gce/gce.go b/lib/promscrape/discovery/gce/gce.go index 9227fe813..f0629d2ef 100644 --- a/lib/promscrape/discovery/gce/gce.go +++ b/lib/promscrape/discovery/gce/gce.go @@ -10,11 +10,11 @@ import ( type SDConfig struct { Project string `yaml:"project"` Zone ZoneYAML `yaml:"zone"` - Filter string `yaml:"filter"` + Filter string `yaml:"filter,omitempty"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.gceSDCheckInterval` command-line option. - Port *int `yaml:"port"` - TagSeparator *string `yaml:"tag_separator"` + Port *int `yaml:"port,omitempty"` + TagSeparator *string `yaml:"tag_separator,omitempty"` } // ZoneYAML holds info about zones. diff --git a/lib/promscrape/discovery/kubernetes/kubernetes.go b/lib/promscrape/discovery/kubernetes/kubernetes.go index 1b8d76809..87c381963 100644 --- a/lib/promscrape/discovery/kubernetes/kubernetes.go +++ b/lib/promscrape/discovery/kubernetes/kubernetes.go @@ -10,14 +10,14 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config type SDConfig struct { - APIServer string `yaml:"api_server"` + APIServer string `yaml:"api_server,omitempty"` Role string `yaml:"role"` - BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth"` - BearerToken string `yaml:"bearer_token"` - BearerTokenFile string `yaml:"bearer_token_file"` - TLSConfig *promauth.TLSConfig `yaml:"tls_config"` - Namespaces Namespaces `yaml:"namespaces"` - Selectors []Selector `yaml:"selectors"` + BasicAuth *promauth.BasicAuthConfig `yaml:"basic_auth,omitempty"` + BearerToken string `yaml:"bearer_token,omitempty"` + BearerTokenFile string `yaml:"bearer_token_file,omitempty"` + TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` + Namespaces Namespaces `yaml:"namespaces,omitempty"` + Selectors []Selector `yaml:"selectors,omitempty"` } // Namespaces represents namespaces for SDConfig diff --git a/lib/promscrape/discovery/openstack/openstack.go b/lib/promscrape/discovery/openstack/openstack.go index 52f0822e3..0a1e9bd1d 100644 --- a/lib/promscrape/discovery/openstack/openstack.go +++ b/lib/promscrape/discovery/openstack/openstack.go @@ -10,25 +10,25 @@ import ( // // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#openstack_sd_config type SDConfig struct { - IdentityEndpoint string `yaml:"identity_endpoint"` - Username string `yaml:"username"` - UserID string `yaml:"userid"` - Password string `yaml:"password"` - ProjectName string `yaml:"project_name"` - ProjectID string `yaml:"project_id"` - DomainName string `yaml:"domain_name"` - DomainID string `yaml:"domain_id"` - ApplicationCredentialName string `yaml:"application_credential_name"` - ApplicationCredentialID string `yaml:"application_credential_id"` - ApplicationCredentialSecret string `yaml:"application_credential_secret"` + IdentityEndpoint string `yaml:"identity_endpoint,omitempty"` + Username string `yaml:"username,omitempty"` + UserID string `yaml:"userid,omitempty"` + Password string `yaml:"password,omitempty"` + ProjectName string `yaml:"project_name,omitempty"` + ProjectID string `yaml:"project_id,omitempty"` + DomainName string `yaml:"domain_name,omitempty"` + DomainID string `yaml:"domain_id,omitempty"` + ApplicationCredentialName string `yaml:"application_credential_name,omitempty"` + ApplicationCredentialID string `yaml:"application_credential_id,omitempty"` + ApplicationCredentialSecret string `yaml:"application_credential_secret,omitempty"` Role string `yaml:"role"` Region string `yaml:"region"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.openstackSDCheckInterval` command-line option. - Port int `yaml:"port"` - AllTenants bool `yaml:"all_tenants"` - TLSConfig *promauth.TLSConfig `yaml:"tls_config"` - Availability string `yaml:"availability"` + Port int `yaml:"port,omitempty"` + AllTenants bool `yaml:"all_tenants,omitempty"` + TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` + Availability string `yaml:"availability,omitempty"` } // GetLabels returns gce labels according to sdc.