Skip to content
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

Reduce timeout for scrapping IMDS and give instruction when fail to scrape IMDS inside container #480

Merged
merged 10 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}

- name: Test
run: make test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
path: |
~/Library/Caches/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}

- name: Test
run: make test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path: |
%LocalAppData%\go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}

- name: Install make
run: choco install make
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
path: |
~/go/pkg/mod
~/.cache/go-build
key: v1-go-pkg-mod-${{ hashFiles('**/go.sum') }}
key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}

- name: Cache binaries
id: cached_binaries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENV GO111MODULE=${GO111MODULE}
COPY go.mod /go/src/github.com/aws/amazon-cloudwatch-agent/
COPY go.sum /go/src/github.com/aws/amazon-cloudwatch-agent/
RUN go mod download -x

COPY . /go/src/github.com/aws/amazon-cloudwatch-agent/
RUN make build-for-docker-${TARGETARCH}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ spec:
hostPath:
path: /dev/disk/
terminationGracePeriodSeconds: 60
serviceAccountName: cloudwatch-agent
serviceAccountName: cloudwatch-agent
79 changes: 79 additions & 0 deletions plugins/processors/ec2tagger/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package ec2tagger

import (
"time"
)

// Reminder, keep this in sync with the plugin's README.md
const sampleConfig = `
##
## ec2tagger calls AWS api to fetch EC2 Metadata and Instance Tags and EBS Volumes associated with the
## current EC2 Instance and attached those values as tags to the metric.
##
## Frequency for the plugin to refresh the EC2 Instance Tags and ebs Volumes associated with this Instance.
## Defaults to 0 (no refresh).
## When it is zero, ec2tagger doesn't do refresh to keep the ec2 tags and ebs volumes updated. However, as the
## AWS api request made by ec2tagger might not return the complete values (e.g. initial api call might return a
## subset of ec2 tags), ec2tagger will retry every 3 minutes until all the tags/volumes (as specified by
## "ec2_instance_tag_keys"/"ebs_device_keys") are retrieved successfully. (Note when the specified list is ["*"],
## there is no way to check if all tags/volumes are retrieved, so there is no retry in that case)
# refresh_interval_seconds = 60
##
## Add tags for EC2 Metadata fields.
## Supported fields are: "InstanceId", "ImageId" (aka AMI), "InstanceType"
## If the configuration is not provided or it has an empty list, no EC2 Metadata tags are applied.
# ec2_metadata_tags = ["InstanceId", "ImageId", "InstanceType"]
##
## Add tags retrieved from the EC2 Instance Tags associated with this instance.
## If this configuration is not provided, or has an empty list, no EC2 Instance Tags are applied.
## If this configuration contains one entry and its value is "*", then ALL EC2 Instance Tags for the instance are applied.
## Note: This plugin renames the "aws:autoscaling:groupName" EC2 Instance Tag key to be spelled "AutoScalingGroupName".
## This aligns it with the AutoScaling dimension-name seen in AWS CloudWatch.
# ec2_instance_tag_keys = ["aws:autoscaling:groupName", "Name"]
##
## Retrieve ebs_volume_id for the specified devices, add ebs_volume_id as tag. The specified devices are
## the values corresponding to the tag key "disk_device_tag_key" in the input metric.
## If this configuration is not provided, or has an empty list, no ebs volume is applied.
## If this configuration contains one entry and its value is "*", then all ebs volume for the instance are applied.
# ebs_device_keys = ["/dev/xvda", "/dev/nvme0n1"]
##
## Specify which tag to use to get the specified disk device name from input Metric
# disk_device_tag_key = "device"
##
## Amazon Credentials
## Credentials are loaded in the following order
## 1) Assumed credentials via STS if role_arn is specified
## 2) explicit credentials from 'access_key' and 'secret_key'
## 3) shared profile from 'profile'
## 4) environment variables
## 5) shared credentials file
## 6) EC2 Instance Profile
# access_key = ""
# secret_key = ""
# token = ""
# role_arn = ""
# profile = ""
# shared_credential_file = ""
`

const (
ec2InstanceTagKeyASG = "aws:autoscaling:groupName"
cwDimensionASG = "AutoScalingGroupName"
mdKeyInstanceId = "InstanceId"
mdKeyImageId = "ImageId"
mdKeyInstanceType = "InstanceType"
ebsVolumeId = "EBSVolumeId"
)

const (
allowedIMDSRetries = 2
)

var (
defaultIMDSTimeout = 1 * time.Second
defaultRefreshInterval = 180 * time.Second
backoffSleepArray = []time.Duration{0, 1 * time.Minute, 1 * time.Minute, 3 * time.Minute, 3 * time.Minute, 3 * time.Minute, 10 * time.Minute} // backoff retry for ec2 describe instances API call. Assuming the throttle limit is 20 per second. 10 mins allow 12000 API calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a random number imo. Think all systems send out the call at the same time. Then next round they all send at the same time. It needs to be random within an interval. This comment is probs out of scope for this pr but something to think about for best behaved agents. @straussb thoughts.

)
Loading