Skip to content

Conversation

@jefchien
Copy link
Contributor

@jefchien jefchien commented Jan 15, 2026

Description of the issue

Follow up for #1981. With the support of the credential chain, the CloudWatch agent components can start to be migrated.

Description of changes

  • Migrates from the forked CloudWatch v1 SDK to the v2 SDK
    • Main changes are to the type definitions and imports
      • StorageResolution: int -> int32
      • Unit: string -> types.StandardUnit (enum)
      • Entity fields: map[string]*string -> map[string]string
    • Removes the forked CloudWatch v1 SDK
  • All API calls in SDKv2 require a context.Context. Typically this would be supplied by ConsumeMetrics, but since the exporter does aggregation, it's a bit harder to use. Decided to just use a context.Background() during publishing.
  • Creates v2 version of log throttle retryer (since other components still use the v1 retryer)
  • Updates dependencies in go.mod
  • Minor fixes to the credentials based off of feedback from previous PR

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

Kept unit tests as intact as possible.
PR Build:

Ran integration tests against branch (https://github.com/aws/amazon-cloudwatch-agent/actions/runs/21011127722).

null_resource.integration_test_run (remote-exec): ValidateCredentialProvider: SharedCredentialsProvider   Failed       failed to parse agent logs: provider mis-match: expected SharedCredentialsProvider, got SharedConfigCredentials
  • The ca_bundle_test fails due to a bug in the credentials chain. Will fix it in a separate PR.

Ran the agent with metric collection enabled and debug SDK logging. Can see it successfully send and can see metrics in CloudWatch.

2026-01-14T20:33:36Z D! Request
POST /service/GraniteServiceVersion20100801/operation/PutMetricData HTTP/1.1
Host: monitoring.us-east-1.amazonaws.com
User-Agent: CWAgent/1.300064.0-5-g0fe190625 (go1.25.5; linux; amd64) ID/<snip> inputs:(cpu) processors:(awsentity) outputs:(awscloudwatch cloudwatch) aws-sdk-go-v2/1.41.1 ua/2.1 os/linux lang/go#1.25.5 md/GOOS#linux md/GOARCH#amd64 api/cloudwatch#1.53.1 m/0,L,M
Content-Length: 1282
Accept: application/cbor
Amz-Sdk-Invocation-Id: <snip>
Amz-Sdk-Request: attempt=1; max=3
Authorization: AWS4-HMAC-SHA256 Credential=<snip>, SignedHeaders=accept;amz-sdk-invocation-id;amz-sdk-request;content-encoding;content-length;content-type;host;smithy-protocol;x-amz-agent-stats;x-amz-date;x-amz-security-token;x-amzn-query-mode, Signature=<snip>
Content-Encoding: gzip
Content-Type: application/cbor
Smithy-Protocol: rpc-v2-cbor
X-Amz-Agent-Stats: "cpu":0.6,"mem":103895040,"fd":11,"th":7,"ric":0,"rt":"EC2M","m":"EC2"
X-Amz-Date: 20260114T203336Z
X-Amz-Security-Token: <snip>
X-Amzn-Query-Mode: true
Accept-Encoding: gzip

2026-01-14T20:33:36Z D! Response
HTTP/1.1 200 OK
Content-Length: 0
Date: Wed, 14 Jan 2026 20:33:36 GMT
Smithy-Protocol: rpc-v2-cbor
X-Amzn-Requestid: <snip>

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.

@jefchien jefchien requested a review from a team as a code owner January 15, 2026 23:01
select {
case m := <-durationAgg.aggregationChan:
if m == nil || m.Timestamp == nil || m.MetricName == nil || m.Unit == nil {
if m == nil || m.Timestamp == nil || m.MetricName == nil || m.Unit == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

type change from sdkv2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the v2 unit is a type.StandardUnit, which is a string enum, so the 0 value is "".

func payload(datum *cloudwatch.MetricDatum) (size int) {
size += timestampSize
func payload(datum *types.MetricDatum) int {
size := timestampSize
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't these lead to different payload sizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. Named returns just initialize a zero value field at the start of a function, so

func test() (size int) {
  size += 1
  return
}

and

func test() int {
  return 1
}

are equivalent. We have a few unit tests for it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants