From 8897b2c40ee8b42f08d7a40ed3515a28a82e90a2 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Fri, 24 Sep 2021 14:34:23 -0700 Subject: [PATCH 1/9] livenessprobe optimization --- scripts/build/windows/livenessprobe.cpp | 127 ++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 scripts/build/windows/livenessprobe.cpp diff --git a/scripts/build/windows/livenessprobe.cpp b/scripts/build/windows/livenessprobe.cpp new file mode 100644 index 000000000..1e2369d7e --- /dev/null +++ b/scripts/build/windows/livenessprobe.cpp @@ -0,0 +1,127 @@ +// OMSProbeExe.cpp : This file contains the 'main' function. Program execution begins and ends there. + +#ifndef UNICODE +#define UNICODE +#endif + +#ifndef _UNICODE +#define _UNICODE +#endif + +#include +#include +#include + +#define SUCCESS 0x00000000 +#define NO_FLUENT_BIT_PROCESS 0x00000001 +#define FILESYSTEM_WATCHER_FILE_EXISTS 0x00000002 +#define CERTIFICATE_RENEWAL_REQUIRED 0x00000003 +#define FLUENTDWINAKS_SERVICE_NOT_RUNNING 0x00000004 +#define UNEXPECTED_ERROR 0xFFFFFFFF + + +bool IsProcessRunning(const wchar_t * const executableName) { + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + + const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (!Process32First(snapshot, &entry)) { + CloseHandle(snapshot); + return false; + } + + do { + if (!_wcsicmp(entry.szExeFile, executableName)) { + CloseHandle(snapshot); + return true; + } + } while (Process32Next(snapshot, &entry)); + + CloseHandle(snapshot); + return false; +} + + +bool IsFileExists(const wchar_t* const fileName) +{ + DWORD dwAttrib = GetFileAttributes(fileName); + return dwAttrib != INVALID_FILE_SIZE; +} + +int GetServiceStatus(const wchar_t * const serivceName) +{ + SC_HANDLE theService, scm; + SERVICE_STATUS_PROCESS ssStatus; + DWORD dwBytesNeeded; + + + scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_ENUMERATE_SERVICE); + if (!scm) { + return UNEXPECTED_ERROR; + } + + theService = OpenService(scm, serivceName, SERVICE_QUERY_STATUS); + if (!theService) { + CloseServiceHandle(scm); + return UNEXPECTED_ERROR; + } + + auto result = QueryServiceStatusEx(theService, SC_STATUS_PROCESS_INFO, + reinterpret_cast(&ssStatus), sizeof(SERVICE_STATUS_PROCESS), + &dwBytesNeeded); + + CloseServiceHandle(theService); + CloseServiceHandle(scm); + + if (result == 0) { + return UNEXPECTED_ERROR; + } + + return ssStatus.dwCurrentState; +} + +int _tmain(int argc, wchar_t * argv[]) +{ + wprintf_s(L"INFO:number of passed arguments - %d \n", argc); + if( argc < 5) { + wprintf_s(L"ERROR:unexpected number arguments and expected is 5"); + return UNEXPECTED_ERROR; + } + + if (IsProcessRunning(argv[1])) + { + wprintf_s(L"INFO:%s is running\n", argv[1]); + } + else + { + wprintf_s(L"ERROR: %s is not running\n", argv[1]); + return NO_FLUENT_BIT_PROCESS; + } + + DWORD dwStatus = GetServiceStatus(argv[2]); + + if (dwStatus == SERVICE_RUNNING) + { + wprintf_s(L"INFO:%s is running\n", argv[2]); + } + else + { + wprintf_s(L"ERROR: %s is running\n", argv[2]); + return FLUENTDWINAKS_SERVICE_NOT_RUNNING; + } + + if (IsFileExists(argv[3])) + { + wprintf_s(L"INFO:%s exists which indicates Config Map Updated since agent started.\n", argv[3]); + return FILESYSTEM_WATCHER_FILE_EXISTS; + } + + if (IsFileExists(argv[4])) + { + wprintf_s(L"INFO:%s exists indicates Certificate needs to be renewed.\n", argv[4]); + return CERTIFICATE_RENEWAL_REQUIRED; + } + + return SUCCESS; +} From b79c797b1a29da1cc67bae01bb96ce0849cdfa9d Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Fri, 24 Sep 2021 19:31:50 -0700 Subject: [PATCH 2/9] optimize windows agent liveness probe --- build/windows/Makefile.ps1 | 18 +++++++++++++++--- .../installer/livenessprobe}/livenessprobe.cpp | 11 +++++++---- kubernetes/omsagent.yaml | 3 ++- kubernetes/windows/Dockerfile | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) rename {scripts/build/windows => build/windows/installer/livenessprobe}/livenessprobe.cpp (89%) diff --git a/build/windows/Makefile.ps1 b/build/windows/Makefile.ps1 index b9bd1f3e4..c8721efeb 100644 --- a/build/windows/Makefile.ps1 +++ b/build/windows/Makefile.ps1 @@ -3,6 +3,7 @@ # 1. Builds the certificate generator code in .NET and copy the binaries in zip file to ..\..\kubernetes\windows\omsagentwindows # 2. Builds the out_oms plugin code in go lang into the shared object(.so) file and copy the out_oms.so file to ..\..\kubernetes\windows\omsagentwindows # 3. copy the files under installer directory to ..\..\kubernetes\windows\omsagentwindows +# 4. Builds the livenessprobe cpp and copy the executable to the under directory ..\..\kubernetes\windows\omsagentwindows $dotnetcoreframework = "netcoreapp3.1" @@ -157,7 +158,7 @@ if ($isCDPxEnvironment) { Write-Host("getting latest go modules ...") go get - Write-Host("successfyullt got latest go modules") -ForegroundColor Green + Write-Host("successfully got latest go modules") -ForegroundColor Green go build -ldflags "-X 'main.revision=$buildVersionString' -X 'main.builddate=$buildVersionDate'" -buildmode=c-shared -o out_oms.so . } @@ -167,16 +168,27 @@ Write-Host("copying out_oms.so file to : $publishdir") Copy-Item -Path (Join-path -Path $outomsgoplugindir -ChildPath "out_oms.so") -Destination $publishdir -Force Write-Host("successfully copied out_oms.so file to : $publishdir") -ForegroundColor Green +# compile and build the liveness probe +Write-Host("Start:build livenessprobe cpp code") +$livenessprobesrcpath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.cpp" +$livenessprobeexepath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.exe" +g++ $livenessprobesrcpath -o $livenessprobeexepath -municode +Write-Host("End:build livenessprobe cpp code") +if (Test-Path -Path $livenessprobeexepath){ + Write-Host("livenessprobe.exe exists which indicates cpp build step succeeded") -ForegroundColor Green +} else { + Write-Host("livenessprobe.exe doesnt exist which indicates cpp build step failed") -ForegroundColor Red +} $installerdir = Join-Path -Path $builddir -ChildPath "common\installer" Write-Host("copying common installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ...") -$exclude = @('*.cs','*.csproj') +$exclude = @('*.cs','*.csproj', '*.cpp') Copy-Item -Path $installerdir -Destination $publishdir -Recurse -Force -Exclude $exclude Write-Host("successfully copied installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ") -ForegroundColor Green $installerdir = Join-Path -Path $builddir -ChildPath "windows\installer" Write-Host("copying installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ...") -$exclude = @('*.cs','*.csproj') +$exclude = @('*.cs','*.csproj', '*.cpp') Copy-Item -Path $installerdir -Destination $publishdir -Recurse -Force -Exclude $exclude Write-Host("successfully copied installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ") -ForegroundColor Green diff --git a/scripts/build/windows/livenessprobe.cpp b/build/windows/installer/livenessprobe/livenessprobe.cpp similarity index 89% rename from scripts/build/windows/livenessprobe.cpp rename to build/windows/installer/livenessprobe/livenessprobe.cpp index 1e2369d7e..3aa5bb95b 100644 --- a/scripts/build/windows/livenessprobe.cpp +++ b/build/windows/installer/livenessprobe/livenessprobe.cpp @@ -1,5 +1,3 @@ -// OMSProbeExe.cpp : This file contains the 'main' function. Program execution begins and ends there. - #ifndef UNICODE #define UNICODE #endif @@ -28,6 +26,7 @@ bool IsProcessRunning(const wchar_t * const executableName) { if (!Process32First(snapshot, &entry)) { CloseHandle(snapshot); + wprintf_s(L"ERROR:IsProcessRunning::Process32First failed"); return false; } @@ -55,15 +54,16 @@ int GetServiceStatus(const wchar_t * const serivceName) SERVICE_STATUS_PROCESS ssStatus; DWORD dwBytesNeeded; - scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_ENUMERATE_SERVICE); if (!scm) { + wprintf_s(L"ERROR:GetServiceStatus::OpenSCManager failed"); return UNEXPECTED_ERROR; } theService = OpenService(scm, serivceName, SERVICE_QUERY_STATUS); if (!theService) { CloseServiceHandle(scm); + wprintf_s(L"ERROR:GetServiceStatus::OpenService failed"); return UNEXPECTED_ERROR; } @@ -75,12 +75,15 @@ int GetServiceStatus(const wchar_t * const serivceName) CloseServiceHandle(scm); if (result == 0) { + wprintf_s(L"ERROR:GetServiceStatus:QueryServiceStatusEx failed"); return UNEXPECTED_ERROR; } return ssStatus.dwCurrentState; } - +/** + +**/ int _tmain(int argc, wchar_t * argv[]) { wprintf_s(L"INFO:number of passed arguments - %d \n", argc); diff --git a/kubernetes/omsagent.yaml b/kubernetes/omsagent.yaml index d84e46701..f7e828b85 100644 --- a/kubernetes/omsagent.yaml +++ b/kubernetes/omsagent.yaml @@ -833,7 +833,8 @@ spec: command: - cmd - /c - - C:\opt\omsagentwindows\scripts\cmd\livenessProbe.cmd + - fluent-bit.exe fluentdwinaks "C:\etc\omsagentwindows\filesystemwatcher.txt" "C:\etc\omsagentwindows\renewcertificate.txt" + - C:\opt\omsagentwindows\scripts\cmd\livenessprobe.exe periodSeconds: 60 initialDelaySeconds: 180 timeoutSeconds: 15 diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index 290deef40..0769e2eeb 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -46,6 +46,7 @@ RUN ./setup.ps1 COPY main.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell +COPY ./omsagentwindows/installer/scripts/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell From d67e4949e7a0812319671a237377f81e542af499 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 25 Sep 2021 09:28:07 -0700 Subject: [PATCH 3/9] optimize windows agent liveness probe --- build/windows/Makefile.ps1 | 3 ++- .../installer/livenessprobe/livenessprobe.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build/windows/Makefile.ps1 b/build/windows/Makefile.ps1 index c8721efeb..9f3c438b0 100644 --- a/build/windows/Makefile.ps1 +++ b/build/windows/Makefile.ps1 @@ -168,7 +168,7 @@ Write-Host("copying out_oms.so file to : $publishdir") Copy-Item -Path (Join-path -Path $outomsgoplugindir -ChildPath "out_oms.so") -Destination $publishdir -Force Write-Host("successfully copied out_oms.so file to : $publishdir") -ForegroundColor Green -# compile and build the liveness probe +# compile and build the liveness probe cpp code Write-Host("Start:build livenessprobe cpp code") $livenessprobesrcpath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.cpp" $livenessprobeexepath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.exe" @@ -178,6 +178,7 @@ if (Test-Path -Path $livenessprobeexepath){ Write-Host("livenessprobe.exe exists which indicates cpp build step succeeded") -ForegroundColor Green } else { Write-Host("livenessprobe.exe doesnt exist which indicates cpp build step failed") -ForegroundColor Red + exit } $installerdir = Join-Path -Path $builddir -ChildPath "common\installer" diff --git a/build/windows/installer/livenessprobe/livenessprobe.cpp b/build/windows/installer/livenessprobe/livenessprobe.cpp index 3aa5bb95b..f6ca6584e 100644 --- a/build/windows/installer/livenessprobe/livenessprobe.cpp +++ b/build/windows/installer/livenessprobe/livenessprobe.cpp @@ -17,7 +17,9 @@ #define FLUENTDWINAKS_SERVICE_NOT_RUNNING 0x00000004 #define UNEXPECTED_ERROR 0xFFFFFFFF - +/* + check if the process running or not for given exe file name +*/ bool IsProcessRunning(const wchar_t * const executableName) { PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); @@ -41,13 +43,18 @@ bool IsProcessRunning(const wchar_t * const executableName) { return false; } - +/* + check if the file exists +*/ bool IsFileExists(const wchar_t* const fileName) { DWORD dwAttrib = GetFileAttributes(fileName); return dwAttrib != INVALID_FILE_SIZE; } +/* + Get the status of the service for given service name +*/ int GetServiceStatus(const wchar_t * const serivceName) { SC_HANDLE theService, scm; @@ -82,7 +89,7 @@ int GetServiceStatus(const wchar_t * const serivceName) return ssStatus.dwCurrentState; } /** - + **/ int _tmain(int argc, wchar_t * argv[]) { From ae4f86b276b94d666247e75e7b5b0349c73f48ef Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 25 Sep 2021 12:00:31 -0700 Subject: [PATCH 4/9] optimize windows agent liveness probe --- kubernetes/windows/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index 0769e2eeb..78c4420ad 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -46,7 +46,7 @@ RUN ./setup.ps1 COPY main.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell -COPY ./omsagentwindows/installer/scripts/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ +COPY ./omsagentwindows/installer/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell From 96ff7aa63490fdbd14a1ecc9c65743921203057d Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 25 Sep 2021 14:10:47 -0700 Subject: [PATCH 5/9] optimize windows agent liveness probe --- .../installer/livenessprobe/livenessprobe.cpp | 23 ++++-------- .../installer/scripts/livenessprobe.cmd | 36 ------------------- kubernetes/omsagent.yaml | 5 ++- kubernetes/windows/Dockerfile | 1 - 4 files changed, 11 insertions(+), 54 deletions(-) delete mode 100644 build/windows/installer/scripts/livenessprobe.cmd diff --git a/build/windows/installer/livenessprobe/livenessprobe.cpp b/build/windows/installer/livenessprobe/livenessprobe.cpp index f6ca6584e..3fde9fa34 100644 --- a/build/windows/installer/livenessprobe/livenessprobe.cpp +++ b/build/windows/installer/livenessprobe/livenessprobe.cpp @@ -93,43 +93,34 @@ int GetServiceStatus(const wchar_t * const serivceName) **/ int _tmain(int argc, wchar_t * argv[]) { - wprintf_s(L"INFO:number of passed arguments - %d \n", argc); if( argc < 5) { wprintf_s(L"ERROR:unexpected number arguments and expected is 5"); return UNEXPECTED_ERROR; } - if (IsProcessRunning(argv[1])) + if (!IsProcessRunning(argv[1])) { - wprintf_s(L"INFO:%s is running\n", argv[1]); - } - else - { - wprintf_s(L"ERROR: %s is not running\n", argv[1]); + wprintf_s(L"ERROR:Process:%s is not running\n", argv[1]); return NO_FLUENT_BIT_PROCESS; } DWORD dwStatus = GetServiceStatus(argv[2]); - if (dwStatus == SERVICE_RUNNING) - { - wprintf_s(L"INFO:%s is running\n", argv[2]); - } - else + if (dwStatus != SERVICE_RUNNING) { - wprintf_s(L"ERROR: %s is running\n", argv[2]); - return FLUENTDWINAKS_SERVICE_NOT_RUNNING; + wprintf_s(L"ERROR:Service:%s is not running\n", argv[2]); + return FLUENTDWINAKS_SERVICE_NOT_RUNNING; } if (IsFileExists(argv[3])) { - wprintf_s(L"INFO:%s exists which indicates Config Map Updated since agent started.\n", argv[3]); + wprintf_s(L"INFO:File:%s exists indicates Config Map Updated since agent started.\n", argv[3]); return FILESYSTEM_WATCHER_FILE_EXISTS; } if (IsFileExists(argv[4])) { - wprintf_s(L"INFO:%s exists indicates Certificate needs to be renewed.\n", argv[4]); + wprintf_s(L"INFO:File:%s exists indicates Certificate needs to be renewed.\n", argv[4]); return CERTIFICATE_RENEWAL_REQUIRED; } diff --git a/build/windows/installer/scripts/livenessprobe.cmd b/build/windows/installer/scripts/livenessprobe.cmd deleted file mode 100644 index 19d0b69d7..000000000 --- a/build/windows/installer/scripts/livenessprobe.cmd +++ /dev/null @@ -1,36 +0,0 @@ -REM "Checking if fluent-bit is running" - -tasklist /fi "imagename eq fluent-bit.exe" /fo "table" | findstr fluent-bit - -IF ERRORLEVEL 1 ( - echo "Fluent-Bit is not running" - exit /b 1 -) - -REM "Checking if config map has been updated since agent start" - -IF EXIST C:\etc\omsagentwindows\filesystemwatcher.txt ( - echo "Config Map Updated since agent started" - exit /b 1 -) - -REM "Checking if certificate needs to be renewed (aka agent restart required)" - -IF EXIST C:\etc\omsagentwindows\renewcertificate.txt ( - echo "Certificate needs to be renewed" - exit /b 1 -) - -REM "Checking if fluentd service is running" -sc query fluentdwinaks | findstr /i STATE | findstr RUNNING - -IF ERRORLEVEL 1 ( - echo "Fluentd Service is NOT Running" - exit /b 1 -) - -exit /b 0 - - - - diff --git a/kubernetes/omsagent.yaml b/kubernetes/omsagent.yaml index f7e828b85..98621b5f0 100644 --- a/kubernetes/omsagent.yaml +++ b/kubernetes/omsagent.yaml @@ -833,8 +833,11 @@ spec: command: - cmd - /c - - fluent-bit.exe fluentdwinaks "C:\etc\omsagentwindows\filesystemwatcher.txt" "C:\etc\omsagentwindows\renewcertificate.txt" - C:\opt\omsagentwindows\scripts\cmd\livenessprobe.exe + - fluent-bit.exe + - fluentdwinaks + - "C:\\etc\\omsagentwindows\\filesystemwatcher.txt" + - "C:\\etc\\omsagentwindows\\renewcertificate.txt" periodSeconds: 60 initialDelaySeconds: 180 timeoutSeconds: 15 diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index 78c4420ad..aa756b8b8 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -47,7 +47,6 @@ RUN ./setup.ps1 COPY main.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ -COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell # copy ruby scripts to /opt folder From a9b004263aef4ce8127bc882836d6011dc0bc936 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 25 Sep 2021 14:18:27 -0700 Subject: [PATCH 6/9] optimize windows agent liveness probe --- .../installer/livenessprobe/livenessprobe.cpp | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/build/windows/installer/livenessprobe/livenessprobe.cpp b/build/windows/installer/livenessprobe/livenessprobe.cpp index 3fde9fa34..063020ec1 100644 --- a/build/windows/installer/livenessprobe/livenessprobe.cpp +++ b/build/windows/installer/livenessprobe/livenessprobe.cpp @@ -10,30 +10,34 @@ #include #include -#define SUCCESS 0x00000000 -#define NO_FLUENT_BIT_PROCESS 0x00000001 -#define FILESYSTEM_WATCHER_FILE_EXISTS 0x00000002 -#define CERTIFICATE_RENEWAL_REQUIRED 0x00000003 -#define FLUENTDWINAKS_SERVICE_NOT_RUNNING 0x00000004 -#define UNEXPECTED_ERROR 0xFFFFFFFF +#define SUCCESS 0x00000000 +#define NO_FLUENT_BIT_PROCESS 0x00000001 +#define FILESYSTEM_WATCHER_FILE_EXISTS 0x00000002 +#define CERTIFICATE_RENEWAL_REQUIRED 0x00000003 +#define FLUENTDWINAKS_SERVICE_NOT_RUNNING 0x00000004 +#define UNEXPECTED_ERROR 0xFFFFFFFF /* check if the process running or not for given exe file name */ -bool IsProcessRunning(const wchar_t * const executableName) { +bool IsProcessRunning(const wchar_t *const executableName) +{ PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); - if (!Process32First(snapshot, &entry)) { + if (!Process32First(snapshot, &entry)) + { CloseHandle(snapshot); wprintf_s(L"ERROR:IsProcessRunning::Process32First failed"); return false; } - do { - if (!_wcsicmp(entry.szExeFile, executableName)) { + do + { + if (!_wcsicmp(entry.szExeFile, executableName)) + { CloseHandle(snapshot); return true; } @@ -46,7 +50,7 @@ bool IsProcessRunning(const wchar_t * const executableName) { /* check if the file exists */ -bool IsFileExists(const wchar_t* const fileName) +bool IsFileExists(const wchar_t *const fileName) { DWORD dwAttrib = GetFileAttributes(fileName); return dwAttrib != INVALID_FILE_SIZE; @@ -55,34 +59,37 @@ bool IsFileExists(const wchar_t* const fileName) /* Get the status of the service for given service name */ -int GetServiceStatus(const wchar_t * const serivceName) +int GetServiceStatus(const wchar_t *const serivceName) { SC_HANDLE theService, scm; SERVICE_STATUS_PROCESS ssStatus; DWORD dwBytesNeeded; scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_ENUMERATE_SERVICE); - if (!scm) { + if (!scm) + { wprintf_s(L"ERROR:GetServiceStatus::OpenSCManager failed"); return UNEXPECTED_ERROR; } theService = OpenService(scm, serivceName, SERVICE_QUERY_STATUS); - if (!theService) { + if (!theService) + { CloseServiceHandle(scm); wprintf_s(L"ERROR:GetServiceStatus::OpenService failed"); return UNEXPECTED_ERROR; } auto result = QueryServiceStatusEx(theService, SC_STATUS_PROCESS_INFO, - reinterpret_cast(&ssStatus), sizeof(SERVICE_STATUS_PROCESS), - &dwBytesNeeded); + reinterpret_cast(&ssStatus), sizeof(SERVICE_STATUS_PROCESS), + &dwBytesNeeded); CloseServiceHandle(theService); CloseServiceHandle(scm); - if (result == 0) { - wprintf_s(L"ERROR:GetServiceStatus:QueryServiceStatusEx failed"); + if (result == 0) + { + wprintf_s(L"ERROR:GetServiceStatus:QueryServiceStatusEx failed"); return UNEXPECTED_ERROR; } @@ -91,9 +98,10 @@ int GetServiceStatus(const wchar_t * const serivceName) /** **/ -int _tmain(int argc, wchar_t * argv[]) +int _tmain(int argc, wchar_t *argv[]) { - if( argc < 5) { + if (argc < 5) + { wprintf_s(L"ERROR:unexpected number arguments and expected is 5"); return UNEXPECTED_ERROR; } @@ -108,8 +116,8 @@ int _tmain(int argc, wchar_t * argv[]) if (dwStatus != SERVICE_RUNNING) { - wprintf_s(L"ERROR:Service:%s is not running\n", argv[2]); - return FLUENTDWINAKS_SERVICE_NOT_RUNNING; + wprintf_s(L"ERROR:Service:%s is not running\n", argv[2]); + return FLUENTDWINAKS_SERVICE_NOT_RUNNING; } if (IsFileExists(argv[3])) From 499d40647fe878187e075ccf9eb53332f57e52fb Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sun, 26 Sep 2021 14:48:21 -0700 Subject: [PATCH 7/9] optimize windows agent liveness probe --- build/windows/installer/livenessprobe/livenessprobe.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/build/windows/installer/livenessprobe/livenessprobe.cpp b/build/windows/installer/livenessprobe/livenessprobe.cpp index 063020ec1..eea792686 100644 --- a/build/windows/installer/livenessprobe/livenessprobe.cpp +++ b/build/windows/installer/livenessprobe/livenessprobe.cpp @@ -95,6 +95,7 @@ int GetServiceStatus(const wchar_t *const serivceName) return ssStatus.dwCurrentState; } + /** **/ From 781d8f98991345b899bee8def4487acbd009fe58 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Mon, 27 Sep 2021 08:36:37 -0700 Subject: [PATCH 8/9] optimize windows agent liveness probe --- build/windows/installer/scripts/livenessprobe.cmd | 2 ++ kubernetes/omsagent.yaml | 6 +----- kubernetes/windows/Dockerfile | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 build/windows/installer/scripts/livenessprobe.cmd diff --git a/build/windows/installer/scripts/livenessprobe.cmd b/build/windows/installer/scripts/livenessprobe.cmd new file mode 100644 index 000000000..c76e2b1f8 --- /dev/null +++ b/build/windows/installer/scripts/livenessprobe.cmd @@ -0,0 +1,2 @@ +REM "invoking livenessprobe.exe" +livenessprobe.exe fluent-bit.exe fluentdwinaks C:\etc\omsagentwindows\filesystemwatcher.txt C:\etc\omsagentwindows\renewcertificate.txt diff --git a/kubernetes/omsagent.yaml b/kubernetes/omsagent.yaml index 98621b5f0..d84e46701 100644 --- a/kubernetes/omsagent.yaml +++ b/kubernetes/omsagent.yaml @@ -833,11 +833,7 @@ spec: command: - cmd - /c - - C:\opt\omsagentwindows\scripts\cmd\livenessprobe.exe - - fluent-bit.exe - - fluentdwinaks - - "C:\\etc\\omsagentwindows\\filesystemwatcher.txt" - - "C:\\etc\\omsagentwindows\\renewcertificate.txt" + - C:\opt\omsagentwindows\scripts\cmd\livenessProbe.cmd periodSeconds: 60 initialDelaySeconds: 180 timeoutSeconds: 15 diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index aa756b8b8..78c4420ad 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -47,6 +47,7 @@ RUN ./setup.ps1 COPY main.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ +COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell # copy ruby scripts to /opt folder From 0ace964deeb5f97d079a0af3b07782389e7f7173 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Mon, 27 Sep 2021 09:54:29 -0700 Subject: [PATCH 9/9] optimize windows agent liveness probe --- build/windows/installer/scripts/livenessprobe.cmd | 2 -- kubernetes/omsagent.yaml | 6 +++++- kubernetes/windows/Dockerfile | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 build/windows/installer/scripts/livenessprobe.cmd diff --git a/build/windows/installer/scripts/livenessprobe.cmd b/build/windows/installer/scripts/livenessprobe.cmd deleted file mode 100644 index c76e2b1f8..000000000 --- a/build/windows/installer/scripts/livenessprobe.cmd +++ /dev/null @@ -1,2 +0,0 @@ -REM "invoking livenessprobe.exe" -livenessprobe.exe fluent-bit.exe fluentdwinaks C:\etc\omsagentwindows\filesystemwatcher.txt C:\etc\omsagentwindows\renewcertificate.txt diff --git a/kubernetes/omsagent.yaml b/kubernetes/omsagent.yaml index d84e46701..98621b5f0 100644 --- a/kubernetes/omsagent.yaml +++ b/kubernetes/omsagent.yaml @@ -833,7 +833,11 @@ spec: command: - cmd - /c - - C:\opt\omsagentwindows\scripts\cmd\livenessProbe.cmd + - C:\opt\omsagentwindows\scripts\cmd\livenessprobe.exe + - fluent-bit.exe + - fluentdwinaks + - "C:\\etc\\omsagentwindows\\filesystemwatcher.txt" + - "C:\\etc\\omsagentwindows\\renewcertificate.txt" periodSeconds: 60 initialDelaySeconds: 180 timeoutSeconds: 15 diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index 78c4420ad..aa756b8b8 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -47,7 +47,6 @@ RUN ./setup.ps1 COPY main.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell COPY ./omsagentwindows/installer/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/ -COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/ COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell # copy ruby scripts to /opt folder