@@ -8,25 +8,25 @@ module ApiClient
88 # Client contains the implementation for a Prometheus compatible api_client,
99 # With special labels for the cadvisor job.
1010 module Cadvisor
11- # Add labels to simple query variables.
11+ # Create a Prometheus API client:
1212 #
13- # Example:
14- # "cpu_usage" => "cpu_usage{labels...}"
15- # "sum(cpu_usage)" => "sum(cpu_usage{labels...})"
16- # "rate(cpu_usage[5m])" => "rate(cpu_usage{labels...}[5m])"
13+ # @param [Hash] options
14+ # @option options [Hash] :url String base URL.
15+ # @option options [Hash] :params URI query unencoded key/value pairs.
16+ # @option options [Hash] :headers Unencoded HTTP header key/value pairs.
17+ # @option options [Hash] :request Request options.
18+ # @option options [Hash] :ssl SSL options.
19+ # @option options [Hash] :proxy Proxy options.
1720 #
18- # Note:
19- # Not supporting more complex queries.
20- def self . update_query ( query , labels )
21- query . sub ( /(?<r>\[ .+\] )?(?<f>[)])?$/ , "{#{ labels } }\\ k<r>\\ k<f>" )
22- end
23-
24- # A client with special labels for node cadvisor metrics
21+ # A default client is created if options is omitted.
2522 class Node < Client
26- def initialize ( instance , region = 'infra' , zone = 'default' , args = { } )
23+ def initialize ( instance :, **options )
24+ region = options [ :region ] || 'infra'
25+ zone = options [ :zone ] || 'default'
26+
2727 @labels = "job=\" kubernetes-cadvisor\" ,region=\" #{ region } \" ," \
2828 "zone=\" #{ zone } \" ,instance=\" #{ instance } \" "
29- super ( args )
29+ super ( options )
3030 end
3131
3232 def query ( options )
@@ -42,13 +42,15 @@ def query_range(options)
4242
4343 # A client with special labels for pod cadvisor metrics
4444 class Pod < Client
45- def initialize ( pod_name , namespace = 'default' , region = 'infra' ,
46- zone = 'default' , args = { } )
45+ def initialize ( pod_name :, **options )
46+ namespace = options [ :namespace ] || 'default'
47+ region = options [ :region ] || 'infra'
48+ zone = options [ :zone ] || 'default'
4749
4850 @labels = "job=\" kubernetes-cadvisor\" ,region=\" #{ region } \" ," \
4951 "zone=\" #{ zone } \" ,namespace=\" #{ namespace } \" ," \
5052 "pod_name=\" #{ pod_name } \" ,container_name=\" POD\" "
51- super ( args )
53+ super ( options )
5254 end
5355
5456 def query ( options )
@@ -64,13 +66,15 @@ def query_range(options)
6466
6567 # A client with special labels for container cadvisor metrics
6668 class Container < Client
67- def initialize ( container_name , pod_name , namespace = 'default' ,
68- region = 'infra' , args = { } )
69+ def initialize ( container_name :, pod_name :, **options )
70+ namespace = args [ :namespace ] || 'default'
71+ region = options [ :region ] || 'infra'
72+ zone = options [ :zone ] || 'default'
6973
7074 @labels = "job=\" kubernetes-cadvisor\" ,region=\" #{ region } \" ," \
71- "namespace=\" #{ namespace } \" ," \
75+ "zone= \" #{ zone } \" , namespace=\" #{ namespace } \" ," \
7276 "pod_name=\" #{ pod_name } \" ,container_name=\" #{ container_name } \" "
73- super ( args )
77+ super ( options )
7478 end
7579
7680 def query ( options )
0 commit comments