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

Add metrics of gophercloud (POST,UPDATE and DELETE) actions #863

Merged
merged 1 commit into from
May 25, 2021

Conversation

jichenjc
Copy link
Contributor

@jichenjc jichenjc commented May 8, 2021

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #856

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 8, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jichenjc

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

The pull request process is described 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 k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 8, 2021
@jichenjc jichenjc force-pushed the add_metrics branch 2 times, most recently from 974ab16 to f306230 Compare May 11, 2021 03:38
@jichenjc jichenjc changed the title WIP:Add metrics Add metrics of gophercloud May 11, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 11, 2021
@sbueringer
Copy link
Member

@seanschneeweiss @chrischdi Maybe one of you has some bandwitdh to review? :)

@jichenjc
Copy link
Contributor Author

jichenjc commented May 11, 2021

I can't create a local env (because difference between 0.3.4 and master)
so I used 0.3.4 and code should be same ,the result are something like

capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.005"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.01"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.025"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.05"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.1"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.25"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="0.5"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="1"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="2.5"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="5"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="10"} 17
capo_openstack_api_request_duration_seconds_bucket{request="server_create",le="+Inf"} 17
capo_openstack_api_request_duration_seconds_sum{request="server_create"} 0.0024148109999999998
capo_openstack_api_request_duration_seconds_count{request="server_create"} 17

@sbueringer @hidekazuna please help review , thanks

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

ObserveRequest always returns the same error which we give to it. So when using it there should be a separate if err != nil part, instead we should use what we had before to not loose context :-)

I think there are lots of more places where we call gophercloud / the OpenStack API to observe metrics.

For example:

I think almost all occurencies can be found using, but ignore the highlighted Extract functions:

for l in $(grep . -r -e "github.com/gophercloud"  | sed -E -e 's/:\t+/;/g' -e 's/"$//g' -e 's/;"/;/g' -e 's/ //g' | grep -v go.sum | grep -v go.mod | grep -v 'test/e2e'); do
  FILE="$(cut -d ";" -f 1 <<< $l)"
  PKG="$(cut -d ";" -f 2 <<< $l | cut -d '"' -f 1 | tr '/' ' ' | awk '{print $NF}')"
  echo "  # $FILE"
  cat $FILE | grep -e "$PKG\.[A-Z][a-zA-Z]+\(" -E -A2 -B2
done

@@ -66,9 +67,14 @@ type OpenStackClusterReconciler struct {
func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := ctrl.LoggerFrom(ctx)

mc := metrics.NewMetricPrometheusContext("snapshot", "create")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are doing a snapshot create here :-) also the r.Client.Get is no openstack request?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's my debug code ... sorry to forget remove them

Comment on lines 276 to 278
if mc.ObserveRequest(err) != nil {
return nil, err
}

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

ObserveRequest just exposes a metric and does return the very same error.

Comment on lines 517 to 428
if mc.ObserveRequest(err) != nil {
return ports.Port{}, err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return ports.Port{}, err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 59 to 61
mc := metrics.NewMetricPrometheusContext("server", "create")

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mc := metrics.NewMetricPrometheusContext("server", "create")
mc := metrics.NewMetricPrometheusContext("server", "create")

Comment on lines 62 to 66
if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 52 to 56
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 129 to 133
if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 231 to 237
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 137 to 142
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return nil, err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Comment on lines 463 to 466

if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mc.ObserveRequest(err) != nil {
return err
}
if err != nil {
if mc.ObserveRequest(err) != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the comments, will check other possible metrics

@jichenjc jichenjc force-pushed the add_metrics branch 2 times, most recently from d806f20 to 89836fe Compare May 11, 2021 06:25
@jichenjc
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-e2e-test

@jichenjc jichenjc force-pushed the add_metrics branch 4 times, most recently from 740f78d to 516b4e1 Compare May 12, 2021 06:29
@jichenjc
Copy link
Contributor Author

@chrischdi I checked again the question you posted above for additional metrics ..
those are GET all which might be overkill , I think POST/PUT is good enough for most customer?

@chrischdi
Copy link
Member

@chrischdi I checked again the question you posted above for additional metrics ..
those are GET all which might be overkill , I think POST/PUT is good enough for most customer?

I think it would be helpful to also have a metric for the get / list requests. It is also done like this in https://github.com/kubernetes/cloud-provider-openstack .

These requests could also fail and another use-case for me would be checking how many requests are done to OpenStack to not overload it.

Copy link
Contributor

@seanschneeweiss seanschneeweiss left a comment

Choose a reason for hiding this comment

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

Thank you for adding all the metrics :) I would also suggest to add metrics for the get/list and delete requests.

pkg/metrics/metrics.go Outdated Show resolved Hide resolved
pkg/metrics/metrics.go Outdated Show resolved Hide resolved
pkg/metrics/metrics.go Outdated Show resolved Hide resolved
pkg/metrics/metrics.go Outdated Show resolved Hide resolved
pkg/metrics/metrics.go Show resolved Hide resolved
pkg/cloud/services/compute/instance.go Show resolved Hide resolved
pkg/cloud/services/compute/instance.go Outdated Show resolved Hide resolved
@jichenjc jichenjc changed the title Add metrics of gophercloud Add metrics of gophercloud (POST,UPDATE and DELETE) actions May 13, 2021
@jichenjc
Copy link
Contributor Author

@chrischdi @seanschneeweiss thanks for the review most comments addressed
I found the List/Get is widely used so I propose to make it next PR to handle (It might need some refactory of code to combe those Get/List into one function..)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 25, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 25, 2021
@jichenjc jichenjc force-pushed the add_metrics branch 3 times, most recently from 661a547 to 74fec38 Compare May 25, 2021 01:55
@sbueringer
Copy link
Member

sbueringer commented May 25, 2021

@jichenjc I'll take another look. Let's please merge this ASAP afterwards. With every refactoring PR we merge in the meantime we could introduce new bugs here. So it's a lot of effort to review it all over again to make sure we're safe :/

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

last round of nits

pkg/cloud/services/compute/instance.go Outdated Show resolved Hide resolved
pkg/cloud/services/loadbalancer/loadbalancer.go Outdated Show resolved Hide resolved
pkg/cloud/services/networking/securitygroups.go Outdated Show resolved Hide resolved
@@ -514,8 +520,9 @@ func (s *Service) createRule(r infrav1.SecurityGroupRule) (infrav1.SecurityGroup
SecGroupID: r.SecurityGroupID,
}
s.logger.V(6).Info("Creating rule", "Description", r.Description, "Direction", dir, "PortRangeMin", r.PortRangeMin, "PortRangeMax", r.PortRangeMax, "Proto", proto, "etherType", etherType, "RemoteGroupID", r.RemoteGroupID, "RemoteIPPrefix", r.RemoteIPPrefix, "SecurityGroupID", r.SecurityGroupID)
mc := metrics.NewMetricPrometheusContext("security_group_rules", "create")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mc := metrics.NewMetricPrometheusContext("security_group_rules", "create")
mc := metrics.NewMetricPrometheusContext("security_group_rule", "create")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

searched and no other plural anymore ..

Copy link
Member

Choose a reason for hiding this comment

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

Thx!

@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2021
@jichenjc
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 25, 2021
@sbueringer
Copy link
Member

sbueringer commented May 25, 2021

/hold

@jichenjc you have to squash locally + push -force before. Otherwise we will get 8 commits on master.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 25, 2021
@jichenjc
Copy link
Contributor Author

/hold

@jichenjc you have to squash locally + push -force before. Otherwise we will get 8 commits on master.

my bad, another mistake ... not a lucky day for me

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2021
@chrischdi
Copy link
Member

Squashed :-)

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2021
@sbueringer
Copy link
Member

@jichenjc No problem :).

/lgtm

@seanschneeweiss
Copy link
Contributor

/lgtm

Thank you.

@jichenjc
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 25, 2021
@k8s-ci-robot k8s-ci-robot merged commit cb38623 into kubernetes-sigs:master May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants