Skip to content

Commit c3136e4

Browse files
authored
add integration for azure subnet ip usage (#774)
* add integration for azure cni subnet ip usage * exclude unfixed cve & remove fixed one
1 parent 315470a commit c3136e4

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

.trivyignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ CVE-2021-31799
1616
CVE-2021-28965
1717

1818
#dpkg vulnerability in ubuntu
19-
CVE-2022-1664
19+
CVE-2022-1304

build/linux/installer/conf/telegraf.conf

+20-1
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,23 @@
805805
# ClusterName = "$TELEMETRY_CLUSTER_NAME"
806806
# ClusterType = "$TELEMETRY_CLUSTER_TYPE"
807807
# Computer = "placeholder_hostname"
808-
# ControllerType = "$CONTROLLER_TYPE"
808+
# ControllerType = "$CONTROLLER_TYPE"
809+
810+
## ip subnet usage
811+
[[inputs.prometheus]]
812+
#name_prefix="container.azm.ms/"
813+
## An array of urls to scrape metrics from.
814+
urls = $AZMON_INTEGRATION_SUBNET_IP_USAGE_METRICS_URL_LIST_NODE
815+
816+
metric_version = 2
817+
url_tag = "scrapeUrl"
818+
819+
## Use bearer token for authorization. ('bearer_token' takes priority)
820+
bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
821+
822+
## Specify timeout duration for slower prometheus clients (default is 3s)
823+
response_timeout = "15s"
824+
825+
## Optional TLS Config
826+
tls_ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
827+
insecure_skip_verify = true

build/linux/installer/scripts/tomlparser-npm-config.rb

+38-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
@npm_node_urls = "[\"http://$NODE_IP:10091/node-metrics\"]"
1919
@npm_cluster_urls="[\"http://npm-metrics-cluster-service.kube-system:9000/cluster-metrics\"]"
2020
@npm_basic_drop_metrics_cluster = "[\"npm_ipset_counts\"]"
21+
@collect_subnet_ip_usage_metrics = false
22+
@azure_subnet_ip_usage_metrics_node_urls = "[\"http://$NODE_IP:10092/metrics\"]"
23+
@azure_subnet_ip_usage_default_setting = "[]"
2124
@tgfConfigFileDS = "/etc/opt/microsoft/docker-cimprov/telegraf.conf"
2225
@tgfConfigFileRS = "/etc/opt/microsoft/docker-cimprov/telegraf-rs.conf"
2326
@replicaset = "replicaset"
@@ -43,6 +46,21 @@ def parseConfigMap
4346

4447
# Use the ruby structure created after config parsing to set the right values to be used as environment variables
4548
def populateSettingValuesFromConfigMap(parsedConfig)
49+
begin
50+
if !parsedConfig.nil? && !parsedConfig[:integrations].nil? && !parsedConfig[:integrations][:azure_subnet_ip_usage].nil? && !parsedConfig[:integrations][:azure_subnet_ip_usage][:enabled].nil?
51+
azure_subnet_ip_usage_metrics = parsedConfig[:integrations][:azure_subnet_ip_usage][:enabled].to_s
52+
puts "config::azure_subnet_ip_usage::got:integrations.azure_subnet_ip_usage.enabled='#{azure_subnet_ip_usage_metrics}'"
53+
if !azure_subnet_ip_usage_metrics.nil? && azure_subnet_ip_usage_metrics.strip.casecmp("true") == 0
54+
@collect_azure_subnet_ip_usage_metrics = true
55+
else
56+
@collect_azure_subnet_ip_usage_metrics = false
57+
end
58+
puts "config::azure_subnet_ip_usage::got:integrations.azure_subnet_ip_usage.enabled=#{@collect_azure_subnet_ip_usage_metrics}"
59+
end
60+
rescue => errorStr
61+
puts "config::npm::error:Exception while reading config settings for azure_subnet_ip_usage setting - #{errorStr}, using defaults"
62+
@collect_azure_subnet_ip_usage_metrics = false
63+
end
4664
begin
4765
if !parsedConfig.nil? && !parsedConfig[:integrations].nil? && !parsedConfig[:integrations][:azure_network_policy_manager].nil? && !parsedConfig[:integrations][:azure_network_policy_manager][:collect_advanced_metrics].nil?
4866
advanced_npm_metrics = parsedConfig[:integrations][:azure_network_policy_manager][:collect_advanced_metrics].to_s
@@ -76,18 +94,19 @@ def populateSettingValuesFromConfigMap(parsedConfig)
7694
end
7795

7896
@configSchemaVersion = ENV["AZMON_AGENT_CFG_SCHEMA_VERSION"]
79-
puts "****************Start NPM Config Processing********************"
97+
puts "****************Start NPM & subnet ip usage integrations Config Processing********************"
8098
if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it
8199
configMapSettings = parseConfigMap
82100
if !configMapSettings.nil?
83101
populateSettingValuesFromConfigMap(configMapSettings)
84102
end
85103
else
86104
if (File.file?(@configMapMountPath))
87-
ConfigParseErrorLogger.logError("config::npm::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults, please use supported schema version")
105+
ConfigParseErrorLogger.logError("config::integrations::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults, please use supported schema version")
88106
end
89107
@collect_basic_npm_metrics = false
90108
@collect_advanced_npm_metrics = false
109+
@collect_azure_subnet_ip_usage_metrics = false
91110
end
92111

93112

@@ -99,7 +118,7 @@ def populateSettingValuesFromConfigMap(parsedConfig)
99118
tgfConfigFile = @tgfConfigFileRS
100119
end
101120

102-
#replace place holders in configuration file
121+
#replace place holders in configuration file for npm integration
103122
tgfConfig = File.read(tgfConfigFile) #read returns only after closing the file
104123

105124
if @collect_advanced_npm_metrics == true
@@ -116,8 +135,19 @@ def populateSettingValuesFromConfigMap(parsedConfig)
116135
tgfConfig = tgfConfig.gsub("$AZMON_INTEGRATION_NPM_METRICS_DROP_LIST_CLUSTER", @npm_default_setting)
117136
end
118137

138+
#replace place holders in configuration file for subnet ip usage integration
139+
if @collect_azure_subnet_ip_usage_metrics == true
140+
tgfConfig = tgfConfig.gsub("$AZMON_INTEGRATION_SUBNET_IP_USAGE_METRICS_URL_LIST_NODE", @azure_subnet_ip_usage_metrics_node_urls)
141+
else
142+
tgfConfig = tgfConfig.gsub("$AZMON_INTEGRATION_SUBNET_IP_USAGE_METRICS_URL_LIST_NODE", @azure_subnet_ip_usage_default_setting)
143+
end
144+
145+
File.open(tgfConfigFile, "w") { |file| file.puts tgfConfig } # 'file' will be closed here after it goes out of scope
146+
puts "config::integrations::Successfully substituted the placeholders for integrations into #{tgfConfigFile} file for #{controller}"
147+
148+
119149
File.open(tgfConfigFile, "w") { |file| file.puts tgfConfig } # 'file' will be closed here after it goes out of scope
120-
puts "config::npm::Successfully substituted the NPM placeholders into #{tgfConfigFile} file for #{controller}"
150+
puts "config::integrations::Successfully substituted the integrations placeholders into #{tgfConfigFile} file for #{controller}"
121151

122152
# Write the telemetry to file, so that they can be set as environment variables
123153
telemetryFile = File.open("integration_npm_config_env_var", "w")
@@ -128,9 +158,12 @@ def populateSettingValuesFromConfigMap(parsedConfig)
128158
elsif @collect_basic_npm_metrics == true
129159
telemetryFile.write("export TELEMETRY_NPM_INTEGRATION_METRICS_BASIC=1\n")
130160
end
161+
if @collect_azure_subnet_ip_usage_metrics == true
162+
telemetryFile.write("export TELEMETRY_SUBNET_IP_USAGE_INTEGRATION_METRICS=1\n")
163+
end
131164
# Close file after writing all environment variables
132165
telemetryFile.close
133166
else
134-
puts "config::npm::Exception while opening file for writing NPM telemetry environment variables"
167+
puts "config::integrations::Exception while opening file for writing Integrations telemetry environment variables"
135168
puts "****************End NPM Config Processing********************"
136169
end

kubernetes/container-azm-ms-agentconfig.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ data:
141141
[integrations.azure_network_policy_manager]
142142
collect_basic_metrics = false
143143
collect_advanced_metrics = false
144+
[integrations.azure_subnet_ip_usage]
145+
enabled = false
144146
145147
# Doc - https://github.com/microsoft/Docker-Provider/blob/ci_prod/Documentation/AgentSettings/ReadMe.md
146148
agent-settings: |-

source/plugins/ruby/CAdvisorMetricsAPIClient.rb

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CAdvisorMetricsAPIClient
3636
@containerLogsRoute = ENV["AZMON_CONTAINER_LOGS_ROUTE"]
3737
@npmIntegrationBasic = ENV["TELEMETRY_NPM_INTEGRATION_METRICS_BASIC"]
3838
@npmIntegrationAdvanced = ENV["TELEMETRY_NPM_INTEGRATION_METRICS_ADVANCED"]
39+
@subnetIpUsageMetrics = ENV["TELEMETRY_SUBNET_IP_USAGE_INTEGRATION_METRICS"]
3940

4041
@os_type = ENV["OS_TYPE"]
4142
if !@os_type.nil? && !@os_type.empty? && @os_type.strip.casecmp("windows") == 0
@@ -282,6 +283,10 @@ def getContainerCpuMetricItems(metricJSON, hostName, cpuMetricNameToCollect, met
282283
elsif (!@npmIntegrationBasic.nil? && !@npmIntegrationBasic.empty?)
283284
telemetryProps["int-npm-b"] = "1"
284285
end
286+
# telemetry for subnet ip usage integration
287+
if (!@subnetIpUsageMetrics.nil? && !@subnetIpUsageMetrics.empty?)
288+
telemetryProps["int-ipsubnetusage"] = "1"
289+
end
285290
#telemetry for Container log schema version clusterContainerLogSchemaVersion
286291
if (!@clusterContainerLogSchemaVersion.nil? && !@clusterContainerLogSchemaVersion.empty?)
287292
telemetryProps["containerLogVer"] = @clusterContainerLogSchemaVersion

0 commit comments

Comments
 (0)