From 0c0e292b6964999048280c5087eb1e3147874d0f Mon Sep 17 00:00:00 2001 From: worker24h Date: Thu, 14 Mar 2024 20:40:18 +0800 Subject: [PATCH] fixbug, ignore hostname not effective, use `OmitHostname` (#828) * fixbug, ignore hostname not effective, use `OmitHostname` * Revert "fixbug, ignore hostname not effective, use `OmitHostname`" This reverts commit 06555386580ed3a5c38cc12ceaf32d00d59d19da. * fixbug, add config for ignore hostname and labels --------- Co-authored-by: xuxiaobing --- api/router_falcon.go | 4 ++-- api/router_opentsdb.go | 4 ++-- api/router_pushgateway.go | 4 ++-- api/router_remotewrite.go | 4 ++-- conf/config.toml | 3 +++ config/config.go | 20 +++++++++++--------- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/api/router_falcon.go b/api/router_falcon.go index fee96ceb..3656a3bc 100644 --- a/api/router_falcon.go +++ b/api/router_falcon.go @@ -168,8 +168,8 @@ func openFalcon(c *gin.Context) { ts = time.Now().Unix() ) - ignoreHostname := c.GetBool("ignore_hostname") - ignoreGlobalLabels := c.GetBool("ignore_global_labels") + ignoreHostname := config.Config.HTTP.IgnoreHostname + ignoreGlobalLabels := config.Config.HTTP.IgnoreGlobalLabels count := len(arr) series := make([]prompb.TimeSeries, 0, count) for i := 0; i < count; i++ { diff --git a/api/router_opentsdb.go b/api/router_opentsdb.go index 10e7f791..fcca84f4 100644 --- a/api/router_opentsdb.go +++ b/api/router_opentsdb.go @@ -150,8 +150,8 @@ func openTSDB(c *gin.Context) { ts = time.Now().Unix() ) - ignoreHostname := c.GetBool("ignore_hostname") - ignoreGlobalLabels := c.GetBool("ignore_global_labels") + ignoreHostname := config.Config.HTTP.IgnoreHostname + ignoreGlobalLabels := config.Config.HTTP.IgnoreGlobalLabels count := len(list) series := make([]prompb.TimeSeries, 0, count) for i := 0; i < len(list); i++ { diff --git a/api/router_pushgateway.go b/api/router_pushgateway.go index 0b1563f7..90663c60 100644 --- a/api/router_pushgateway.go +++ b/api/router_pushgateway.go @@ -38,8 +38,8 @@ func pushgateway(c *gin.Context) { return } - ignoreHostname := c.GetBool("ignore_hostname") - ignoreGlobalLabels := c.GetBool("ignore_global_labels") + ignoreHostname := config.Config.HTTP.IgnoreHostname + ignoreGlobalLabels := config.Config.HTTP.IgnoreGlobalLabels now := time.Now() diff --git a/api/router_remotewrite.go b/api/router_remotewrite.go index 82f7e3b9..71998938 100644 --- a/api/router_remotewrite.go +++ b/api/router_remotewrite.go @@ -23,8 +23,8 @@ func remoteWrite(c *gin.Context) { return } - ignoreHostname := c.GetBool("ignore_hostname") - ignoreGlobalLabels := c.GetBool("ignore_global_labels") + ignoreHostname := config.Config.HTTP.IgnoreHostname + ignoreGlobalLabels := config.Config.HTTP.IgnoreGlobalLabels for i := 0; i < count; i++ { // 去除重复的数据 if duplicateLabelKey(req.Timeseries[i]) { diff --git a/conf/config.toml b/conf/config.toml index c9070434..17d3b8cf 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -26,6 +26,7 @@ providers = ["local"] # However, utilizing the concurrency setting can help mitigate this issue and optimize the response time. concurrency = -1 +# Setting http.ignore_global_labels = true if disabled report custom labels [global.labels] # region = "shanghai" # env = "localhost" @@ -80,6 +81,8 @@ enable = false address = ":9100" print_access = false run_mode = "release" +ignore_hostname = false +ignore_global_labels = false [ibex] enable = false diff --git a/config/config.go b/config/config.go index 888ad696..8db7003f 100644 --- a/config/config.go +++ b/config/config.go @@ -65,15 +65,17 @@ type WriterOption struct { } type HTTP struct { - Enable bool `toml:"enable"` - Address string `toml:"address"` - PrintAccess bool `toml:"print_access"` - RunMode string `toml:"run_mode"` - CertFile string `toml:"cert_file"` - KeyFile string `toml:"key_file"` - ReadTimeout int `toml:"read_timeout"` - WriteTimeout int `toml:"write_timeout"` - IdleTimeout int `toml:"idle_timeout"` + Enable bool `toml:"enable"` + Address string `toml:"address"` + PrintAccess bool `toml:"print_access"` + RunMode string `toml:"run_mode"` + IgnoreHostname bool `toml:"ignore_hostname"` + IgnoreGlobalLabels bool `toml:"ignore_global_labels"` + CertFile string `toml:"cert_file"` + KeyFile string `toml:"key_file"` + ReadTimeout int `toml:"read_timeout"` + WriteTimeout int `toml:"write_timeout"` + IdleTimeout int `toml:"idle_timeout"` } type IbexConfig struct {