Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix(discovery/aws): Fixed ECS SD region loading to check AWS config before IMDS.#17684

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
akshatsinha0 wants to merge1 commit intoprometheus:main
base:main
Choose a base branch
Loading
fromakshatsinha0:fix-ecs-region-loading

Conversation

@akshatsinha0
Copy link
Contributor

@akshatsinha0akshatsinha0 commentedDec 14, 2025
edited
Loading

Which issue(s) does the PR fix:

NONE

Description:

This PR fixes the ECS service discovery region loading logic to match the behavior of EC2 and Lightsail discovery.

Problem:
The ECS discovery was added after the region loading bugfix (PR#17376) was applied to EC2 and Lightsail. ECS has incomplete region detection logic...
It skips checkingcfg.Region (which loads fromAWS_REGION env var and~/.aws/config)
usedcontext.Background() (like other AWS discoveries)

Does this PR introduce a user-facing change?

Does this PR introduce a user-facing change?

[BUGFIX] ECS service discovery: Fix region loading to check AWS config before IMDS.

@akshatsinha0
Copy link
ContributorAuthor

@krajorama Please have a look here.

@bboreham
Copy link
Member

Please rebase on main after#17695 to fix the Fuzzing CI failure.

Also you seem to have some format issue.

@akshatsinha0
Copy link
ContributorAuthor

Yes i will

…efore IMDS.Signed-off-by: Akshat Sinha <akshatsinhasramhardy@gmail.com>

ifc.Region=="" {
cfg,err:=awsConfig.LoadDefaultConfig(context.TODO())
cfg,err:=awsConfig.LoadDefaultConfig(context.Background())
Copy link
Member

Choose a reason for hiding this comment

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

I cannot comment on whether this is correct or not, will ask@sysadmind and@matt-gp about that, but given that now we'll have this code 3 times copied, let's refactor into a function, something like:

func ensureRegion(region string) (string, error) {if region != "" {return region, nil}cfg, err := awsConfig.LoadDefaultConfig(context.Background())if err != nil {return "", err}if cfg.Region != "" {// Use the region from the AWS config. It will load environment variables and shared config files.return cfg.Region, nil}// Try to get the region from the instance metadata service (IMDS).imdsClient := imds.NewFromConfig(cfg)imdsRegion, err := imdsClient.GetRegion(context.Background(), &imds.GetRegionInput{})if err != nil {return "", err}return imdsRegion.Region, nil}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think abstracting to a function is worthwhile. Its the same code in 3 places.

This PR is okay as it sits though from a correctness perspective. LGTM

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

Reviewers

@krajoramakrajoramakrajorama left review comments

@sysadmindsysadmindAwaiting requested review from sysadmind

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@akshatsinha0@bboreham@sysadmind@krajorama

[8]ページ先頭

©2009-2025 Movatter.jp