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

[e2e] Check labels documentation #1082

Merged
merged 3 commits into from
Mar 9, 2020

Conversation

olivierlemasle
Copy link
Member

What this PR does / why we need it:
This PR adds a new e2e test, checking that all metrics and labels found in /metrics endpoint are correctly documented (currently, metrics documentation is already checked with make doccheck, but labels are not validated).

When part of the label name is documented in uppercase (e.g. label_DAEMONSET_LABEL), we will consider that by convention, it means that the uppercase part is dynamic (checked as a wildcard).

NB: we also remove test manifest for Lease; as explained in the commit message, this was not necessary and caused an (ignored) error at the end of e2e tests.

Which issue(s) this PR fixes:
Fixes #1078

The coordination.k8s.io/Lease used in e2e tests had an ownerReference,
referencing non-existing node "kube-master" (non-existing in default
Minikube deployments), so the lease was never created, and there was
an (ignored) error during deletion.

But, as a lease is automatically created for each node, there will always
be leases in e2e, so there's no need to add one.
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 26, 2020
@olivierlemasle
Copy link
Member Author

olivierlemasle commented Feb 26, 2020

CI failures are actually good news:

=== RUN   TestDocumentation
---- FAIL: TestDocumentation (0.08s)
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_spec_min_replicas are: hpa, namespace
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_spec_max_replicas are: hpa, namespace
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_status_current_replicas are: hpa, namespace
-    main_test.go:112: Metric kube_validatingwebhookconfiguration_created not found in documentation.
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_allocatable are: node, resource
-    main_test.go:112: Metric kube_pod_start_time not found in documentation.
-    main_test.go:112: Metric kube_mutatingwebhookconfiguration_created not found in documentation.
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_status_condition are: hpa, namespace, condition, status
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_status_condition are: hpa, namespace, condition, status
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_status_condition are: hpa, namespace, condition, status
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label unit not found in documentation. Documented labels for metric kube_node_status_capacity are: node, resource
-    main_test.go:131: Label label_app_kubernetes_io_name not found in documentation. Documented labels for metric kube_replicaset_labels are: replicaset, namespace
-    main_test.go:131: Label label_app_kubernetes_io_version not found in documentation. Documented labels for metric kube_replicaset_labels are: replicaset, namespace
-    main_test.go:131: Label label_pod_template_hash not found in documentation. Documented labels for metric kube_replicaset_labels are: replicaset, namespace
-    main_test.go:131: Label label_k8s_app not found in documentation. Documented labels for metric kube_replicaset_labels are: replicaset, namespace
-    main_test.go:131: Label label_pod_template_hash not found in documentation. Documented labels for metric kube_replicaset_labels are: replicaset, namespace
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_metadata_generation are: hpa, namespace
-    main_test.go:112: Metric kube_mutatingwebhookconfiguration_info not found in documentation.
-    main_test.go:112: Metric kube_validatingwebhookconfiguration_info not found in documentation.
-    main_test.go:131: Label label_k8s_app not found in documentation. Documented labels for metric kube_deployment_labels are: deployment, namespace
-    main_test.go:131: Label label_app_kubernetes_io_name not found in documentation. Documented labels for metric kube_deployment_labels are: deployment, namespace
-    main_test.go:131: Label label_app_kubernetes_io_version not found in documentation. Documented labels for metric kube_deployment_labels are: deployment, namespace
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label phase not found in documentation. Documented labels for metric kube_namespace_status_phase are: namespace, status
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_spec_target_metric are: hpa, namespace, metric_name, metric_target_type
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_status_desired_replicas are: hpa, namespace
-    main_test.go:112: Metric kube_validatingwebhookconfiguration_metadata_resource_version not found in documentation.
-    main_test.go:112: Metric kube_mutatingwebhookconfiguration_metadata_resource_version not found in documentation.
-    main_test.go:112: Metric kube_node_spec_unschedulable not found in documentation.
-    main_test.go:131: Label horizontalpodautoscaler not found in documentation. Documented labels for metric kube_horizontalpodautoscaler_labels are: hpa, namespace
-FAIL
-FAIL	k8s.io/kube-state-metrics/tests/e2e	0.121s
-FAIL

It shows the following errors, that I will fix in a new commit:

  • Metrics kube_pod_start_time and kube_node_spec_unschedulable do not have a stability stage (STABLE, EXPERIMENTAL, etc.)
  • For metrics kube_node_status_capacity and kube_node_status_allocatable, in the definition of label unit, characters ` and = have been exchanged.
  • Metric kube_namespace_status_phase has a label phase, whereas it is documented as status.
  • Metrics kube_deployment_labels and kube_replicaset_labels miss dynamic label label_*
  • Metrics kube_horizontalpodautoscaler_* have a label horizontalpodautoscaler, whereas the old label hpa is still documented.
  • Documentation files for mutatingwebhookconfiguration and validatingwebhookconfiguration do not end by -metrics.md like other metric documentation files.

/hold

@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 Feb 26, 2020
@olivierlemasle
Copy link
Member Author

/assign @tariq1890

@olivierlemasle
Copy link
Member Author

Added commit with documentation fixes; it resolves e2e test failures.
/unhold

@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 Feb 27, 2020
@tariq1890
Copy link
Contributor

This is so awesome. Thanks @olivierlemasle :)!

func getLabelsDocumentation() (map[string][]string, error) {
documentedMetrics := map[string][]string{}

docPath := "../../docs/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any go libraries from stdlib to get the directory the project root?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... I suppose we could use https://stackoverflow.com/a/38644571/625158, that uses runtime.Caller, but is it better?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can go with that :). From the looks of it, I don't see any problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just tested adding:

_, b, _, _ = runtime.Caller(0)

Using make e2e (from the root path of the project), b is actually the absolute path of ./tests/e2e/main_test.go. So I cannot get the documentation path with this method, without using ../../docs/.

@olivierlemasle
Copy link
Member Author

@tariq1890 PTAL thanks!

@tariq1890
Copy link
Contributor

/lgtm

Thanks again @olivierlemasle :)

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: olivierlemasle, tariq1890

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 Mar 9, 2020
@k8s-ci-robot k8s-ci-robot merged commit 9230c40 into kubernetes:master Mar 9, 2020
@olivierlemasle olivierlemasle deleted the fix-1078 branch March 9, 2020 23:40
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.

e2e: check labels documentation
3 participants