diff --git a/charts/azuremonitor-containers/templates/omsagent-daemonset.yaml b/charts/azuremonitor-containers/templates/omsagent-daemonset.yaml index 5bd8bdf79..3acfdb4a2 100644 --- a/charts/azuremonitor-containers/templates/omsagent-daemonset.yaml +++ b/charts/azuremonitor-containers/templates/omsagent-daemonset.yaml @@ -103,6 +103,14 @@ spec: {{- end }} - name: ISTEST value: {{ .Values.omsagent.ISTEST | quote }} + {{ if .Values.omsagent.isArcACluster }} + - name: IS_ARCA_CLUSTER + value: {{ .Values.omsagent.isArcACluster | quote }} + {{- end }} + {{- if ne .Values.omsagent.metricsEndpoint "" }} + - name: CUSTOM_METRICS_ENDPOINT + value: {{ .Values.omsagent.metricsEndpoint | quote }} + {{- end }} securityContext: privileged: true ports: diff --git a/charts/azuremonitor-containers/templates/omsagent-deployment.yaml b/charts/azuremonitor-containers/templates/omsagent-deployment.yaml index a0abb0f57..b5b239af0 100644 --- a/charts/azuremonitor-containers/templates/omsagent-deployment.yaml +++ b/charts/azuremonitor-containers/templates/omsagent-deployment.yaml @@ -89,6 +89,14 @@ spec: value: {{ .Values.omsagent.sidecarscraping | quote }} - name: ISTEST value: {{ .Values.omsagent.ISTEST | quote }} + {{ if .Values.omsagent.isArcACluster }} + - name: IS_ARCA_CLUSTER + value: {{ .Values.omsagent.isArcACluster | quote }} + {{- end }} + {{- if ne .Values.omsagent.metricsEndpoint "" }} + - name: CUSTOM_METRICS_ENDPOINT + value: {{ .Values.omsagent.metricsEndpoint | quote }} + {{- end }} securityContext: privileged: true ports: diff --git a/charts/azuremonitor-containers/values.yaml b/charts/azuremonitor-containers/values.yaml index 480e7040c..91b8270cd 100644 --- a/charts/azuremonitor-containers/values.yaml +++ b/charts/azuremonitor-containers/values.yaml @@ -49,6 +49,9 @@ omsagent: # This flag used to determine whether to use AAD MSI auth or not for Arc K8s cluster useAADAuth: false + # This flag used to determine whether this cluster is connected to ArcA control plane. This value will be setup before pushed into on-premise ArcA ACR. + isArcACluster: false + ## To get your workspace id and key do the following ## You can create a Azure Loganalytics workspace from portal.azure.com and get its ID & PRIMARY KEY from 'Advanced Settings' tab in the Ux. @@ -57,6 +60,8 @@ omsagent: key: domain: opinsights.azure.com proxy: + # This metricsEndpoint used to define the endpoint custom metrics emit to. If not defined, default public Azure monitoring endpoint '{aks_region}.monitoring.azure.com' will be used. + metricsEndpoint: env: clusterName: ## Applicable for only managed clusters hosted in Azure diff --git a/source/plugins/ruby/CustomMetricsUtils.rb b/source/plugins/ruby/CustomMetricsUtils.rb index fd9290b78..77675950c 100644 --- a/source/plugins/ruby/CustomMetricsUtils.rb +++ b/source/plugins/ruby/CustomMetricsUtils.rb @@ -13,6 +13,11 @@ def check_custom_metrics_availability if aks_region.to_s.empty? || aks_resource_id.to_s.empty? return false # This will also take care of AKS-Engine Scenario. AKS_REGION/AKS_RESOURCE_ID is not set for AKS-Engine. Only ACS_RESOURCE_NAME is set end + # If this is cluster is connected to ArcA control plane and metrics endpoint provided, custom metrics shall be emitted. + is_arca_cluster = ENV['IS_ARCA_CLUSTER'] + if is_arca_cluster.to_s.downcase == "true" && !ENV['CUSTOM_METRICS_ENDPOINT'].to_s.empty? + return true + end return aks_cloud_environment.to_s.downcase == 'azurepubliccloud' end diff --git a/source/plugins/ruby/out_mdm.rb b/source/plugins/ruby/out_mdm.rb index d850d93e5..e882f5ec7 100644 --- a/source/plugins/ruby/out_mdm.rb +++ b/source/plugins/ruby/out_mdm.rb @@ -26,7 +26,8 @@ def initialize @@token_resource_audience = "https://monitor.azure.com/" @@grant_type = "client_credentials" @@azure_json_path = "/etc/kubernetes/host/azure.json" - @@post_request_url_template = "https://%{aks_region}.monitoring.azure.com%{aks_resource_id}/metrics" + @@public_metrics_endpoint_template = "https://%{aks_region}.monitoring.azure.com" + @@post_request_url_template = "%{metrics_endpoint}%{aks_resource_id}/metrics" @@aad_token_url_template = "https://login.microsoftonline.com/%{tenant_id}/oauth2/token" # msiEndpoint is the well known endpoint for getting MSI authentications tokens @@ -98,7 +99,16 @@ def start if aks_resource_id.downcase.include?("microsoft.kubernetes/connectedclusters") @isArcK8sCluster = true end - @@post_request_url = @@post_request_url_template % { aks_region: aks_region, aks_resource_id: aks_resource_id } + + # If CUSTOM_METRICS_ENDPOINT provided, the url format shall be validated before emitting metrics into given endpoint. + custom_metrics_endpoint = ENV['CUSTOM_METRICS_ENDPOINT'] + if !custom_metrics_endpoint.to_s.empty? + metrics_endpoint = custom_metrics_endpoint.strip + URI.parse(metrics_endpoint) + else + metrics_endpoint = @@public_metrics_endpoint_template % { aks_region: aks_region } + end + @@post_request_url = @@post_request_url_template % { metrics_endpoint: metrics_endpoint, aks_resource_id: aks_resource_id } @post_request_uri = URI.parse(@@post_request_url) proxy = (ProxyUtils.getProxyConfiguration) if proxy.nil? || proxy.empty?