Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

added support for --listen-metrics-url parameter #160

Closed
wants to merge 2 commits into from

Conversation

suhrud-kumar
Copy link

support for #157

@dlipovetsky
Added new flag --listen-metrics-url

  • If user passes a URL to this parameter, we'll use that URL to expose additional metrics endpoint in http
  • By default (without passing any extra params) this will expose /metrics endpoint on http://client-ip:9379

I can't seem to make this optional without messing up with existing code structure. Let me know if I need to make any changes

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 8, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: suhrud-kumar
To complete the pull request process, please assign luxas
You can assign the PR to them by writing /assign @luxas in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Hi @suhrud-kumar. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 8, 2020
@dlipovetsky
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 8, 2020
@dlipovetsky
Copy link
Contributor

I can't seem to make this optional without messing up with existing code structure. Let me know if I need to make any changes

I want to make sure I understand what you mean here. When you say"make this optional," are you saying "make the use of a separate metrics endpoint optional?" By optional, I mean: If the --listen-metrics-url flag is not used, then etcd does not use a separate metrics endpoint.

util/url_value.go Outdated Show resolved Hide resolved
@@ -235,4 +236,5 @@ func init() {
joinCmd.PersistentFlags().StringVar(&etcdAdmConfig.InstallDir, "install-dir", constants.DefaultInstallDir, "install directory")
joinCmd.PersistentFlags().StringArrayVar(&etcdAdmConfig.EtcdDiskPriorities, "disk-priorities", constants.DefaultEtcdDiskPriorities, "Setting etcd disk priority")
joinCmd.PersistentFlags().BoolVar(&etcdAdmConfig.Retry, "retry", true, "Enable or disable backoff retry when join etcd member to cluster")
joinCmd.PersistentFlags().Var(util.URLValue{URL: &etcdAdmConfig.AdditionalMetricsURL}, "listen-metrics-url", "URL to expose additional /metrics endpoint without TLS")
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the user passes in a string that isn't a valid URL?

Copy link
Author

Choose a reason for hiding this comment

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

we use url.ParseRequestURI() function in URLValue Set function to parse it into a valid URL, if not it returns an error.

[root@ip-172-31-17-207 tmp]# ./etcdadm init --listen-metrics-url http//1.1.1.1
Error: invalid argument "http//1.1.1.1" for "--listen-metrics-url" flag: parse http//1.1.1.1: invalid URI for request

[root@ip-172-31-17-207 tmp]# ./etcdadm init --listen-metrics-url 1.1.1.1
Error: invalid argument "1.1.1.1" for "--listen-metrics-url" flag: parse 1.1.1.1: invalid URI for request

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 explaining. I overlooked the use of .Var.

The UX looks good! (Do you think it would be nice if the error gives an example of a valid URI?)

@@ -0,0 +1,49 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the Set and Type receivers used anywhere?

Copy link
Author

@suhrud-kumar suhrud-kumar May 8, 2020

Choose a reason for hiding this comment

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

Set is used to set argument passed to the assigned variable.

Since URLValue is an implementation of Value interface in pflag, all three functions are required - https://godoc.org/github.com/spf13/pflag#Value

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. I missed this.

@suhrud-kumar
Copy link
Author

By optional, I mean: If the --listen-metrics-url flag is not used, then etcd does not use a separate metrics endpoint.

Yes, thats what I meant.

Just to clarify, with current implementation we have below two options

etcdadm init -> additional http /metrics endpoint on http://<etcd-client-ip>:defaultport
etcdadm init --listen-metrics-url http://ip:port -> additional http /metrics endpoint on user requested URL

but we don't have an option to disable this.

Initially I wanted to design something like below

etcdadm init -> no additional http /metrics endpoint
etcdadm init --listen-metrics-url -> additional http /metrics endpoint on http://<client-ip>:defaultport
etcdadm init --listen-metrics-url http://ip:port -> additional http /metrics endpoint on use requested URL

Since etcdadm is for making etcd operations simple, I think we can accommodate this design consideration.

@suhrud-kumar
Copy link
Author

I signed it

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 8, 2020
@dlipovetsky
Copy link
Contributor

etcdadm init -> no additional http /metrics endpoint
etcdadm init --listen-metrics-url -> additional http /metrics endpoint on http://:defaultport
etcdadm init --listen-metrics-url http://ip:port -> additional http /metrics endpoint on use requested URL

I favor this, because etcdadm typically uses etcd defaults, and by default, etcd does not enable a separate http metrics endpoint.

I think you can use https://godoc.org/github.com/spf13/pflag#FlagSet.Changed to tell between etcdadm init and etcdadm init --listen-metrics-url. WDYT?

@suhrud-kumar
Copy link
Author

suhrud-kumar commented May 11, 2020

etcdadm init -> no additional http /metrics endpoint
etcdadm init --listen-metrics-url -> additional http /metrics endpoint on http://:defaultport
etcdadm init --listen-metrics-url http://ip:port -> additional http /metrics endpoint on use requested URL

I favor this, because etcdadm typically uses etcd defaults, and by default, etcd does not enable a separate http metrics endpoint.

Yes, that is what I wanted to implement at first. But since this is the only flag that uses this, it could somewhat mess up existing code structure.

I think you can use https://godoc.org/github.com/spf13/pflag#FlagSet.Changed to tell between etcdadm init and etcdadm init --listen-metrics-url. WDYT?

pflag would throw an error if there is no argument or no default value for a flag (probably only for non-boolean flags)

[root@ip-172-31-16-230 tmp]# ./etcdadm init --snapshot
Error: flag needs an argument: --snapshot

[root@ip-172-31-16-230 tmp]# ./etcdadm init --listen-metrics-url
Error: flag needs an argument: --listen-metrics-url

So we have to use this https://github.com/spf13/pflag#setting-no-option-default-values-for-flags

So, init function looks like

initCmd.PersistentFlags().Var(util.URLValue{URL: &etcdAdmConfig.AdditionalMetricsURL}, "listen-metrics-url", "URL to expose additional /metrics endpoint without TLS")
initCmd.PersistentFlags().Lookup("listen-metrics-url").NoOptDefVal = apis.DefaultAdditionalMetricsURL()

and additional method in apis/config.go pkg

// DefaultAdditionalMetricsURL sets additional metrics url using node ip
func DefaultAdditionalMetricsURL() string {
	externalAddress, err := defaultExternalAddress()
	if err != nil {
		log.Fatalf("failed to set default DefaultAdditionalMetricsURL: %s", err)
	}
	url := url.URL{
		Scheme: constants.DefaultAdditionalMetricsScheme,
		Host:   fmt.Sprintf("%s:%d", externalAddress.String(), constants.DefaultAdditionalMetricsPort),
	}
	return url.String()
}

Let me know if you are okay with this and I can push it.

Also, I think I found a bug (?) in pflag NoOptDefVal func, it doesn't work in all cases, will open a issue with them.

@suhrud-kumar
Copy link
Author

Also, I think I found a bug (?) in pflag NoOptDefVal func, it doesn't work in all cases, will open a issue with them.

Looks like this is an expected behaviour with pflag - spf13/pflag#134
https://github.com/spf13/pflag#command-line-flag-syntax

So, if we use NoOptDefVal for this param
--listen-metrics-url # valid, sets to default ip
--listen-metrics-url=http://<node-ip>:1234 # valid, sets to user provided ip
--listen-metrics-url http://<node-ip>:1234 # invalid, sets to default ip

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 9, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 8, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants