Skip to content

remove prometheus dependencies from k/k #89285

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

Merged
merged 1 commit into from
Apr 25, 2020
Merged

remove prometheus dependencies from k/k #89285

merged 1 commit into from
Apr 25, 2020

Conversation

tanjunchen
Copy link
Contributor

@tanjunchen tanjunchen commented Mar 20, 2020

What type of PR is this?

/kind cleanup
/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Ref kubernetes/enhancements#1238
ref #89267
Special notes for your reviewer:

/cc @RainbowMango
/cc @serathius

Could you help me review it if you are free. Thanks

Does this PR introduce a user-facing change?:

None

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

None

@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Mar 20, 2020
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 20, 2020
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.
Can you try to refactor original tests?

}

// ExpectFindMetric find a metric with the given name nad labels or reports a fatal test error.
func ExpectFindMetric(t *testing.T, name string, expectedLabels map[string]string) *dto.Metric {
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid we can't just simply move LabelsMatch and ExpectFindMetric to components.

There are a few methods you can select in testutil package, such as CollectAndCompare and GatherAndCompare, etc.
That means you need to refactor the original test case with the methods in testutil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure , thanks your comment , i will udpate it

@fedebongio
Copy link
Contributor

/cc @logicalhan

@k8s-ci-robot k8s-ci-robot requested a review from logicalhan March 24, 2020 20:09
Copy link
Member

@logicalhan logicalhan left a comment

Choose a reason for hiding this comment

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

Can you run hack/update-vendor.sh, it looks like the dependencies are out of date now.

Also, it looks like golint is failing.

@tanjunchen
Copy link
Contributor Author

Can you run hack/update-vendor.sh, it looks like the dependencies are out of date now.

Also, it looks like golint is failing.

Sure , Thanks for your review.

@tanjunchen
Copy link
Contributor Author

/retest
/cc @logicalhan

@k8s-ci-robot k8s-ci-robot requested a review from logicalhan March 27, 2020 15:18
@tanjunchen
Copy link
Contributor Author

/test pull-kubernetes-dependencies
/test pull-kubernetes-e2e-gce

@tanjunchen
Copy link
Contributor Author

/cc @RainbowMango

@k8s-ci-robot k8s-ci-robot added the area/dependency Issues or PRs related to dependency changes label Apr 3, 2020
@tanjunchen
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind-ipv6

1 similar comment
@tanjunchen
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind-ipv6

Comment on lines 364 to 384
// LabelsMatch returns true if metric has all expected labels otherwise false
func LabelsMatch(metric *dto.Metric, labelFilter map[string]string) bool {
for _, lp := range metric.GetLabel() {
if value, ok := labelFilter[lp.GetName()]; ok && lp.GetValue() != value {
return false
}
}
return true
}
Copy link
Member

Choose a reason for hiding this comment

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

The docstring looks like it's not true. Let's say we have a labelFilter that this:

map[string]string{
    "a": "expectedVal1",
    "b": "expectedVal2",
}

If the metric only has a single label, let's say 'a', then this function returns true, which seems not in line with the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oo , sure .
Thanks . I will update it .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @logicalhan
/cc @RainbowMango
could you review it again?Thanks

gotLabelCount := len(metric.GetLabel())
wantLabelCount := len(expectedLabels)
if wantLabelCount != gotLabelCount {
t.Errorf("Got metric with %d labels, but wanted %d labels. Wanted %#+v for %s",
gotLabelCount, wantLabelCount, expectedLabels, metric.String())
}
return metric
Copy link
Member

Choose a reason for hiding this comment

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

This line is important. You need to return here otherwise this function will never successfully find a match.

This is why the blaze unit test is failing. You can run these tests locally (bazel test //staging/src/k8s.io/apiserver/pkg/admission/metrics:go_default_test) to debug what is happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right.
thanks

@tanjunchen
Copy link
Contributor Author

/retest

1 similar comment
@tanjunchen
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 22, 2020
Comment on lines +331 to +333
"a": "1",
"b": "2",
"c": "3",
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind adding two edge cases?

(1) empty LabelPair and a non-empty map
(2) non-empty LabelPair but an empty map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @logicalhan
is it ok now?

labelFilter map[string]string
expectedMatch bool
}{
{"metric's labels and labelFilter have the same labels and values", &dto.Metric{
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for reply late.
Would you mind replace metric's with metric? That'll be ugly if subtest's name contains a specific symbol.

Same as below.

And, why not set fields name here? like,

{
    name: "...",
    metric: ...
    ....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok . I have replace metric's with metric.
And for fields, I have updated it though i think both are ok.
Thanks for your reply.

@k8s-ci-robot k8s-ci-robot requested a review from logicalhan April 24, 2020 02:05
Copy link
Member

@logicalhan logicalhan left a comment

Choose a reason for hiding this comment

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

Looks great!

/lgtm
/approve
Thanks for your patience through the iterations!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2020
@tanjunchen
Copy link
Contributor Author

kindly
/cc @lavalamp
for staging/src/k8s.io/apiserver/

@k8s-ci-robot k8s-ci-robot requested a review from lavalamp April 24, 2020 03:29
for labelName, labelValue := range labelFilter {
labelFound := false
for _, labelPair := range metric.Label {
if labelName == *labelPair.Name && labelValue == *labelPair.Value {
Copy link
Member

Choose a reason for hiding this comment

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

labelPair.GetName() returns the literal string and likewise for labelPair.GetValue()

Comment on lines 368 to 373
for _, labelPair := range metric.Label {
if labelName == *labelPair.Name && labelValue == *labelPair.Value {
labelFound = true
break
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can bring the nested for-loop to the outer scope to avoid the repeated work (practically the number of labels are going to be bounded in tests and hopefully in our metrics).

metricLabels := map[string]string{}
for _, labelPair := range metric.Label {
	metricLabels[labelPair.GetName()] = labelPair.GetValue()
}
// length comparison then match key to values in the maps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @logicalhan
updated

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2020
@tanjunchen
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot requested a review from logicalhan April 24, 2020 08:09
Copy link
Member

@logicalhan logicalhan left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2020
@liggitt
Copy link
Member

liggitt commented Apr 24, 2020

/approve
for dependency cleanup

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, logicalhan, tanjunchen

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 24, 2020
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 41201e7 into kubernetes:master Apr 25, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Apr 25, 2020
@tanjunchen tanjunchen deleted the remove-prometheus-staging/src/k8s.io/apiserver/pkg/admission/metrics branch April 25, 2020 07:27
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. area/apiserver area/cloudprovider area/dependency Issues or PRs related to dependency changes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. 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.

7 participants