Skip to content
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
9 changes: 5 additions & 4 deletions Dev Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ to preserve the overall 15-second metric-scrape limit; upstream's
[1.40 documentation](https://github.com/influxdata/telegraf/blob/e9017dc3266369d6fa185e0e130af1d1d4021ce9/plugins/inputs/prometheus/README.md#L152-L157)
explains that `response_timeout` now covers headers only, unlike the
[1.24.2 client timeout](https://github.com/influxdata/telegraf/blob/9550e7a533dd00632e14435e87ed3eb4b04832c6/plugins/inputs/prometheus/prometheus.go#L254-L261).
Procstat uses `tag_with = ["pid"]` to retain PID tags. Existing `fieldpass`/`fielddrop`
names are unchanged on both OSes because
[1.40 still parses them](https://github.com/influxdata/telegraf/blob/e9017dc3266369d6fa185e0e130af1d1d4021ce9/config/config.go#L1649-L1687).
Linux rendering remains unchanged. Run `ruby build/common/installer/scripts/tomlparser-prom-customconfig_test.rb`
Procstat uses `tag_with = ["pid"]` to retain PID tags. Both OSes render
`fieldinclude`/`fieldexclude` instead of the deprecated `fieldpass`/`fielddrop`
Telegraf options. The public ConfigMap keys remain `fieldpass`/`fielddrop` for
backward compatibility; the shared parser maps them to the current Telegraf names.
Run `ruby build/common/installer/scripts/tomlparser-prom-customconfig_test.rb`
for rendering coverage with and without namespace filters. On Windows, set
`TELEGRAF_WINDOWS_BINARY` to the extracted `telegraf.exe` to also load the generated
configs with that binary in bounded `--test` mode, without Kubernetes access or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu
new_contents = new_contents.gsub("$AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_FIELD_SELECTOR", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_FIELD_SELECTOR")
new_contents = new_contents.gsub("$AZMON_TELEGRAF_CUSTOM_PROM_SCRAPE_SCOPE", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_TELEGRAF_CUSTOM_PROM_SCRAPE_SCOPE")

timeout_config_key = "timeout"

pluginConfigsWithNamespaces = ""
podScrapeScope = (@controller.casecmp(@replicaset) == 0) ? "cluster" : "node"
monitorKubernetesPodsNamespaces.each do |namespace|
Expand All @@ -208,11 +206,11 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu
monitor_kubernetes_pods_namespace = #{toTomlBasicString(namespace)}
kubernetes_label_selector = #{toTomlBasicString(kubernetesLabelSelectors)}
kubernetes_field_selector = #{toTomlBasicString(kubernetesFieldSelectors)}
fieldpass = #{fieldPassSetting}
fielddrop = #{fieldDropSetting}
fieldinclude = #{fieldPassSetting}
fieldexclude = #{fieldDropSetting}
metric_version = #{@metricVersion}
url_tag = #{toTomlBasicString(@urlTag)}
#{timeout_config_key} = #{toTomlBasicString(@responseTimeout)}
timeout = #{toTomlBasicString(@responseTimeout)}
tls_ca = #{toTomlBasicString(@tlsCa)}
insecure_skip_verify = #{@insecureSkipVerify}\n"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,24 @@ def test_kubernetes_namespace_validation
result = run_parser(scenario, configmap_for(scenario, "fieldpass = ['''#{BREAKOUT}''']"))
assert_no_injected_plugins(scenario, result[:conf], "the #{scenario} fieldpass array")
# The value survives, but only as a single escaped string.
assert_includes collect_values(result[:conf], "fieldpass"), BREAKOUT
assert_includes collect_values(result[:conf], "fieldinclude"), BREAKOUT
end

define_method("test_fielddrop_breakout_is_neutralized_#{scenario}") do
result = run_parser(scenario, configmap_for(scenario, "fielddrop = ['''#{BREAKOUT}''']"))
assert_no_injected_plugins(scenario, result[:conf], "the #{scenario} fielddrop array")
assert_includes collect_values(result[:conf], "fielddrop"), BREAKOUT
assert_includes collect_values(result[:conf], "fieldexclude"), BREAKOUT
end

define_method("test_valid_settings_are_preserved_#{scenario}") do
result = run_parser(scenario, configmap_for(scenario, "interval = \"45s\"\nfieldpass = [\"a\",\"b\"]"))
result = run_parser(scenario, configmap_for(scenario, "interval = \"45s\"\nfieldpass = [\"a\",\"b\"]\nfielddrop = [\"c\"]"))
assert_includes result[:conf], "interval = \"45s\"", "a valid interval must be preserved"
assert_includes result[:conf], "fieldpass = [\"a\",\"b\"]", "array formatting must be unchanged"
assert_includes result[:conf], "fieldinclude = [\"a\",\"b\"]", "array formatting must be unchanged"
assert_includes result[:conf], "fieldexclude = [\"c\"]", "array formatting must be unchanged"
parse_generated_toml(result[:conf])["inputs"]["prometheus"].each do |plugin|
refute plugin.key?("fieldpass")
refute plugin.key?("fielddrop")
end
assert_no_injected_plugins(scenario, result[:conf], "a benign #{scenario} configuration")
end
end
Expand Down Expand Up @@ -333,8 +338,10 @@ def test_namespace_plugins_are_generated_for_valid_namespaces
assert_equal "scrapeUrl", plugin["url_tag"]
assert_equal "pod_namespace", plugin["pod_namespace_label_name"]
assert_equal (scenario == :replicaset ? "cluster" : "node"), plugin["pod_scrape_scope"]
assert_equal ["requests_total"], plugin["fieldpass"]
assert_equal ["debug_total"], plugin["fielddrop"]
assert_equal ["requests_total"], plugin["fieldinclude"]
assert_equal ["debug_total"], plugin["fieldexclude"]
refute plugin.key?("fieldpass")
refute plugin.key?("fielddrop")
assert_equal "app=metrics", plugin["kubernetes_label_selector"]
assert_equal "spec.nodeName=test-node", plugin["kubernetes_field_selector"]
end
Expand Down Expand Up @@ -375,6 +382,7 @@ def test_windows_rendered_configs_load_in_packaged_telegraf
output = readers.map(&:value).join("\n")
assert completed, "Telegraf config smoke test exceeded 20 seconds"
assert process.value.success?, "Telegraf rejected the rendered config for #{namespaces.inspect}: #{output}"
refute_match(/Deprecation(?:Error|Warning).*"(?:fieldpass|fielddrop|pid_tag)"/, output)
end
end
end
Expand All @@ -388,7 +396,8 @@ def test_windows_process_metrics_config_preserves_pid_tags_and_fields
config["inputs"]["procstat"].each do |plugin|
assert_equal ["pid"], plugin["tag_with"]
refute plugin.key?("pid_tag")
assert_equal ["cpu_usage", "memory_rss"], plugin["fieldpass"]
assert_equal ["cpu_usage", "memory_rss"], plugin["fieldinclude"]
refute plugin.key?("fieldpass")
assert_equal "native", plugin["pid_finder"]
assert_equal "agent_telemetry", plugin["name_override"]
assert_equal "t.azm.ms/", plugin["name_prefix"]
Expand All @@ -400,6 +409,51 @@ def test_windows_process_metrics_config_preserves_pid_tags_and_fields
)
end

def test_linux_process_metrics_config_preserves_pid_tags_and_fields
path = File.join(REPO_ROOT, "build/linux/installer/conf/telegraf-ama-logs-process-metrics.conf")
config = Tomlrb.load_file(path)
assert_equal({ "telegraf_role" => "ama-logs-process-metrics" }, config["global_tags"])
assert_equal 9, config["inputs"]["procstat"].length
config["inputs"]["procstat"].each do |plugin|
assert_equal ["pid"], plugin["tag_with"]
refute plugin.key?("pid_tag")
assert_equal ["cpu_usage", "memory_rss"], plugin["fieldinclude"]
refute plugin.key?("fieldpass")
assert_equal "native", plugin["pid_finder"]
assert_equal "agent_telemetry", plugin["name_override"]
assert_equal "t.azm.ms/", plugin["name_prefix"]
assert_equal "$CONTROLLER_TYPE", plugin["tags"]["ControllerType"]
# ORDER matters: renamed keys must stay above [inputs.procstat.tags], otherwise
# TOML binds them to the nested table and telegraf never sees them.
["tag_with", "fieldinclude"].each do |key|
refute plugin["tags"].key?(key), "#{key} must not be absorbed by [inputs.procstat.tags]"
end
end
assert_equal(
{ "ai.cloud.role" => "ControllerType", "ai.cloud.roleInstance" => "PodName" },
config["outputs"]["application_insights"].first["context_tag_sources"]
)
end

# Telegraf treats an unrecognized plugin option as a fatal config-load error, so a single
# reintroduced legacy name silently stops the agent from loading that configuration.
REMOVED_TELEGRAF_OPTIONS = %w[fieldpass fielddrop pid_tag ignore_protocol_stats].freeze

def test_shipped_telegraf_templates_do_not_use_removed_options
templates = Dir.glob(File.join(REPO_ROOT, "build/{linux,windows}/installer/conf/telegraf*.conf")).sort
refute_empty templates, "expected to find shipped telegraf templates"

templates.each do |path|
offenders = File.readlines(path).each_with_index.filter_map do |line, index|
stripped = line.strip
next if stripped.empty? || stripped.start_with?("#")
option = REMOVED_TELEGRAF_OPTIONS.find { |name| stripped =~ /\A#{name}\s*=/ }
"#{File.basename(path)}:#{index + 1}: #{stripped}" if option
end
assert_empty offenders, "removed telegraf options must not be used in shipped templates"
end
end

def test_selectors_are_escaped_in_generated_namespace_plugins
body = "monitor_kubernetes_pods = true\n" \
"monitor_kubernetes_pods_namespaces = [\"default\"]\n" \
Expand All @@ -411,6 +465,28 @@ def test_selectors_are_escaped_in_generated_namespace_plugins
assert_equal BREAKOUT, plugin["kubernetes_label_selector"]
end

def test_namespace_filters_preserve_modern_keys_and_escaping
[:replicaset, :sidecar, :windows].each do |scenario|
body = "monitor_kubernetes_pods = true\n" \
"monitor_kubernetes_pods_namespaces = [\"default\"]\n" \
"fieldpass = ['''#{BREAKOUT}''']\n" \
"fielddrop = ['''#{BREAKOUT}''']\n" \
"kubernetes_label_selector = '''#{BREAKOUT}'''\n" \
"kubernetes_field_selector = '''#{BREAKOUT}'''"
result = run_parser(scenario, configmap_for(scenario, body))
assert_no_injected_plugins(scenario, result[:conf], "namespaced #{scenario} filters")
plugin = parse_generated_toml(result[:conf])["inputs"]["prometheus"]
.find { |entry| entry["monitor_kubernetes_pods_namespace"] == "default" }
refute_nil plugin
assert_equal [BREAKOUT], plugin["fieldinclude"]
assert_equal [BREAKOUT], plugin["fieldexclude"]
assert_equal BREAKOUT, plugin["kubernetes_label_selector"]
assert_equal BREAKOUT, plugin["kubernetes_field_selector"]
assert_equal(scenario == :replicaset ? "cluster" : "node", plugin["pod_scrape_scope"])
["fieldpass", "fielddrop"].each { |key| refute plugin.key?(key), "#{scenario} must not emit #{key}" }
end
end

def monitored_namespaces(conf)
parse_generated_toml(conf)["inputs"]["prometheus"]
.map { |plugin| plugin["monitor_kubernetes_pods_namespace"] }
Expand Down
36 changes: 18 additions & 18 deletions build/linux/installer/conf/telegraf-ama-logs-process-metrics.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
exe = "mdsd"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -38,9 +38,9 @@
exe = "fluent-bit"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -54,9 +54,9 @@
pattern = "telegraf(-rs|-prom-side-car)?.conf"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -70,9 +70,9 @@
pattern = "telegraf-ama-logs-process-metrics.conf"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -85,9 +85,9 @@
name_prefix = "t.azm.ms/"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -104,9 +104,9 @@
exe = "crond"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -120,9 +120,9 @@
exe = "inotifywait"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -135,9 +135,9 @@
name_prefix = "t.azm.ms/"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand All @@ -154,9 +154,9 @@
pattern = "main.sh"
interval = "60s"
pid_finder = "native"
pid_tag = true
tag_with = ["pid"]
name_override = "agent_telemetry"
fieldpass = ["cpu_usage", "memory_rss"]
fieldinclude = ["cpu_usage", "memory_rss"]
[inputs.procstat.tags]
Computer = "placeholder_hostname"
PodName = "placeholder_podname"
Expand Down
4 changes: 2 additions & 2 deletions build/linux/installer/conf/telegraf-prom-side-car.conf
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@
$AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_LABEL_SELECTOR
$AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_FIELD_SELECTOR

fieldpass = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDPASS
fielddrop = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDDROP
fieldinclude = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDPASS
fieldexclude = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDDROP

metric_version = 2
url_tag = "scrapeUrl"
Expand Down
6 changes: 3 additions & 3 deletions build/linux/installer/conf/telegraf-rs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@
$AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_LABEL_SELECTOR
$AZMON_TELEGRAF_CUSTOM_PROM_KUBERNETES_FIELD_SELECTOR

fieldpass = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDPASS
fielddrop = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDDROP
fieldinclude = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDPASS
fieldexclude = $AZMON_TELEGRAF_CUSTOM_PROM_FIELDDROP

metric_version = 2
url_tag = "scrapeUrl"
Expand Down Expand Up @@ -641,7 +641,7 @@ $AZMON_TELEGRAF_OSM_PROM_PLUGINS
#name_prefix="container.azm.ms/"
## An array of urls to scrape metrics from.
urls = $AZMON_INTEGRATION_NPM_METRICS_URL_LIST_CLUSTER
fielddrop = $AZMON_INTEGRATION_NPM_METRICS_DROP_LIST_CLUSTER
fieldexclude = $AZMON_INTEGRATION_NPM_METRICS_DROP_LIST_CLUSTER

metric_version = 2
url_tag = "scrapeUrl"
Expand Down
21 changes: 10 additions & 11 deletions build/linux/installer/conf/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@

## Ignore mount points by filesystem type.
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs", "cifs", "fuse"]
fieldpass = ["free", "used", "used_percent"]
fieldinclude = ["free", "used", "used_percent"]
taginclude = ["device","path","hostName"]
# Below due to Bug - https://github.com/influxdata/telegraf/issues/5615
# ORDER matters here!! - i.e the below should be the LAST modifier
Expand Down Expand Up @@ -489,7 +489,7 @@
## The typical use case is for LVM volumes, to get the VG/LV name instead of
## the near-meaningless DM-0 name.
# name_templates = ["$ID_FS_LABEL","$DM_VG_NAME/$DM_LV_NAME"]
fieldpass = ["reads", "read_bytes", "read_time", "writes", "write_bytes", "write_time", "io_time", "iops_in_progress"]
fieldinclude = ["reads", "read_bytes", "read_time", "writes", "write_bytes", "write_time", "io_time", "iops_in_progress"]
taginclude = ["name","hostName"]

# Read metrics about network interface usage
Expand All @@ -501,12 +501,11 @@
##
# interfaces = ["eth0"]
##
## On linux systems telegraf also collects protocol stats.
## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
## NOTE: protocol stats collection was removed in telegraf 1.37.0 and the
## ignore_protocol_stats option became a no-op (removed in 1.45.0), so it is
## no longer set here. Current behavior matches the previous "true" setting.
##
ignore_protocol_stats = true
##
fieldpass = ["bytes_recv", "bytes_sent", "err_in", "err_out"]
fieldinclude = ["bytes_recv", "bytes_sent", "err_in", "err_out"]
taginclude = ["interface","hostName"]

# net plugin is collecting loopback interface metrics by default from telegraf 1.34.3
Expand Down Expand Up @@ -652,7 +651,7 @@
name_prefix="container.azm.ms/"
## An array of urls to scrape metrics from.
urls = ["$CADVISOR_METRICS_URL"]
fieldpass = ["$KUBELET_RUNTIME_OPERATIONS_METRIC", "$KUBELET_RUNTIME_OPERATIONS_ERRORS_METRIC", "$KUBELET_RUNTIME_OPERATIONS_TOTAL_METRIC", "$KUBELET_RUNTIME_OPERATIONS_ERRORS_TOTAL_METRIC"]
fieldinclude = ["$KUBELET_RUNTIME_OPERATIONS_METRIC", "$KUBELET_RUNTIME_OPERATIONS_ERRORS_METRIC", "$KUBELET_RUNTIME_OPERATIONS_TOTAL_METRIC", "$KUBELET_RUNTIME_OPERATIONS_ERRORS_TOTAL_METRIC"]

metric_version = 2
url_tag = "scrapeUrl"
Expand Down Expand Up @@ -697,7 +696,7 @@

# <= 1.18: metric name is kubelet_running_pod_count
# >= 1.19: metric name changed to kubelet_running_pods
fieldpass = ["kubelet_running_pod_count","kubelet_running_pods","volume_manager_total_volumes", "kubelet_node_config_error", "process_resident_memory_bytes", "process_cpu_seconds_total"]
fieldinclude = ["kubelet_running_pod_count","kubelet_running_pods","volume_manager_total_volumes", "kubelet_node_config_error", "process_resident_memory_bytes", "process_cpu_seconds_total"]

metric_version = 2
url_tag = "scrapeUrl"
Expand All @@ -721,9 +720,9 @@
## An array of urls to scrape metrics from.
urls = $AZMON_DS_PROM_URLS

fieldpass = $AZMON_DS_PROM_FIELDPASS
fieldinclude = $AZMON_DS_PROM_FIELDPASS

fielddrop = $AZMON_DS_PROM_FIELDDROP
fieldexclude = $AZMON_DS_PROM_FIELDDROP

metric_version = 2
url_tag = "scrapeUrl"
Expand Down
2 changes: 1 addition & 1 deletion build/linux/installer/scripts/tomlparser-osm-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def replaceOsmTelegrafConfigPlaceHolders
monitor_kubernetes_pods = true
pod_scrape_scope = \"#{(@controllerType.casecmp(@replicaset) == 0) ? "cluster" : "node"}\"
monitor_kubernetes_pods_namespace = \"#{namespace}\"
fieldpass = #{@fieldPassSetting}
fieldinclude = #{@fieldPassSetting}
metric_version = #{@metricVersion}
url_tag = \"#{@urlTag}\"
bearer_token = \"#{@bearerToken}\"
Expand Down
Loading
Loading