Skip to content

Adding data plane metrics to ApiServerSource#1786

Merged
knative-prow-robot merged 34 commits into
knative:masterfrom
sayanh:add-http-response-codes-in-metrics
Sep 9, 2019
Merged

Adding data plane metrics to ApiServerSource#1786
knative-prow-robot merged 34 commits into
knative:masterfrom
sayanh:add-http-response-codes-in-metrics

Conversation

@sayanh
Copy link
Copy Markdown
Contributor

@sayanh sayanh commented Sep 2, 2019

Helps #1693

Proposed Changes

  • Enabled metrics for apiserversource
  • Tagging metrics with the responseCode and the responseCodeClass

Release Note

 ApiServerSource now reports event counts

@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 2, 2019
@knative-prow-robot
Copy link
Copy Markdown
Contributor

Hi @sayanh. Thanks for your PR.

I'm waiting for a knative 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.

Details

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.

@knative-prow-robot knative-prow-robot added the area/test-and-release Test infrastructure, tests or release label Sep 2, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 2, 2019
@nachocano
Copy link
Copy Markdown
Contributor

/hold
until we merge this #1784

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 3, 2019
@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented Sep 3, 2019

/ok-to-test

@knative-prow-robot knative-prow-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 Sep 3, 2019
@sayanh sayanh force-pushed the add-http-response-codes-in-metrics branch from df4492a to 0eca934 Compare September 3, 2019 18:07
@nachocano
Copy link
Copy Markdown
Contributor

can you update the title of the PR to better match what is it about. Adding data plane metrics to ApiServerSource, maybe?

Comment thread cmd/apiserver_receive_adapter/main.go Outdated
Comment thread cmd/apiserver_receive_adapter/main.go Outdated
Comment thread cmd/apiserver_receive_adapter/main.go
Comment thread cmd/apiserver_receive_adapter/main.go Outdated
Comment thread cmd/apiserver_receive_adapter/main.go Outdated
Comment thread cmd/apiserver_receive_adapter/main.go Outdated
Comment thread pkg/adapter/apiserver/adapter.go Outdated
Comment thread pkg/adapter/apiserver/adapter_test.go Outdated
Comment thread pkg/adapter/apiserver/events/events.go Outdated
Comment thread pkg/adapter/apiserver/events/events.go Outdated
Comment thread pkg/adapter/apiserver/ref.go Outdated
Comment thread pkg/adapter/apiserver/resource.go Outdated
Comment thread pkg/adapter/apiserver/resource.go Outdated
Comment thread pkg/adapter/apiserver/resource.go Outdated
Comment thread pkg/adapter/apiserver/resource.go Outdated
@sayanh sayanh force-pushed the add-http-response-codes-in-metrics branch from 3b3344c to f73ddce Compare September 5, 2019 08:47
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 5, 2019
@nachocano
Copy link
Copy Markdown
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 5, 2019
// metrics.ExporterOptions. This is used to configure the metrics exporter
// options, the config is stored in a config map inside the controllers
// namespace and copied here.
MetricsConfigBase64 string `envconfig:"K_METRICS_CONFIG" required:"true"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably a foolish question, but why are we base64 encoding these? Flags tend to make sense, as it can be very annoying to get the escaping just right, but these are environment variables, where we don't have that problem.

Copy link
Copy Markdown
Contributor Author

@sayanh sayanh Sep 6, 2019

Choose a reason for hiding this comment

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

My rationale was to be consistent with knative-gcp in here. @n3wscott What's your
take on this?

Comment thread cmd/apiserver_receive_adapter/main.go Outdated
panic(err)
}
}
logger, _ := logging.NewLoggerFromConfig(loggingConfig, component)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this ignoring a possible error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is ignoring a zap.AtomicLevel

Comment thread cmd/apiserver_receive_adapter/main.go Outdated
panic(err)
}
}
logger, _ := logging.NewLoggerFromConfig(loggingConfig, component)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Desugar the logger. As-is, there is a mistake on line 140. By desugaring, we can use the type system to ensure we don't have any problems.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed logger to be desugared

rctx, _, err := a.ce.Send(ctx, *event)
rtctx := cloudevents.HTTPTransportContextFrom(rctx)
a.reporter.ReportEventCount(reportArgs, rtctx.StatusCode)
return err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is a non-nil err logged in the caller?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added logs for non-nil error in here

Comment thread pkg/adapter/apiserver/adapter_test.go Outdated
}

func makeRefAndTestingClient() (*ref, *kncetesting.TestCloudEventsClient) {
func makeRefAndTestingClient(t *testing.T) (*ref, *kncetesting.TestCloudEventsClient) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is t being passed in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

t is not needed. I removed it.


source string
sinkReconciler *duck.SinkReconciler
context context.Context
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think I've ever seen context saved this way. Can we rename this loggingContext or something similar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, renamed to loggingContext

Comment thread pkg/utils/config.go Outdated
quoted64 := strconv.Quote(string(base64))

var bytes []byte
// Do not care about the unmarshal error.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment, if the error is non-nil, we return it. So I think we care about the error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are indeed caring about the error. I removed those comments.

Comment thread pkg/utils/config.go Outdated
return nil, err
}

// Do not care about the unmarshal error.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment removed

Comment thread pkg/utils/config.go Outdated
if err != nil {
return fmt.Sprintf(`{"error":"%s}`, err.Error())
}
// Turn the base64 encoded []byte back into a string.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like this belongs a few lines above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed it

Comment thread pkg/utils/config.go Outdated

jsonOpts, err := json.Marshal(opts)
if err != nil {
return fmt.Sprintf(`{"error":"%s}`, err.Error())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do this, rather than having the function return (string, error)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, hence fixed

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2019
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/adapter/apiserver/ref.go 83.3% 95.0% 11.7
pkg/adapter/apiserver/resource.go 80.6% 96.7% 16.0
pkg/adapter/apiserver/stats_reporter.go Do not exist 76.9%
pkg/reconciler/apiserversource/apiserversource.go 77.5% 77.5% 0.0
pkg/utils/config.go Do not exist 72.9%

Copy link
Copy Markdown
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

type mockReporter struct{}

func (r *mockReporter) ReportEventCount(args *ReportArgs, responseCode int) error {
return nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would still prefer if we asserted the metrics were incremented in the test, but I won't hold up this PR for it.

metricsConfig, err := utils.Base64ToMetricsOptions(
env.MetricsConfigBase64)
if err != nil {
logger.Error("failed to process metrics options ", zap.Error(err))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.Error("failed to process metrics options ", zap.Error(err))
logger.Error("failed to process metrics options", zap.Error(err))

Don't need the extra space when using the desugared logger. Not here or the other lines.

Once, again, I'll let it submit as-is, please send a follow up PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do, thanks @Harwayne!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Harwayne, sayanh

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

The pull request process is described here

Details 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 Sep 9, 2019
@knative-prow-robot knative-prow-robot merged commit 470dfb7 into knative:master Sep 9, 2019
pierDipi pushed a commit to pierDipi/eventing that referenced this pull request Jul 11, 2022
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/test-and-release Test infrastructure, tests or release cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants