Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes object logs #161

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config-templates/helm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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='<<LOGZIO_LOGS_SHIPPING_TOKEN>>' \\"
},
{
"template": " --set logzio-k8s-telemetry.secrets.LogzioRegion='<<LOGZIO_ACCOUNT_REGION_CODE>>' \\"
}
]
},
Expand All @@ -99,6 +109,9 @@
},
{
"template": " --set logzio-k8s-telemetry.secrets.SpmToken='<<LOGZIO_METRICS_SHIPPING_TOKEN>>' \\"
},
{
"template": " --set logzio-k8s-telemetry.serviceGraph.enabled=true \\"
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions configs/2-1-k8s-eks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 8 additions & 0 deletions configs/2-2-k8s-aks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions configs/2-3-k8s-gke.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 8 additions & 0 deletions configs/2-4-k8s-digitalocean.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
Loading
Loading