From 185004eba3f1d6cc217dee7a05753a977258d251 Mon Sep 17 00:00:00 2001 From: ralongit Date: Sun, 21 Apr 2024 15:23:33 +0300 Subject: [PATCH 1/4] Add Kubernetes object logs --- config-templates/helm.json | 13 ++ configs/2-1-k8s-eks.json | 8 + configs/2-2-k8s-aks.json | 8 + configs/2-3-k8s-gke.json | 8 + configs/2-4-k8s-digitalocean.json | 8 + .../kubernetes/telemetry/metrics/metrics.bash | 10 + .../kubernetes/telemetry/metrics/metrics.bash | 10 + .../kubernetes/telemetry/metrics/metrics.bash | 10 + .../kubernetes/telemetry/metrics/metrics.bash | 10 + .../telemetry/metrics/functions.ps1 | 188 ++++++++++++++++++ .../kubernetes/telemetry/metrics/metrics.ps1 | 12 ++ .../telemetry/metrics/functions.ps1 | 188 ++++++++++++++++++ .../kubernetes/telemetry/metrics/metrics.ps1 | 12 ++ .../telemetry/metrics/functions.ps1 | 188 ++++++++++++++++++ .../kubernetes/telemetry/metrics/metrics.ps1 | 12 ++ .../telemetry/metrics/functions.ps1 | 187 +++++++++++++++++ .../kubernetes/telemetry/metrics/metrics.ps1 | 12 ++ .../k8s/datasource_metrics_utils.bash | 111 +++++++++++ .../k8s/datasource_metrics_utils.bash | 110 ++++++++++ 19 files changed, 1105 insertions(+) diff --git a/config-templates/helm.json b/config-templates/helm.json index 01ed8362c..d0fa6dc4d 100644 --- a/config-templates/helm.json +++ b/config-templates/helm.json @@ -75,6 +75,16 @@ "template": " --set logzio-k8s-telemetry.collector.mode=standalone \\", "condition": "$[?(@ == 'EKS')]", "targetElement": "datasources[?(@.name=='Kubernetes')].params[?(@.name=='isFargate')].value" + }, + { + "template": " --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true \\", + "targetElement": "datasources[?(@.name=='Kubernetes')].params[?(@.name=='isObjectLogs')].value" + }, + { + "template": " --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken='<>' \\" + }, + { + "template": " --set logzio-k8s-telemetry.secrets.LogzioRegion='<>' \\" } ] }, @@ -99,6 +109,9 @@ }, { "template": " --set logzio-k8s-telemetry.secrets.SpmToken='<>' \\" + }, + { + "template": " --set logzio-k8s-telemetry.serviceGraph.enabled=true \\" } ] } diff --git a/configs/2-1-k8s-eks.json b/configs/2-1-k8s-eks.json index a34adf571..161523428 100644 --- a/configs/2-1-k8s-eks.json +++ b/configs/2-1-k8s-eks.json @@ -70,6 +70,14 @@ "description": "", "hint": "Check this box if you want Logz.io Telemetry Collector to collect only the relevant system metrics to populate Kubernetes 360 and prebuilt dashboards. In addition, we will also collect application metrics that are exposed by your pods.", "value": true + }, + { + "type": "boolean", + "name": "isObjectLogs", + "label": "Collect correlated Kubernetes resource object logs", + "description": "", + "hint": "Check this box if you want Logz.io Telemetry Collector to collect Kubernetes resource object logs that correlate with metrics to populate Kubernetes 360 and prebuilt dashboards.", + "value": true } ], "dashboards": [ diff --git a/configs/2-2-k8s-aks.json b/configs/2-2-k8s-aks.json index 12accdbd5..13a2050d3 100644 --- a/configs/2-2-k8s-aks.json +++ b/configs/2-2-k8s-aks.json @@ -58,6 +58,14 @@ "hint": "Check this box if you want Logz.io Telemetry Collector to collect only the relevant system metrics to populate Kubernetes 360 and prebuilt dashboards. In addition, we will also collect application metrics that are exposed by your pods.", "value": true }, + { + "type": "boolean", + "name": "isObjectLogs", + "label": "Collect correlated Kubernetes resource object logs", + "description": "", + "hint": "Check this box if you want Logz.io Telemetry Collector to collect Kubernetes resource object logs that correlate with metrics to populate Kubernetes 360 and prebuilt dashboards.", + "value": true + }, { "type": "boolean", "name": "isWindows", diff --git a/configs/2-3-k8s-gke.json b/configs/2-3-k8s-gke.json index 273c089d8..6baaf54db 100644 --- a/configs/2-3-k8s-gke.json +++ b/configs/2-3-k8s-gke.json @@ -62,6 +62,14 @@ "description": "", "hint": "Check this box if you want Logz.io Telemetry Collector to collect only the relevant system metrics to populate Kubernetes 360 and prebuilt dashboards. In addition, we will also collect application metrics that are exposed by your pods.", "value": true + }, + { + "type": "boolean", + "name": "isObjectLogs", + "label": "Collect correlated Kubernetes resource object logs", + "description": "", + "hint": "Check this box if you want Logz.io Telemetry Collector to collect Kubernetes resource object logs that correlate with metrics to populate Kubernetes 360 and prebuilt dashboards.", + "value": true } ], "dashboards": [ diff --git a/configs/2-4-k8s-digitalocean.json b/configs/2-4-k8s-digitalocean.json index 6ea366516..cc8e2ec02 100644 --- a/configs/2-4-k8s-digitalocean.json +++ b/configs/2-4-k8s-digitalocean.json @@ -62,6 +62,14 @@ "description": "", "hint": "Check this box if you want Logz.io Telemetry Collector to collect only the relevant system metrics to populate Kubernetes 360 and prebuilt dashboards. In addition, we will also collect application metrics that are exposed by your pods.", "value": true + }, + { + "type": "boolean", + "name": "isObjectLogs", + "label": "Collect correlated Kubernetes resource object logs", + "description": "", + "hint": "Check this box if you want Logz.io Telemetry Collector to collect Kubernetes resource object logs that correlate with metrics to populate Kubernetes 360 and prebuilt dashboards.", + "value": true } ], "dashboards": [ diff --git a/datasources/mac/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash b/datasources/mac/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash index 2dc565bc6..1da3fc186 100755 --- a/datasources/mac/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/mac/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash @@ -36,3 +36,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='aks' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/mac/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash b/datasources/mac/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash index c46678a1d..288634a8f 100755 --- a/datasources/mac/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/mac/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash @@ -30,3 +30,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='aks' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/mac/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash b/datasources/mac/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash index 3ee1a8075..c67cac476 100755 --- a/datasources/mac/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/mac/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash @@ -34,3 +34,13 @@ if $IS_FARGATE; then # Build Fargate collector mode standalone Helm set execute_task 'build_fargate_collector_mode_standalone_helm_set' 'Building Fargate collector mode standalone Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/mac/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash b/datasources/mac/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash index d00c3bb8f..5de1883cb 100755 --- a/datasources/mac/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/mac/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash @@ -30,3 +30,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='gke' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/functions.ps1 b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/functions.ps1 index 06a3542dd..eeb2d4ff0 100755 --- a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/functions.ps1 +++ b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/functions.ps1 @@ -259,3 +259,191 @@ function Build-EnableMetricsFilterHelmSet { Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" } + +# Gets Logz.io Kubernetes object logs token +# Input: +# --- +# Output: +# ObjectLogsToken - Logz.io Kubernetes object logs token +function Get-LogzioObjectLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io Kubernetes object logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io Kubernetes object logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:ObjectLogsToken = '$ShippingToken'" +} + +# Builds Logz.io Kubernetes object logs token Helm set +# Input: +# FuncArgs - Hashtabla {ObjectLogsToken = $script:ObjectLogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioObjectLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io Kubernetes object logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ObjectLogsToken') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ObjectLogsToken = $FuncArgs.ObjectLogsToken + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$ObjectLogsToken" + + $local:Message = "Logz.io Kubernetes object logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Gets is Kubernetes object logs was selected +# Input: +# FuncArgs - Hashtable {MetricsParams = $script:MetricsParams} +# Output: +# isObjectLogs - Tells if Kubernetes object logs was selected (true/false) +function Get-IsObjectLogsWasSelected { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 5 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting if Kubernetes object logs option was selected ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('MetricsParams') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:MetricsParams = $FuncArgs.MetricsParams + + $Err = Get-ParamValue $MetricsParams 'isObjectLogs' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:IsObjectLogs = $script:ParamValue + + if ($IsObjectLogs) { + $Message = 'Kubernetes object logs option was selected' + } + else { + $Message = 'Kubernetes object logs option was not selected' + } + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:IsObjectLogs = `$$IsObjectLogs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-EnableObjectLogsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable Kubernetes object logs Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + $local:Message = "Enable Kubernetes object logs Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io region Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# HelmSets - Contains all the Helm sets +function Build-LogzioRegionHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io region Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:Region = Get-LogzioRegion $ListenerUrl + + $Message = "Logz.io region is '$LogzioRegion'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.LogzioRegion=$Region" + + $local:Message = "Logz.io region Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} \ No newline at end of file diff --git a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 index 5d094bc0c..ffe3a7c29 100755 --- a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 @@ -60,6 +60,18 @@ if ($script:IsFilter) { # Build enable metrics filter Helm set Invoke-Task 'Build-EnableMetricsFilterHelmSet' @{} 'Building enable metrics filter Helm set' @($MetricsFunctionsScript) } +# Get if Kubernetes object logs option was selected +Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParams} 'Getting if Kubernetes object logs was selected' @($MetricsFunctionsScript) +if ($script:IsObjectLogs) { + # Build enable Kubernetes object logs Helm set + Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) +} +# Get Logz.io Kubernetes object logs token +Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) +# Build Logz.io Kubernetes object logs token Helm set +Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) +# Build Logz.io region Helm set +Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/functions.ps1 b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/functions.ps1 index 51612b043..a9cc2eb76 100755 --- a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/functions.ps1 +++ b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/functions.ps1 @@ -208,3 +208,191 @@ function Build-EnableMetricsFilterHelmSet { Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" } + +# Gets Logz.io Kubernetes object logs token +# Input: +# --- +# Output: +# ObjectLogsToken - Logz.io Kubernetes object logs token +function Get-LogzioObjectLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io Kubernetes object logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io Kubernetes object logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:ObjectLogsToken = '$ShippingToken'" +} + +# Builds Logz.io Kubernetes object logs token Helm set +# Input: +# FuncArgs - Hashtabla {ObjectLogsToken = $script:ObjectLogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioObjectLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io Kubernetes object logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ObjectLogsToken') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ObjectLogsToken = $FuncArgs.ObjectLogsToken + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$ObjectLogsToken" + + $local:Message = "Logz.io Kubernetes object logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Gets is Kubernetes object logs was selected +# Input: +# FuncArgs - Hashtable {MetricsParams = $script:MetricsParams} +# Output: +# isObjectLogs - Tells if Kubernetes object logs was selected (true/false) +function Get-IsObjectLogsWasSelected { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 5 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting if Kubernetes object logs option was selected ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('MetricsParams') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:MetricsParams = $FuncArgs.MetricsParams + + $Err = Get-ParamValue $MetricsParams 'isObjectLogs' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:IsObjectLogs = $script:ParamValue + + if ($IsObjectLogs) { + $Message = 'Kubernetes object logs option was selected' + } + else { + $Message = 'Kubernetes object logs option was not selected' + } + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:IsObjectLogs = `$$IsObjectLogs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-EnableObjectLogsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable Kubernetes object logs Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + $local:Message = "Enable Kubernetes object logs Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io region Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# HelmSets - Contains all the Helm sets +function Build-LogzioRegionHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io region Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:Region = Get-LogzioRegion $ListenerUrl + + $Message = "Logz.io region is '$LogzioRegion'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.LogzioRegion=$Region" + + $local:Message = "Logz.io region Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} \ No newline at end of file diff --git a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 index fd2b3a826..dcb11cca3 100755 --- a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 @@ -26,6 +26,18 @@ if ($script:IsFilter) { # Build enable metrics filter Helm set Invoke-Task 'Build-EnableMetricsFilterHelmSet' @{} 'Building enable metrics filter Helm set' @($MetricsFunctionsScript) } +# Get if Kubernetes object logs option was selected +Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParams} 'Getting if Kubernetes object logs was selected' @($MetricsFunctionsScript) +if ($script:IsObjectLogs) { + # Build enable Kubernetes object logs Helm set + Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) +} +# Get Logz.io Kubernetes object logs token +Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) +# Build Logz.io Kubernetes object logs token Helm set +Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) +# Build Logz.io region Helm set +Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/functions.ps1 b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/functions.ps1 index e54a3db35..e5a4d2325 100755 --- a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/functions.ps1 +++ b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/functions.ps1 @@ -231,3 +231,191 @@ function Build-FargateCollectorModeStandaloneHelmSet { Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" } + +# Gets Logz.io Kubernetes object logs token +# Input: +# --- +# Output: +# ObjectLogsToken - Logz.io Kubernetes object logs token +function Get-LogzioObjectLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io Kubernetes object logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io Kubernetes object logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:ObjectLogsToken = '$ShippingToken'" +} + +# Builds Logz.io Kubernetes object logs token Helm set +# Input: +# FuncArgs - Hashtabla {ObjectLogsToken = $script:ObjectLogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioObjectLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io Kubernetes object logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ObjectLogsToken') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ObjectLogsToken = $FuncArgs.ObjectLogsToken + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$ObjectLogsToken" + + $local:Message = "Logz.io Kubernetes object logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Gets is Kubernetes object logs was selected +# Input: +# FuncArgs - Hashtable {MetricsParams = $script:MetricsParams} +# Output: +# isObjectLogs - Tells if Kubernetes object logs was selected (true/false) +function Get-IsObjectLogsWasSelected { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 5 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting if Kubernetes object logs option was selected ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('MetricsParams') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:MetricsParams = $FuncArgs.MetricsParams + + $Err = Get-ParamValue $MetricsParams 'isObjectLogs' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:IsObjectLogs = $script:ParamValue + + if ($IsObjectLogs) { + $Message = 'Kubernetes object logs option was selected' + } + else { + $Message = 'Kubernetes object logs option was not selected' + } + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:IsObjectLogs = `$$IsObjectLogs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-EnableObjectLogsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable Kubernetes object logs Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + $local:Message = "Enable Kubernetes object logs Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Builds Logz.io region Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# HelmSets - Contains all the Helm sets +function Build-LogzioRegionHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io region Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:Region = Get-LogzioRegion $ListenerUrl + + $Message = "Logz.io region is '$LogzioRegion'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.LogzioRegion=$Region" + + $local:Message = "Logz.io region Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} \ No newline at end of file diff --git a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 index d97b0748e..ffc9285d3 100755 --- a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 @@ -30,6 +30,18 @@ if ($script:IsFargate) { # Build Fargate collector mode standalone Helm set Invoke-Task 'Build-FargateCollectorModeStandaloneHelmSet' @{} 'Building Fargate collector mode standalone Helm set' @($MetricsFunctionsScript) } +# Get if Kubernetes object logs option was selected +Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParams} 'Getting if Kubernetes object logs was selected' @($MetricsFunctionsScript) +if ($script:IsObjectLogs) { + # Build enable Kubernetes object logs Helm set + Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) +} +# Get Logz.io Kubernetes object logs token +Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) +# Build Logz.io Kubernetes object logs token Helm set +Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) +# Build Logz.io region Helm set +Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/functions.ps1 b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/functions.ps1 index 51612b043..6f00a2ab8 100755 --- a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/functions.ps1 +++ b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/functions.ps1 @@ -208,3 +208,190 @@ function Build-EnableMetricsFilterHelmSet { Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" } + +# Gets Logz.io Kubernetes object logs token +# Input: +# --- +# Output: +# ObjectLogsToken - Logz.io Kubernetes object logs token +function Get-LogzioObjectLogsToken { + $local:ExitCode = 1 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting Logz.io Kubernetes object logs token ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Get-JsonFileFieldValue $script:AgentJson '.shippingTokens.LOG_ANALYTICS' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ShippingToken = $script:JsonValue + + $Message = "Logz.io Kubernetes object logs token is '$ShippingToken'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:ObjectLogsToken = '$ShippingToken'" +} + +# Builds Logz.io Kubernetes object logs token Helm set +# Input: +# FuncArgs - Hashtabla {ObjectLogsToken = $script:ObjectLogsToken} +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-LogzioObjectLogsTokenHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io Kubernetes object logs token Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ObjectLogsToken') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ObjectLogsToken = $FuncArgs.ObjectLogsToken + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$ObjectLogsToken" + + $local:Message = "Logz.io Kubernetes object logs token Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} + +# Gets is Kubernetes object logs was selected +# Input: +# FuncArgs - Hashtable {MetricsParams = $script:MetricsParams} +# Output: +# isObjectLogs - Tells if Kubernetes object logs was selected (true/false) +function Get-IsObjectLogsWasSelected { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 5 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Getting if Kubernetes object logs option was selected ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('MetricsParams') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:MetricsParams = $FuncArgs.MetricsParams + + $Err = Get-ParamValue $MetricsParams 'isObjectLogs' + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:IsObjectLogs = $script:ParamValue + + if ($IsObjectLogs) { + $Message = 'Kubernetes object logs option was selected' + } + else { + $Message = 'Kubernetes object logs option was not selected' + } + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:IsObjectLogs = `$$IsObjectLogs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LogHelmSets - Containt all the Helm sets for logging +# HelmSets - Contains all the Helm sets +function Build-EnableObjectLogsHelmSet { + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building enable Kubernetes object logs Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + $local:Message = "Enable Kubernetes object logs Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} +# Builds Logz.io region Helm set +# Input: +# FuncArgs - Hashtable {ListenerUrl = $script:ListenerUrl} +# Output: +# HelmSets - Contains all the Helm sets +function Build-LogzioRegionHelmSet { + param ( + [hashtable]$FuncArgs + ) + + $local:ExitCode = 3 + $local:FuncName = $MyInvocation.MyCommand.Name + + $local:Message = 'Building Logz.io region Helm set ...' + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:Err = Test-AreFuncArgsExist $FuncArgs @('ListenerUrl') + if ($Err.Count -ne 0) { + $Message = "metrics.ps1 ($ExitCode): $($Err[0])" + Send-LogToLogzio $script:LogLevelError $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-TaskPostRun "Write-Error `"$Message`"" + + return $ExitCode + } + + $local:ListenerUrl = $FuncArgs.ListenerUrl + + $local:Region = Get-LogzioRegion $ListenerUrl + + $Message = "Logz.io region is '$LogzioRegion'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + $local:HelmSet = " --set logzio-k8s-telemetry.secrets.LogzioRegion=$Region" + + $local:Message = "Logz.io region Helm set is '$HelmSet'" + Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource + Write-Log $script:LogLevelDebug $Message + + Write-TaskPostRun "`$script:LogHelmSets += '$HelmSet'" + Write-TaskPostRun "`$script:HelmSets += '$HelmSet'" +} \ No newline at end of file diff --git a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 index fd2b3a826..4d90670ae 100755 --- a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 @@ -26,6 +26,18 @@ if ($script:IsFilter) { # Build enable metrics filter Helm set Invoke-Task 'Build-EnableMetricsFilterHelmSet' @{} 'Building enable metrics filter Helm set' @($MetricsFunctionsScript) } +# Get if Kubernetes object logs option was selected +Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParams} 'Getting if Kubernetes object logs was selected' @($MetricsFunctionsScript) +if ($script:IsObjectLogs) { + # Build enable Kubernetes object logs Helm set + Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) +} +# Get Logz.io Kubernetes object logs token +Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) +# Build Logz.io Kubernetes object token logs Helm set +Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) +# Build Logz.io region Helm set +Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/resources-linux/k8s/datasource_metrics_utils.bash b/resources-linux/k8s/datasource_metrics_utils.bash index 3d9f01f38..d4b2db97b 100755 --- a/resources-linux/k8s/datasource_metrics_utils.bash +++ b/resources-linux/k8s/datasource_metrics_utils.bash @@ -131,3 +131,114 @@ function build_enable_metrics_filter_helm_set { write_task_post_run "LOG_HELM_SETS+='$helm_set'" write_task_post_run "HELM_SETS+='$helm_set'" } + +# Gets is Kubernetes object logs was selected +# Input: +# --- +# Output: +# IS_OBJECT_LOGS - Tells if Kubernetes object logs was selected (true/false) +function get_is_object_logs_was_selected { + local func_name="${FUNCNAME[0]}" + + local message='Getting if Kubernetes object logs option was selected ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + PARAMS=("${METRICS_PARAMS[@]}") + get_param_value_list 'isObjectLogs' + if [[ $? -ne 0 ]]; then + message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + + local is_object_logs=$PARAM_VALUE + + if $is_object_logs; then + message='Kubernetes object logs option was selected' + else + message='Kubernetes object logs option was not selected' + fi + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "IS_OBJECT_LOGS=$is_object_logs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_enable_object_logs_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building enable Kubernetes object logs Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + message="Enable Kubernetes object logs Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io region Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_region_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io region Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local region=$(get_logzio_region "$LISTENER_URL") + + message="Logz.io region is '$region'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.secrets.LogzioRegion=$region" + + message="Logz.io region Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io metrics token Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_object_logs_token_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io Kubernetes object logs token Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$METRICS_TOKEN" + + local message="Logz.io Kubernetes object logs token Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + diff --git a/resources-mac/k8s/datasource_metrics_utils.bash b/resources-mac/k8s/datasource_metrics_utils.bash index 6398da413..585a4cb20 100755 --- a/resources-mac/k8s/datasource_metrics_utils.bash +++ b/resources-mac/k8s/datasource_metrics_utils.bash @@ -131,3 +131,113 @@ function build_enable_metrics_filter_helm_set { write_task_post_run "LOG_HELM_SETS+='$helm_set'" write_task_post_run "HELM_SETS+='$helm_set'" } + +# Gets is Kubernetes object logs was selected +# Input: +# --- +# Output: +# IS_OBJECT_LOGS - Tells if Kubernetes object logs was selected (true/false) +function get_is_object_logs_was_selected { + local func_name="${FUNCNAME[0]}" + + local message='Getting if Kubernetes object logs option was selected ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + PARAMS=("${METRICS_PARAMS[@]}") + get_param_value_list 'isObjectLogs' + if [[ $? -ne 0 ]]; then + message="metrics.bash ($EXIT_CODE): $(get_task_error_message)" + send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_task_post_run "write_error \"$message\"" + + return $EXIT_CODE + fi + + local is_object_logs=$PARAM_VALUE + + if $is_object_logs; then + message='Kubernetes object logs option was selected' + else + message='Kubernetes object logs option was not selected' + fi + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "IS_OBJECT_LOGS=$is_object_logs" +} + +# Builds enable Kubernetes object logs Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_enable_object_logs_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building enable Kubernetes object logs Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.k8sObjectsConfig.enabled=true" + + message="Enable Kubernetes object logs Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io region Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_region_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io region Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local region=$(get_logzio_region "$LISTENER_URL") + + message="Logz.io region is '$region'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.secrets.LogzioRegion=$region" + + message="Logz.io region Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} + +# Builds Logz.io metrics token Helm set +# Input: +# --- +# Output: +# LOG_HELM_SETS - Contains all the Helm sets for logging +# HELM_SETS - Contains all the Helm sets +function build_logzio_object_logs_token_helm_set { + local func_name="${FUNCNAME[0]}" + + local message='Building Logz.io Kubernetes object logs token Helm set ...' + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$METRICS_TOKEN" + + local message="Logz.io Kubernetes object logs token Helm set is '$helm_set'" + send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" + write_log "$LOG_LEVEL_DEBUG" "$message" + + write_task_post_run "LOG_HELM_SETS+='$helm_set'" + write_task_post_run "HELM_SETS+='$helm_set'" +} From f1e2639aa2d8ccb8dbef882b9acfdbc188a85e02 Mon Sep 17 00:00:00 2001 From: ralongit Date: Sun, 21 Apr 2024 17:59:08 +0300 Subject: [PATCH 2/4] Update linux --- .../aks/kubernetes/telemetry/metrics/metrics.bash | 10 ++++++++++ .../kubernetes/telemetry/metrics/metrics.bash | 10 ++++++++++ .../eks/kubernetes/telemetry/metrics/metrics.bash | 10 ++++++++++ .../gke/kubernetes/telemetry/metrics/metrics.bash | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/datasources/linux/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash b/datasources/linux/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash index cf8cbaca9..da660e106 100755 --- a/datasources/linux/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/linux/kubernetes/aks/kubernetes/telemetry/metrics/metrics.bash @@ -36,3 +36,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='aks' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/linux/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash b/datasources/linux/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash index 9a387b0db..2971756d8 100755 --- a/datasources/linux/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/linux/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.bash @@ -30,3 +30,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='aks' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/linux/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash b/datasources/linux/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash index cc57706b4..dcb43a184 100755 --- a/datasources/linux/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/linux/kubernetes/eks/kubernetes/telemetry/metrics/metrics.bash @@ -34,3 +34,13 @@ if $IS_FARGATE; then # Build Fargate collector mode standalone Helm set execute_task 'build_fargate_collector_mode_standalone_helm_set' 'Building Fargate collector mode standalone Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi diff --git a/datasources/linux/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash b/datasources/linux/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash index 7dd821fc4..861cef5d1 100755 --- a/datasources/linux/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash +++ b/datasources/linux/kubernetes/gke/kubernetes/telemetry/metrics/metrics.bash @@ -30,3 +30,13 @@ if $IS_FILTER; then CLOUD_PROVIDER='gke' execute_task 'build_enable_metrics_filter_helm_set' 'Building enable metrics filter Helm set' fi +# Get if Kubernetes object logs option was selected +execute_task 'get_is_object_logs_was_selected' 'Getting is Kubernetes object logs was selected' +if $IS_OBJECT_LOGS; then + # Build Logz.io region Helm set + execute_task 'build_logzio_region_helm_set' 'Building Logz.io region Helm set' + # Build Logz.io Kubernetes object logs token Helm set + execute_task 'build_logzio_object_logs_token_helm_set' 'Building Logz.io Kubernetes object logs token Helm set' + # Build enable Kubernetes object logs Helm set + execute_task 'build_enable_object_logs_helm_set' 'Building enable Kubernetes object logs Helm set' +fi From 6fa248981c938425dc6da245caad1179580749aa Mon Sep 17 00:00:00 2001 From: ralongit Date: Mon, 22 Apr 2024 09:50:56 +0300 Subject: [PATCH 3/4] Use logs instead of metrics token --- resources-linux/k8s/datasource_metrics_utils.bash | 2 +- resources-mac/k8s/datasource_metrics_utils.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources-linux/k8s/datasource_metrics_utils.bash b/resources-linux/k8s/datasource_metrics_utils.bash index d4b2db97b..9b3b5184b 100755 --- a/resources-linux/k8s/datasource_metrics_utils.bash +++ b/resources-linux/k8s/datasource_metrics_utils.bash @@ -232,7 +232,7 @@ function build_logzio_object_logs_token_helm_set { send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_log "$LOG_LEVEL_DEBUG" "$message" - local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$METRICS_TOKEN" + local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$LOGS_TOKEN" local message="Logz.io Kubernetes object logs token Helm set is '$helm_set'" send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" diff --git a/resources-mac/k8s/datasource_metrics_utils.bash b/resources-mac/k8s/datasource_metrics_utils.bash index 585a4cb20..214bd6114 100755 --- a/resources-mac/k8s/datasource_metrics_utils.bash +++ b/resources-mac/k8s/datasource_metrics_utils.bash @@ -232,7 +232,7 @@ function build_logzio_object_logs_token_helm_set { send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" write_log "$LOG_LEVEL_DEBUG" "$message" - local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$METRICS_TOKEN" + local helm_set=" --set logzio-k8s-telemetry.secrets.k8sObjectsLogsToken=$LOGS_TOKEN" local message="Logz.io Kubernetes object logs token Helm set is '$helm_set'" send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE" From acf5ef895c09a33aaf5a5a42baad4b513b892825 Mon Sep 17 00:00:00 2001 From: ralongit Date: Wed, 24 Apr 2024 11:49:37 +0300 Subject: [PATCH 4/4] Nest Windows functions under condition --- .../aks/kubernetes/telemetry/metrics/metrics.ps1 | 12 ++++++------ .../kubernetes/telemetry/metrics/metrics.ps1 | 12 ++++++------ .../eks/kubernetes/telemetry/metrics/metrics.ps1 | 12 ++++++------ .../gke/kubernetes/telemetry/metrics/metrics.ps1 | 13 ++++++------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 index ffe3a7c29..e017a02e4 100755 --- a/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/aks/kubernetes/telemetry/metrics/metrics.ps1 @@ -65,13 +65,13 @@ Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParam if ($script:IsObjectLogs) { # Build enable Kubernetes object logs Helm set Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) + # Get Logz.io Kubernetes object logs token + Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) + # Build Logz.io Kubernetes object logs token Helm set + Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) + # Build Logz.io region Helm set + Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) } -# Get Logz.io Kubernetes object logs token -Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) -# Build Logz.io Kubernetes object logs token Helm set -Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) -# Build Logz.io region Helm set -Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 index dcb11cca3..089dc9e31 100755 --- a/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/digitalocean/kubernetes/telemetry/metrics/metrics.ps1 @@ -31,13 +31,13 @@ Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParam if ($script:IsObjectLogs) { # Build enable Kubernetes object logs Helm set Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) + # Get Logz.io Kubernetes object logs token + Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) + # Build Logz.io Kubernetes object logs token Helm set + Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) + # Build Logz.io region Helm set + Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) } -# Get Logz.io Kubernetes object logs token -Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) -# Build Logz.io Kubernetes object logs token Helm set -Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) -# Build Logz.io region Helm set -Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 index ffc9285d3..fb35e22b7 100755 --- a/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/eks/kubernetes/telemetry/metrics/metrics.ps1 @@ -35,13 +35,13 @@ Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParam if ($script:IsObjectLogs) { # Build enable Kubernetes object logs Helm set Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) + # Get Logz.io Kubernetes object logs token + Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) + # Build Logz.io Kubernetes object logs token Helm set + Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) + # Build Logz.io region Helm set + Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) } -# Get Logz.io Kubernetes object logs token -Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) -# Build Logz.io Kubernetes object logs token Helm set -Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) -# Build Logz.io region Helm set -Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) # Finished successfully Exit 0 diff --git a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 index 4d90670ae..60efb096c 100755 --- a/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 +++ b/datasources/windows/kubernetes/gke/kubernetes/telemetry/metrics/metrics.ps1 @@ -31,13 +31,12 @@ Invoke-Task 'Get-IsObjectLogsWasSelected' @{MetricsParams = $script:MetricsParam if ($script:IsObjectLogs) { # Build enable Kubernetes object logs Helm set Invoke-Task 'Build-EnableObjectLogsHelmSet' @{} 'Building enable Kubernetes object logs Helm set' @($MetricsFunctionsScript) + # Get Logz.io Kubernetes object logs token + Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) + # Build Logz.io Kubernetes object token logs Helm set + Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) + # Build Logz.io region Helm set + Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) } -# Get Logz.io Kubernetes object logs token -Invoke-Task 'Get-LogzioObjectLogsToken' @{} 'Getting Logz.io Kubernetes object logs token' @($MetricsFunctionsScript) -# Build Logz.io Kubernetes object token logs Helm set -Invoke-Task 'Build-LogzioObjectLogsTokenHelmSet' @{ObjectLogsToken = $script:ObjectLogsToken} 'Building Logz.io Kubernetes object logs token Helm set' @($MetricsFunctionsScript) -# Build Logz.io region Helm set -Invoke-Task 'Build-LogzioRegionHelmSet' @{ListenerUrl = $script:ListenerUrl} 'Building Logz.io region Helm set' @($MetricsFunctionsScript) - # Finished successfully Exit 0