Skip to content

Commit

Permalink
Add user-agent header and dynamic version update (#171)
Browse files Browse the repository at this point in the history
* Add user-agent header and dynamic version update
  • Loading branch information
bardabun authored May 27, 2024
1 parent 6efd49e commit 93fb098
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ function Add-LogsExporterToOtelConfig {
return $ExitCode
}

$Err = Set-YamlFileFieldValue "$script:OtelExportersDir\logzio_logs.yaml" '.logzio/logs.headers.user-agent' $script:UserAgentLogs
if ($Err.Count -ne 0) {
$Message = "logs.ps1 ($ExitCode): $($Err[0]))"
Send-LogToLogzio $script:LogLevelError $Message $script:LogStepLogs $script:LogScriptLogs $FuncName $script:AgentId $script:Platform $script:SubType $script:CurrentDataSource
Write-TaskPostRun "Write-Error `"$Message`""
return $ExitCode
}

$local:LogzioRegion = Get-LogzioRegion $ListenerUrl

$Message = "Logz.io region is '$LogzioRegion'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ function Add-MetricsExporterToOtelConfig {
return $ExitCode
}

$Err = Set-YamlFileFieldValue "$script:OtelExportersDir\prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' $script:UserAgentMetrics
if ($Err.Count -ne 0) {
$Message = "metrics.ps1 ($ExitCode): $($Err[0]))"
Send-LogToLogzio $script:LogLevelDebug $Message $script:LogStepMetrics $script:LogScriptMetrics $FuncName $script:AgentId $script:Platform $script:Subtype $script:CurrentDataSource
Write-TaskPostRun "Write-Error `"$Message`""
return $ExitCode
}

$Err = Add-YamlFileFieldValueToAnotherYamlFileField "$script:OtelExportersDir\prometheusremotewrite.yaml" "$script:OtelResourcesDir\$script:OtelConfigName" '' '.exporters'
if ($Err.Count -ne 0) {
$Message = "metrics.ps1 ($ExitCode): $($Err[0]))"
Expand Down
9 changes: 9 additions & 0 deletions resources-linux/otel/datasource_logs_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ function add_logs_exporter_to_otel_config {
return $EXIT_CODE
fi

set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/logzio_logs.yaml" '.logzio/logs.headers.user-agent' "$USER_AGENT_LOGS"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_task_post_run "write_error \"$message\""

return $EXIT_CODE
fi

local logzio_region=$(get_logzio_region "$LISTENER_URL")

message="Logz.io region is '$logzio_region'"
Expand Down
9 changes: 9 additions & 0 deletions resources-linux/otel/datasource_metrics_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ function add_metrics_exporter_to_otel_config {
return $EXIT_CODE
fi

set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' "Bearer $USER_AGENT_METRICS"
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

add_yaml_file_field_value_to_another_yaml_file_field "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" "$OTEL_RESOURCES_DIR/$OTEL_CONFIG_NAME" '' '.exporters'
if [[ $? -ne 0 ]]; then
message="metrics.bash ($EXIT_CODE): $(get_task_error_message)"
Expand Down
9 changes: 9 additions & 0 deletions resources-mac/otel/datasource_logs_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ function add_logs_exporter_to_otel_config {
return $EXIT_CODE
fi

set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/logzio_logs.yaml" '.logzio/logs.headers.user-agent' "$USER_AGENT_LOGS"
if [[ $? -ne 0 ]]; then
message="logs.bash ($EXIT_CODE): $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_LOGS" "$LOG_SCRIPT_LOGS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_task_post_run "write_error \"$message\""

return $EXIT_CODE
fi

local logzio_region=$(get_logzio_region "$LISTENER_URL")

message="Logz.io region is '$logzio_region'"
Expand Down
9 changes: 9 additions & 0 deletions resources-mac/otel/datasource_metrics_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ function add_metrics_exporter_to_otel_config {
return $EXIT_CODE
fi

set_yaml_file_field_value "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" '.prometheusremotewrite.headers.user-agent' "Bearer $USER_AGENT_METRICS"
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

add_yaml_file_field_value_to_another_yaml_file_field "$OTEL_EXPORTERS_DIR/prometheusremotewrite.yaml" "$OTEL_RESOURCES_DIR/$OTEL_CONFIG_NAME" '' '.exporters'
if [[ $? -ne 0 ]]; then
message="metrics.bash ($EXIT_CODE): $(get_task_error_message)"
Expand Down
5 changes: 5 additions & 0 deletions scripts/linux/consts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,8 @@ PURPLE_COLOR='\033[0;35m'
WHITE_COLOR='\033[0;37m'
RED_COLOR_BOLD='\033[1;31m'
GREEN_COLOR_BOLD='\033[0;32m'

## Headers
AGENT_VERSION=$(cat "$LOGZIO_TEMP_DIR/version")
USER_AGENT_LOGS="logzio-linux-version-$AGENT_VERSION-logs"
USER_AGENT_METRICS="logzio-linux-version-$AGENT_VERSION-metrics"
6 changes: 6 additions & 0 deletions scripts/mac/consts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,9 @@ PURPLE_COLOR='\033[0;35m'
WHITE_COLOR='\033[0;37m'
RED_COLOR_BOLD='\033[1;31m'
GREEN_COLOR_BOLD='\033[0;32m'

## Headers
## Headers
AGENT_VERSION=$(cat "$LOGZIO_TEMP_DIR/version")
USER_AGENT_LOGS="logzio-mac-version-$AGENT_VERSION-logs"
USER_AGENT_METRICS="logzio-mac-version-$AGENT_VERSION-metrics"
5 changes: 5 additions & 0 deletions scripts/windows/consts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,9 @@ $script:LogScriptMetrics = 'metrics.ps1'
$script:LogsScriptTraces = 'traces.ps1'
$script:LogScriptPostrequisites = 'postrequisites.ps1'

## Headers
$script:AgentVersion = Get-Content "$env:TEMP\Logzio\version"
$script:UserAgentLogs = "logzio-windows-version-$script:AgentVersion-logs"
$script:UserAgentMetrics = "logzio-windows-version-$script:AgentVersion-metrics"

# Dynamic Consts (Will be added while the agent running)

0 comments on commit 93fb098

Please sign in to comment.