Skip to content

Commit

Permalink
reafactor(http_listener_v2): use hardcoded http_listener_v2_path tag …
Browse files Browse the repository at this point in the history
…to store path

Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
  • Loading branch information
Dominik Rosiek committed Jul 23, 2021
1 parent 84e7904 commit e70e6aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
20 changes: 20 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[agent]
interval = "2s"
flush_interval = "3s"

[[inputs.http_listener_v2]]
service_address = ":9888"
# path = "/prometheus.metrics.container"
path_tag = "path"
data_format = "prometheusremotewrite"
paths = ["/prometheus.metrics.controller-manager", "/prometheus.metrics.scheduler", "/prometheus.metrics.apiserver", "/prometheus.metrics.kubelet", "/prometheus.metrics.container", "/prometheus.metrics.container", "/prometheus.metrics.node", "/prometheus.metrics.operator.rule", "/prometheus.metrics", "/prometheus.metrics.control-plane.coredns", "/prometheus.metrics.control-plane.kube-etcd", "/prometheus.metrics.applications.nginx-ingress", "/prometheus.metrics.applications.nginx", "/prometheus.metrics.applications.redis", "/prometheus.metrics.applications.jmx", "/prometheus.metrics.applications.kafka", "/prometheus.metrics.applications.mysql", "/prometheus.metrics.applications.postgresql", "/prometheus.metrics.applications.apache"]

[[outputs.file]]
## Files to write to, "stdout" is a specially handled file.
files = ["stdout"]

## Data format to output.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
data_format = "prometheus"
7 changes: 5 additions & 2 deletions plugins/inputs/http_listener_v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ This is a sample configuration for the plugin.
service_address = ":8080"

## Path to listen to.
## This is depracated and will be appended to paths
## This option is deprecated and only available for backward-compatibility. Please use paths instead.
# path = "/telegraf"

## Paths to listen to.
# paths = ["/telegraf"]

## Save path as http_listener_v2_path tag if set to true
# path_tag = false

## HTTP methods to accept.
# methods = ["POST", "PUT"]

Expand Down Expand Up @@ -63,7 +66,7 @@ This is a sample configuration for the plugin.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "json"
data_format = "influx"
```

### Metrics:
Expand Down
22 changes: 10 additions & 12 deletions plugins/inputs/http_listener_v2/http_listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
const defaultMaxBodySize = 500 * 1024 * 1024

const (
body = "body"
query = "query"
body = "body"
query = "query"
pathTag = "http_listener_v2_path"
)

// TimeFunc provides a timestamp for the metrics
Expand All @@ -39,7 +40,7 @@ type HTTPListenerV2 struct {
ServiceAddress string `toml:"service_address"`
Path string `toml:"path"`
Paths []string `toml:"paths"`
PathTag string `toml:"path_tag"`
PathTag bool `toml:"path_tag"`
Methods []string `toml:"methods"`
DataSource string `toml:"data_source"`
ReadTimeout config.Duration `toml:"read_timeout"`
Expand Down Expand Up @@ -67,15 +68,14 @@ const sampleConfig = `
service_address = ":8080"
## Path to listen to.
## This is depracated and will be appended to paths
## This option is deprecated and only available for backward-compatibility. Please use paths instead.
# path = "/telegraf"
## Paths to listen to.
# paths = ["/telegraf"]
## Save path in path_tag
## Do not include path in tag if path_tag is an empty string
# path_tag = ""
## Save path as http_listener_v2_path tag if set to true
# path_tag = false
## HTTP methods to accept.
# methods = ["POST", "PUT"]
Expand All @@ -86,7 +86,7 @@ const sampleConfig = `
# write_timeout = "10s"
## Maximum allowed http request body size in bytes.
## 0 means to use the default of 524,288,00 bytes (500 mebibytes)
## 0 means to use the default of 524,288,000 bytes (500 mebibytes)
# max_body_size = "500MB"
## Part of the request to consume. Available options are "body" and
Expand Down Expand Up @@ -147,8 +147,6 @@ func (h *HTTPListenerV2) Start(acc telegraf.Accumulator) error {
h.WriteTimeout = config.Duration(time.Second * 10)
}

h.PathTag = strings.TrimSpace(h.PathTag)

// Append h.Path to h.Paths
h.Paths = append(h.Paths, h.Path)

Expand Down Expand Up @@ -267,8 +265,8 @@ func (h *HTTPListenerV2) serveWrite(res http.ResponseWriter, req *http.Request)
}
}

if h.PathTag != "" {
m.AddTag(h.PathTag, req.URL.Path)
if h.PathTag {
m.AddTag(pathTag, req.URL.Path)
}

h.acc.AddMetric(m)
Expand Down

0 comments on commit e70e6aa

Please sign in to comment.