Skip to content

Optimize logic of retrieving user agent appID from env config#2314

Merged
wty-Bryant merged 3 commits intomainfrom
feat-optimize-ua-appID
Oct 13, 2023
Merged

Optimize logic of retrieving user agent appID from env config#2314
wty-Bryant merged 3 commits intomainfrom
feat-optimize-ua-appID

Conversation

@wty-Bryant
Copy link
Copy Markdown
Collaborator

@wty-Bryant wty-Bryant commented Oct 13, 2023

In a previous PR, a new appID field is introduced into request's user agent header. In that old PR, appID set via env var is retrieved separately after iterating resolver chain's all configs, this pr now optimize this step by setting appID as a field of env config so that it be retrieved directly from env config struct

@wty-Bryant wty-Bryant requested a review from a team as a code owner October 13, 2023 16:57
Comment thread config/env_config.go Outdated
}

func (c EnvConfig) getAppID(context.Context) (string, bool, error) {
appID := os.Getenv(`AWS_SDK_UA_APP_ID`)
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.

while this works, i dont think this is the typical setup. see the other fields in env_config.go

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just want to lazy set this field in case it is modified, but you are right, I will change that

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.

i dont think there is actually any reasonable time interval between when NewEnvConfig is called and when getAppId is called. so i dont think lazily evaluating it here makes a difference

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.

Yeah - loadEnvConfig first reads everything out of the environment into the env config struct, and then the "resolvers" e.g. getAppID just read out of the struct. getAppID shouldn't be querying the environment directly. See other fields in env_config as @isaiahvita said.

Copy link
Copy Markdown
Contributor

@lucix-aws lucix-aws Oct 13, 2023

Choose a reason for hiding this comment

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

Just want to lazy set this field in case it is modified,

i dont think there is actually any reasonable time interval

There's no chance of changing or interval to speak of - a process' environment is static.

@isaiahvita
Copy link
Copy Markdown
Contributor

@wty-Bryant also, while i already know the context of this PR. it will be good to clearly explain the motivation for it in the description

Copy link
Copy Markdown
Contributor

@isaiahvita isaiahvita left a comment

Choose a reason for hiding this comment

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

LGTM, wait until the relevant CI passes though before merging

@wty-Bryant wty-Bryant merged commit 1cc8d04 into main Oct 13, 2023
@wty-Bryant wty-Bryant deleted the feat-optimize-ua-appID branch October 13, 2023 20:27
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.

3 participants