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

Enable the ability to configure the ClientTimeout of the http client that interacts with the Consul API #1178

Merged
merged 59 commits into from
May 4, 2022

Conversation

jmurret
Copy link
Member

@jmurret jmurret commented Apr 19, 2022

Related to issue: #714

Note: This PR imports the consul api package from the branch in this PR rather than a released version. We have validated that this change works for the customer and will update this PR when the COnsul change gets merged.

Changes proposed in this PR:

  • Defined global. consulAPITimeout with a default of 5s
  • Everything in charts/consul/templates passes -consul-api-timeout={{ .Values.global.consulAPITimeout }} to control-plane commands
  • Everything in charts/consul/test/unit asserts that those argument passings occur.
  • Everything in control-plane/ ensures:
    • -consul-api-timeout is greater than zero
    • -consul-api-timeout is used when creating consul Client

How I've tested this PR:

  • Unit test added
  • Acceptance test passed

How I expect reviewers to test this PR:

  • 👀

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

Excellent work @jmurret !!!

@@ -43,3 +43,13 @@ func TestNewClient(t *testing.T) {
UserAgentHeader: fmt.Sprintf("consul-k8s/%s", version.GetHumanVersion()),
}, consulAPICalls[0])
}

func TestNewClient_httpClientDefaultTimeout(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/consul/api v1.10.1-0.20220413234639-3e88f579fce3
github.com/hashicorp/consul/api v1.10.1-0.20220425143126-6d0162a58a94
Copy link
Member Author

Choose a reason for hiding this comment

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

this temporarily points to consul core dev branch.

github.com/hashicorp/consul/api v1.10.1-0.20220421045807-e7bb156a82e2 h1:kwb0ddQK6XTg9AVQgxe517Q0vrJ7MIPMIrp0yP/EZbE=
github.com/hashicorp/consul/api v1.10.1-0.20220421045807-e7bb156a82e2/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ=
github.com/hashicorp/consul/api v1.10.1-0.20220425143126-6d0162a58a94 h1:mPhpaeGO4BmD0Fi9gmevT7kYDyDml1kNjf0HKCFF5xM=
github.com/hashicorp/consul/api v1.10.1-0.20220425143126-6d0162a58a94/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ=
Copy link
Member Author

Choose a reason for hiding this comment

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

this temporarily points to consul core dev branch.

@jmurret jmurret requested a review from thisisnotashwin May 2, 2022 20:14
Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

Excellent work on the PR @jmurret !!

Comment on lines +3676 to +3679
// Splitting this into two asserts on fragments of the error because the error thrown
// can be either of the two below and matching on the whole string causes the test tobe flakey
// "1 error occurred:\n\t* Get \"http://126.0.0.1:31200/v1/agent/services?filter=Meta%5B%22k8s-service-name%22%5D+%3D%3D+%22service-created%22+and+Meta%5B%22k8s-namespace%22%5D+%3D%3D+%22default%22+and+Meta%5B%22managed-by%22%5D+%3D%3D+%22consul-k8s-endpoints-controller%22\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)\n\n"
// "1 error occurred:\n\t* Get \"http://126.0.0.1:31200/v1/agent/services?filter=Meta%5B%22k8s-service-name%22%5D+%3D%3D+%22service-created%22+and+Meta%5B%22k8s-namespace%22%5D+%3D%3D+%22default%22+and+Meta%5B%22managed-by%22%5D+%3D%3D+%22consul-k8s-endpoints-controller%22\": dial tcp 126.0.0.1:31200: i/o timeout (Client.Timeout exceeded while awaiting headers)\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the rationale! This makes sense.

@@ -234,6 +228,23 @@ func (c *Command) Run(args []string) int {
return 0
}

func (c *Command) validateFlags() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@@ -161,3 +169,43 @@ func (s *StringValue) String() string {
}
return current
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This is excellent!!!

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

So thorough!! LGTM!

@@ -161,3 +169,43 @@ func (s *StringValue) String() string {
}
return current
}

// DurationValue provides a flag value that's aware if it has been set.
type DurationValue struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

How are these DurationValue functions being used/meant to be used? Was it because we didn't have any duration related flags before and all duration flags need to implement these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the StringValue was copied from this same file from consul core: https://github.com/hashicorp/consul/blob/21e855d860865f1472b3fdcb64a916e92bc83a9f/command/flags/config.go#L91 and there is a comment at the top of this file from a while ago about why we have copied them.

I originally had this an IntValue but ultimately it is going to become a duration and we already have some places in our helm values where you can configure duration like "5s", "500ms", etc., so I changed it to make it consistent and more flexible.

@jmurret jmurret changed the title Providing endpoints controller with an http client with a timeout Enable the ability to configure the ClientTimeout of the http client that interacts with the Consul API May 3, 2022
@jmurret jmurret merged commit 488e8ac into main May 4, 2022
@jmurret jmurret deleted the jm/endpoints-bug branch May 4, 2022 02:48
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