Skip to content

Enable request log flag support#8958

Merged
knative-prow-robot merged 11 commits intoknative:masterfrom
skonto:add_flag_log
Aug 10, 2020
Merged

Enable request log flag support#8958
knative-prow-robot merged 11 commits intoknative:masterfrom
skonto:add_flag_log

Conversation

@skonto
Copy link
Contributor

@skonto skonto commented Aug 7, 2020

Fixes #8644

Proposed Changes

Release Note

NONE

/assign @vagababov

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 7, 2020
@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 7, 2020
@knative-prow-robot
Copy link
Contributor

Hi @skonto. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. area/API API objects and controllers area/networking labels Aug 7, 2020
Copy link
Contributor

@julz julz left a comment

Choose a reason for hiding this comment

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

/ok-to-test

Value: observabilityConfig.RequestLogTemplate,
}, {
Name: "SERVING_ENABLE_REQUEST_LOG",
Value: strconv.FormatBool(observabilityConfig.EnableRequestLog),
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems worth adding a quick test for

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.

@@ -29,11 +30,20 @@ import (

func updateRequestLogFromConfigMap(logger *zap.SugaredLogger, h *pkghttp.RequestLogHandler) func(configMap *corev1.ConfigMap) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like it'll need updates to request_log_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it was queue_test.go, for 0.17 we want things to work as previously so unit tests shouldnt break.

Copy link
Contributor

Choose a reason for hiding this comment

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

queue_test.go failed because of the changes to queue.go. This requires changes to request_log_test.go because it changes the behaviour so should probably at least result in a new row in the table test or something :-).

Copy link
Contributor Author

@skonto skonto Aug 10, 2020

Choose a reason for hiding this comment

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

Yes I was referring to the failures.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah right, gotcha. I was just meaning "we probably need to add a test for the new logic here"

var newTemplate string // default is an empty template, disables logging
obsconfig, err := metrics.NewObservabilityConfigFromConfigMap(configMap)
if err != nil {
logger.Errorw("Failed to get observability configmap.", zap.Error(err), "configmap", configMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

probably better to do this as a guard clause at the top with a return, then the rest of the method can be out-dented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

@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 Aug 7, 2020
logger.Errorw("Failed to get observability configmap.", zap.Error(err), "configmap", configMap)
} else {
logger.Infow("Updated the request log template.", "template", newTemplate)
if obsconfig.EnableRequestLog {
Copy link
Contributor

Choose a reason for hiding this comment

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

If EnableRequestLog is false, newTemplate will always be empty. I think this is the logic we will roll out in 0.18, but not 0.17. Is my understanding correct?

Copy link
Contributor Author

@skonto skonto Aug 10, 2020

Choose a reason for hiding this comment

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

@yanweiguo right now the logic in observability config sets everything as expected for 0.17 and 0.18. However, we need this check here so we dont pass a template that is kept in the cm while the only thing that the user changed was the flag value to false. In the latter case we have a template that is not empty but flag is false now with the new cm update, if we dont check here we will accidentally enable logging.
In the general case the observability config will set the enableRequestLog flag to true when it is needed (for 0.17, 0.18) so that is the source of truth for enabling/disabling logging at the client side.

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 10, 2020
if err != nil {
logger.Errorw("Failed to get observability configmap.", zap.Error(err), "configmap", configMap)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

total nit, but nicer to have a newline after a guard clause I think

Suggested change
}
}

*ptr = val
return ptr
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there is an option impl to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is knative.dev/pkg/ptr and then ptr.Bool.

body: "test",
template: "",
want: "",
enableRequestLog: getBoolPtr(true),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@julz tests added.

body: "test",
template: "",
want: "",
enableRequestLog: ptr.Bool(true),
Copy link
Contributor

@julz julz Aug 10, 2020

Choose a reason for hiding this comment

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

could also just explicitly put the data map in the test table, i.e. add data map[string]string as a field in the table, and then you can explicitly show the keys there/not there in each test. e.g. a row might look like

{
		name: "explicitly disable request logging",
		url:  "http://example.com/testpage",
		body: "test",
		data: map[string]string{
			"logging.request-log-template": "disable_request_log",
			"logging.enable-request-log": "false",
		},
		want: "",
 }

avoids the ptr stuff and the if block/dereference below, and is maybe a bit clearer? I don't feel super strongly though if you prefer this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me check :)

func updateRequestLogFromConfigMap(logger *zap.SugaredLogger, h *pkghttp.RequestLogHandler) func(configMap *corev1.ConfigMap) {
return func(configMap *corev1.ConfigMap) {
newTemplate := configMap.Data["logging.request-log-template"]
var newTemplate string
Copy link
Contributor

Choose a reason for hiding this comment

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

again bit of a nit sorry, but could we move this down to just above if obsconfig.EnableRequestLog? that way the defaulting of that variable is in one place (and I think it's best if a guard is the first thing if possible anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem

@knative-prow-robot knative-prow-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 Aug 10, 2020
@skonto
Copy link
Contributor Author

skonto commented Aug 10, 2020

@julz its now updated.

name: "empty template",
url: "http://example.com/testpage",
body: "test",
data: map[string]string{"logging.request-log-template": ""},
Copy link
Contributor

@julz julz Aug 10, 2020

Choose a reason for hiding this comment

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

nice, let's touch up the formatting though since the lines get pretty long otherwise (same for all the rows in the table):

Suggested change
data: map[string]string{"logging.request-log-template": ""},
data: map[string]string{
"logging.request-log-template": "",
},

Copy link
Contributor Author

@skonto skonto Aug 10, 2020

Choose a reason for hiding this comment

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

@julz go fmt does this. Will the format you suggest pass the ci checks?

Copy link
Contributor

@julz julz Aug 10, 2020

Choose a reason for hiding this comment

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

it will do what I typed above if you add a newline at the right places (go fmt doesn't split long initialisers automatically, but it's definitely the right thing here and consistent with the rest of the code base, e.g. 1, 2, 3)

Copy link
Contributor

Choose a reason for hiding this comment

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

just run go fmt after adding some newlines as above and it'll do the right thing :)

Copy link
Contributor Author

@skonto skonto Aug 10, 2020

Choose a reason for hiding this comment

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

correct I have already done it for some of them. Let me update it.


func pushRequestLogHandler(currentHandler http.Handler, env config) http.Handler {
if env.ServingRequestLogTemplate == "" {
if !env.ServingEnableRequestLog {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to handle the case where ServiceEnableRequestLog is true but ServingRequestLogTemplate is ""? (e.g. maybe this would happen with default settings in 0.17 and we'd still want to avoid bothering with the request log handler, even though it'll eventually be a no-op?)

Copy link
Contributor Author

@skonto skonto Aug 10, 2020

Choose a reason for hiding this comment

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

@julz in config_overvability.go:

	if raw, ok := configMap.Data["logging.enable-request-log"]; ok {
		if strings.EqualFold(raw, "true") && oc.RequestLogTemplate != "" {
			oc.EnableRequestLog = true
		}
	} 

Afaik what you describe cannot happen. We only set it to true internally in 0.17 if the template is not empty.
So even if the configmap has a value of true we push down (activator, QP) a false value.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok cool, sounds good to me then

@skonto
Copy link
Contributor Author

skonto commented Aug 10, 2020

I am wondering why TestRunLatestService fails the first time. Rebasing to master just in case (although its flaky).

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/activator/request_log.go 100.0% 95.0% -5.0

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-integration-tests 2020-08-10 14:02:20.149 +0000 UTC 1/3

Automatically retrying due to test flakiness...
/test pull-knative-serving-integration-tests

@skonto
Copy link
Contributor Author

skonto commented Aug 10, 2020

@markusthoemmes @julz @yanweiguo I believe this is mergeable now.

Copy link
Contributor

@julz julz 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 10, 2020
@vagababov
Copy link
Contributor

/lgtm
/approve

@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 10, 2020
Copy link
Contributor

@yanweiguo yanweiguo 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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, skonto, vagababov, yanweiguo

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 merged commit b901d34 into knative:master Aug 10, 2020
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/API API objects and controllers area/networking 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/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.

Add a new toggle to config observability to trigger log collection.

9 participants