Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.
Merged
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
21 changes: 20 additions & 1 deletion lib/fluent/plugin/in_kubernetes_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ def start
super

timer_execute :metric_scraper, @interval, &method(:scrape_metrics)
timer_execute :stats_metric_scraper, @interval, &method(:scrape_stats_metrics)
timer_execute :cadvisor_metric_scraper, @interval, &method(:scrape_cadvisor_metrics)
# It is done to optionally fetch from 'stats' for k8s version <1.21
if is_stats_endpoint_available?
timer_execute :stats_metric_scraper, @interval, &method(:scrape_stats_metrics)
else
log.info "'/stats' endpoint is not available. It has been deprecated since k8s v1.15, disabled since v1.18, and removed in v1.21 and onwards"
end
end

def close
Expand Down Expand Up @@ -642,6 +647,20 @@ def scrape_metrics
end
end

def is_stats_endpoint_available?
if @use_rest_client
response_stats = RestClient::Request.execute request_options_stats
else
@node_names.each do |node|
@node_name = node
response_stats = stats_proxy_api(node).get(@client.headers)
end
end
true
rescue RestClient::NotFound
false
end

def scrape_stats_metrics
if @use_rest_client
response_stats = RestClient::Request.execute request_options_stats
Expand Down