Skip to content

Add workload detection for PostgreSQL - #2220

Merged
Paamicky merged 1 commit into
mainfrom
mcommey/postgresql-workload
Jul 30, 2026
Merged

Add workload detection for PostgreSQL#2220
Paamicky merged 1 commit into
mainfrom
mcommey/postgresql-workload

Conversation

@Paamicky

Copy link
Copy Markdown
Contributor

Description of the issue

Adds workload detection support for PostgreSQL database servers as part of the workload-discovery feature

Description of changes

Implements a PostgreSQL process detector that:

  • Identifies PostgreSQL server instances by checking for the postgres executable
  • Filters out PostgreSQL worker processes by detecting the : pattern in cmdline
  • Extracts the listening port from process arguments (-p flag) or the PGPORT environment variable, defaulting to 5432 if neither is set. This is consistent with the upstream OTEL PostgreSQL receiver default
  • Always returns READY status with the resolved port

New files:

  • nternal/detector/postgresql/postgresql.go - Main detector implementation
  • internal/detector/postgresql/extract/port.go - Port extraction logic
  • Unit tests for both components

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

  • Added unit tests for PostgreSQL detector (postgresql_test.go)
  • Added unit tests for port extractor (port_test.go)
  • make fmt and make lint pass

Test on AL2023:

[ec2-user@ip-172-31-85-207 ~]$  sudo /tmp/workload-discovery -debug
time=2026-06-04T18:55:28.897Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/internal/detector/nvidia/nvidia.go:36 msg="Starting NVIDIA GPU detection"
time=2026-06-04T18:55:28.897Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/internal/detector/nvidia/nvidia.go:39 msg="No NVIDIA GPU devices found"
time=2026-06-04T18:55:28.917Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:105 msg="Starting discovery" num_process=110 num_worker=2
time=2026-06-04T18:55:28.921Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/internal/detector/postgresql/postgresql.go:60 msg="PostgreSQL process detected" pid=108075
time=2026-06-04T18:55:28.921Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:201 msg="Detected supported workload(s) for process" pid=108075 categories=[POSTGRESQL]
time=2026-06-04T18:55:28.922Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:165 msg="Process skipped due to pre-filter" pid=187928
time=2026-06-04T18:55:28.922Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:165 msg="Process skipped due to pre-filter" pid=187930
time=2026-06-04T18:55:28.922Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:165 msg="Process skipped due to pre-filter" pid=187931
time=2026-06-04T18:55:28.922Z level=DEBUG source=github.com/aws/amazon-cloudwatch-agent/cmd/workload-discovery/discovery.go:93 msg="Discovered metadata" elapsed=24.892452ms
[
  {
    "categories": [
      "POSTGRESQL"
    ],
    "name": "postgresql",
    "telemetry_port": 5432,
    "status": "READY"
  }
]
[ec2-user@ip-172-31-85-207 ~]$ 

Requirements

Before commiting your code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

Integration Tests

To run integration tests against this PR, add the ready for testing label.

@Paamicky
Paamicky requested review from JayPolanco and musa-asad July 30, 2026 17:44
@Paamicky Paamicky added the ready for testing Indicates this PR is ready for integration tests to run label Jul 30, 2026
@Paamicky
Paamicky marked this pull request as ready for review July 30, 2026 17:45
@Paamicky
Paamicky requested a review from a team as a code owner July 30, 2026 17:45

@musa-asad musa-asad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return nil, err
}

if len(args) > 0 && strings.HasPrefix(strings.TrimSpace(args[0]), exeName+":") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if cmdline is unreadable here (race with process exit, permission denied), this propagates the raw error even though we already confirmed the exe is postgres at L47. Could return ErrIncompatibleDetector instead so a transient /proc read failure doesn't surface as a detection error for a process we can't confirm is the main server. Low risk since the discoverer just continues past non-nil errors anyway.

@github-actions

Copy link
Copy Markdown
Contributor

Binary Size Report

linux/amd64

Binary PR vs main (706474e) vs v1.300070.0
amazon-cloudwatch-agent 193.2 MB +0 B ${\color{green}▼}$ 38.1 MB (-16.5%)
amazon-cloudwatch-agent-config-wizard 2.0 MB +0 B ${\color{red}▲}$ +86.0 KB (+4.5%)
config-downloader 2.0 MB +0 B ${\color{red}▲}$ +86.0 KB (+4.5%)
config-translator 2.0 MB +0 B ${\color{red}▲}$ +86.0 KB (+4.5%)
start-amazon-cloudwatch-agent 2.5 MB +0 B ${\color{red}▲}$ +81.9 KB (+3.4%)
workload-discovery 3.0 MB ${\color{red}▲}$ +8.2 KB (+0.3%) ${\color{red}▲}$ +94.2 KB (+3.2%)
Total 204.8 MB ${\color{red}▲}$ +8.2 KB (+0.0%) ${\color{green}▼}$ 37.7 MB (-15.5%)
linux/amd64 amazon-cloudwatch-agent (last 9 main commits + this PR)

 235 ┤                                        
     ┤███ ███                                 
     ┤███ ███                                 
     ┤███ ███                                 
     ┤███ ███                                 
     ┤███ ███                                 
     ┤███ ███                                 
     ┤███ ███                                 
 191 ┤███ ███ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ 
 MB  └────────────────────────────────────────
      5d99671                             PR

Notable changes:

linux/arm64
Binary PR vs main (706474e) vs v1.300070.0
amazon-cloudwatch-agent 176.9 MB +0 B ${\color{green}▼}$ 34.5 MB (-16.3%)
amazon-cloudwatch-agent-config-wizard 2.0 MB +0 B ${\color{green}▼}$ 22 B (-0.0%)
config-downloader 2.0 MB +0 B ${\color{green}▼}$ 22 B (-0.0%)
config-translator 2.0 MB +0 B ${\color{green}▼}$ 22 B (-0.0%)
start-amazon-cloudwatch-agent 2.4 MB +0 B ${\color{red}▲}$ +65.5 KB (+2.8%)
workload-discovery 2.9 MB +0 B ${\color{red}▲}$ +65.5 KB (+2.3%)
Total 188.2 MB +0 B ${\color{green}▼}$ 34.4 MB (-15.5%)
windows/amd64
Binary PR vs main (706474e) vs v1.300070.0
amazon-cloudwatch-agent.exe 196.0 MB ${\color{red}▲}$ +6.7 KB (+0.0%) ${\color{green}▼}$ 38.2 MB (-16.3%)
amazon-cloudwatch-agent-config-wizard.exe 2.1 MB +0 B ${\color{red}▲}$ +130.6 KB (+6.5%)
config-downloader.exe 2.1 MB +0 B ${\color{red}▲}$ +130.0 KB (+6.5%)
config-translator.exe 2.1 MB +0 B ${\color{red}▲}$ +130.6 KB (+6.5%)
start-amazon-cloudwatch-agent.exe 2.3 MB +0 B ${\color{red}▲}$ +112.1 KB (+5.2%)
workload-discovery.exe 2.9 MB ${\color{red}▲}$ +5.6 KB (+0.2%) ${\color{red}▲}$ +97.3 KB (+3.5%)
Total 207.7 MB ${\color{red}▲}$ +12.3 KB (+0.0%) ${\color{green}▼}$ 37.6 MB (-15.3%)
Investigating size changes

Use go-size-analyzer to compare binaries:

GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary>

@Paamicky
Paamicky merged commit 0c715d0 into main Jul 30, 2026
417 of 429 checks passed
@Paamicky
Paamicky deleted the mcommey/postgresql-workload branch July 30, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for testing Indicates this PR is ready for integration tests to run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants