-
Notifications
You must be signed in to change notification settings - Fork 209
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
Using cmd/c to avoid PowerShell ISE does not accept stderr #473
Changes from 2 commits
d6381de
a77b984
a306cfa
cc79774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,10 +113,10 @@ $EC2 = $false | |
$CIM = $false | ||
|
||
Function StartAll() { | ||
Write-Output "****** processing cwagent-otel-collector ******" | ||
Write-Output "****** Processing cwagent-otel-collector ******" | ||
AgentStart -service_name $CWOCServiceName -service_display_name $CWOCServiceDisplayName | ||
|
||
Write-Output "`r`n****** processing amazon-cloudwatch-agent ******" | ||
Write-Output "`r`n****** Processing amazon-cloudwatch-agent ******" | ||
AgentStart -service_name $CWAServiceName -service_display_name $CWAServiceDisplayName | ||
} | ||
|
||
|
@@ -169,10 +169,10 @@ Function AgentStart() { | |
} | ||
|
||
Function StopAll() { | ||
Write-Output "****** processing cwagent-otel-collector ******" | ||
Write-Output "****** Processing cwagent-otel-collector ******" | ||
AgentStop -service_name $CWOCServiceName | ||
|
||
Write-Output "`r`n****** processing amazon-cloudwatch-agent ******" | ||
Write-Output "`r`n****** Processing amazon-cloudwatch-agent ******" | ||
AgentStop -service_name $CWAServiceName | ||
} | ||
|
||
|
@@ -356,27 +356,27 @@ Function CWAConfig() { | |
} | ||
|
||
if ($ConfigLocation -eq $AllConfig -And $multi_config -ne 'remove') { | ||
Write-Output "ignore cwa configuration `"$AllConfig`" as it is only supported by action `"remove-config`"" | ||
Write-Output "Ignore amazon-cloudwatch-agent's configuration ${AllConfig} as it is only supported by action `"remove-config`"" | ||
return | ||
} | ||
|
||
if ($ConfigLocation -eq $AllConfig) { | ||
Remove-Item -Path "${JSON_DIR}\*" -Force -ErrorAction SilentlyContinue | ||
} else { | ||
& $CWAProgramFiles\config-downloader.exe --output-dir "${JSON_DIR}" --download-source "${ConfigLocation}" --mode "${param_mode}" --config "${COMMON_CONIG}" --multi-config "${multi_config}" | ||
& cmd /c "`"$CWAProgramFiles\config-downloader.exe`" --output-dir ${JSON_DIR} --download-source ${ConfigLocation} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} 2>&1" | ||
CheckCMDResult | ||
} | ||
|
||
$jsonDirContent = Get-ChildItem "${JSON_DIR}" | Measure-Object | ||
|
||
if ($jsonDirContent.count -eq 0) { | ||
Write-Output "all amazon-cloudwatch-agent configurations have been removed" | ||
Write-Output "All amazon-cloudwatch-agent configurations have been removed" | ||
Remove-Item "${TOML}" -Force -ErrorAction SilentlyContinue | ||
} else { | ||
Write-Output "Start configuration validation..." | ||
& cmd /c "`"$CWAProgramFiles\config-translator.exe`" --input ${JSON} --input-dir ${JSON_DIR} --output ${TOML} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} 2>&1" | ||
CheckCMDResult | ||
# Let command pass so we can check return code and give user-friendly error-message | ||
|
||
$ErrorActionPreference = "Continue" | ||
& cmd /c "`"${CWAProgramFiles}\amazon-cloudwatch-agent.exe`" --schematest --config ${TOML} 2>&1" | Out-File $CVLogFile | ||
if ($LASTEXITCODE -ne 0) { | ||
|
@@ -425,11 +425,11 @@ Function CWOCConfig() { | |
) | ||
|
||
if (Test-Path -LiteralPath "${Env:ProgramFiles}\Amazon\AWSOTelCollector\aws-otel-collector-ctl.ps1") { | ||
Write-Output "REMINDER: you are configuring `"cwagent-otel-collector`" instead of `"aws-otel-collector`"." | ||
Write-Output "REMINDER: You are configuring `"cwagent-otel-collector`" instead of `"aws-otel-collector`"." | ||
} | ||
|
||
if ($multi_config -eq 'append') { | ||
Write-Output "ignore `"-o`" as cwagent-otel-collector doesn't support append-config" | ||
Write-Output "Ignore `"-o`" as cwagent-otel-collector doesn't support append-config" | ||
return | ||
} | ||
|
||
|
@@ -439,7 +439,7 @@ Function CWOCConfig() { | |
} | ||
|
||
if ($OtelConfigLocation -eq $AllConfig -And $multi_config -ne 'remove') { | ||
Write-Output "ignore cwoc configuration `"$AllConfig`" as it is only supported by action `"remove-config`"" | ||
Write-Output "Ignore cwagent-otel-collector's configuration `"$AllConfig`" as it is only supported by action `"remove-config`"" | ||
return | ||
} | ||
|
||
|
@@ -449,15 +449,13 @@ Function CWOCConfig() { | |
Copy-Item "${PREDEFINED_CONFIG_DATA}" -Destination "${YAML_DIR}/default.tmp" | ||
Write-Output "Successfully fetched the config and saved in ${YAML_DIR}\default.tmp" | ||
} else { | ||
& $CWAProgramFiles\config-downloader.exe --output-dir "${YAML_DIR}" --download-source "${OtelConfigLocation}" --mode "${param_mode}" --config "${COMMON_CONIG}" --multi-config "${multi_config}" | ||
if ($LASTEXITCODE -ne 0) { | ||
return | ||
} | ||
& cmd /c "`"$CWAProgramFiles\config-downloader.exe`" --output-dir ${YAML_DIR} --download-source ${OtelConfigLocation} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} 2>&1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the PR overview, change description: it says "using cmd/ c for config-translator". I think you meant to say "using cmd/ c for config-downloader.exe". Nice work figuring out this change fix the issue, before we merge this change, can you do a quick spike regarding understand, why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ack. My bad on writing the wrong artifacts.
That's a good question. Besides the advantage/disadvatange between using |
||
CheckCMDResult | ||
} | ||
|
||
$yamlDirContent = Get-ChildItem "${YAML_DIR}" | Measure-Object | ||
if ($yamlDirContent.count -eq 0) { | ||
Write-Output "all cwagent-otel-collector configurations have been removed" | ||
Write-Output "All cwagent-otel-collector configurations have been removed" | ||
Remove-Item "${YAML}" -Force -ErrorAction SilentlyContinue | ||
} else { | ||
# delete old file which are without .tmp suffix | ||
|
@@ -469,7 +467,7 @@ Function CWOCConfig() { | |
$destination = Join-Path -Path $_.Directory.FullName -ChildPath "${newName}" | ||
Move-Item $_.FullName -Destination "${destination}" -Force | ||
Copy-Item "${destination}" -Destination "${YAML}" -Force | ||
Write-Output "cwagent-otel-collector config has been successfully fetched." | ||
Write-Output "cwagent-otel-collector's configuration has been successfully fetched." | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this comment? It is explaining what setting the
$ErrorActionPreference
does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to update the comment on the config-translator since the existing one would not be enough. However, I have fixed it in the newest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to touch this. Can you just revert the change for the comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its for better information right? Just wank to ask if there anything wrong with the new comments. Customer won't look at this file; therefore, its only for dev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you want to include information, what needs to be explained is why the
ErrorActionPreference
is set here, and not in the line above it for the config translator. If there isn't a clear explanation for that, I don't see value in trying to add more comments here. I also don't see any reason to link to https://www.tutorialspoint.com/how-to-use-the-erroractionpreference-variable-in-powershellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. I have updated the newest comment regarding these details. Thanks for reminding me and sorry for commenting late.