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

Use view.Count() instead of view.Sum() for request count stats #5191

Merged
merged 3 commits into from
Aug 22, 2019

Conversation

anniefu
Copy link
Contributor

@anniefu anniefu commented Aug 17, 2019

Proposed Changes

  • For stats/metrics that represent integer counter values, use opencensus.io view.Count() instead of view.Sum()
  • Because recording an opencensus CountData always converts to a Measurement of 1, remove ability to pass int value into "ReportRequestCount" StatsReporter APIs for pkg/activator and pkg/queue

The CountData is intended for integers and is the appropriate type. This also ensures that Knative request_count metrics are exported to Prometheus as Prometheus "counter" metrics instead of "untyped" (see opencensus-go Supported metric primitives and opencensus-go-exporter-prometheus/prometheus.go).

Example of incorrect prometheus type when using opencensus view.Sum() (from /metrics endpoint)

# HELP activator_request_count The number of requests that are routed to Activator
# TYPE activator_request_count untyped
activator_request_count{configuration_name="helloworld-go",namespace_name="default",num_tries="2",response_code="200",response_code_class="2xx",revision_name="helloworld-go-ls5dq",service_name="helloworld-go"} 1

Example of correct prometheus type when using opencensus view.Count()

# HELP autoscaler_reconcile_count Number of reconcile operations
# TYPE autoscaler_reconcile_count counter
autoscaler_reconcile_count{key="default/helloworld-go",reconciler="KPA-Class Autoscaling",success="true"} 1

Note: This is not an issue for Knative 0.8.0+, because the opencensus-go package has been updated and view.Sum() now converts to Prometheus "counter" type, likely as a side effect of this opencensus-go change.

For future reference when using view.Sum(), there are open issues about the opencensus to prometheus counter type conversion being inconsistent across implementations (see opencensus-spec Exported type/kind conversion for different aggregates and opencensus-csharp Counter type conversion inconsistency in Prometheus exporter).

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 17, 2019
@knative-prow-robot knative-prow-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 17, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@anniefu: 0 warnings.

In response to this:

Proposed Changes

  • For stats/metrics that represent integer counter values, use opencensus.io view.Count() instead of view.Sum()

The CountData is intended for integers and is the appropriate type. This also ensures that Knative request_count metrics are exported to Prometheus as Prometheus "counter" metrics instead of "untyped" (see opencensus-go Supported metric primitives and opencensus-go-exporter-prometheus/prometheus.go).

Example of incorrect prometheus type when using opencensus view.Sum() (from /metrics endpoint)

# HELP activator_request_count The number of requests that are routed to Activator
# TYPE activator_request_count untyped
activator_request_count{configuration_name="helloworld-go",namespace_name="default",num_tries="2",response_code="200",response_code_class="2xx",revision_name="helloworld-go-ls5dq",service_name="helloworld-go"} 1

Example of correct prometheus type when using opencensus view.Count()

# HELP autoscaler_reconcile_count Number of reconcile operations
# TYPE autoscaler_reconcile_count counter
autoscaler_reconcile_count{key="default/helloworld-go",reconciler="KPA-Class Autoscaling",success="true"} 1

Note: This is not an issue for Knative 0.8.0+, because the opencensus-go package has been updated and view.Sum() now converts to Prometheus "counter" type, likely as a side effect of this opencensus-go change.

For future reference when using view.Sum(), there are open issues about the opencensus to prometheus counter type conversion being inconsistent across implementations (see opencensus-spec Exported type/kind conversion for different aggregates and opencensus-csharp Counter type conversion inconsistency in Prometheus exporter).

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.

@anniefu
Copy link
Contributor Author

anniefu commented Aug 17, 2019

/assign @mdemirhan
/assign @yanweiguo
/assign @ssmall
/assign @trshafer

@yanweiguo
Copy link
Contributor

unit tests need update

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 19, 2019
@anniefu
Copy link
Contributor Author

anniefu commented Aug 19, 2019

unit tests need update

For view.Count()/CountData, passing in a non-1 value at record time is equivalent to passing in a 1, so I removed the value parameter from the ReportRequestCount functions. I edited the PR description to reflect this.

Copy link
Contributor

@ssmall ssmall left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 19, 2019
@yanweiguo
Copy link
Contributor

/lgtm

@anniefu anniefu changed the title Use view.Count() instead of view.Sum() for integer stats Use view.Count() instead of view.Sum() for request count stats Aug 19, 2019
@mdemirhan mdemirhan added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Aug 20, 2019
@mdemirhan
Copy link
Contributor

/lgtm
/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anniefu, mdemirhan

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2019
@knative-prow-robot knative-prow-robot merged commit f79b0c6 into knative:master Aug 22, 2019
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/networking cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. 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.

7 participants