-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add traceid to decision logs #462
Changes from all commits
fb653da
1338d33
50850b5
b8df96d
a7d8ace
9772e66
e20f317
6d0fa17
48a8895
b1ab8b3
65f30a7
a0badb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,10 +8,30 @@ import ( | |||||||||||||||||||
"github.com/open-policy-agent/opa-envoy-plugin/internal" | ||||||||||||||||||||
"github.com/open-policy-agent/opa-envoy-plugin/plugin" | ||||||||||||||||||||
"github.com/open-policy-agent/opa/plugins" | ||||||||||||||||||||
"github.com/open-policy-agent/opa/plugins/logs" | ||||||||||||||||||||
"github.com/open-policy-agent/opa/storage" | ||||||||||||||||||||
"github.com/open-policy-agent/opa/storage/inmem" | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
type testPlugin struct { | ||||||||||||||||||||
events []logs.EventV1 | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (*testPlugin) Start(context.Context) error { | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (*testPlugin) Stop(context.Context) { | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (*testPlugin) Reconfigure(context.Context, interface{}) { | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (p *testPlugin) Log(_ context.Context, event logs.EventV1) error { | ||||||||||||||||||||
p.events = append(p.events, event) | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// TestAuthzServerWithWithOpts creates a new AuthzServer | ||||||||||||||||||||
// that implements the Envoy ext_authz API. Options for | ||||||||||||||||||||
// plugins.Manager can/should be customized for the test case. | ||||||||||||||||||||
|
@@ -37,6 +57,18 @@ func TestAuthzServerWithWithOpts(module string, path string, addr string, opts . | |||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
m.Register(plugin.PluginName, internal.New(m, cfg)) | ||||||||||||||||||||
|
||||||||||||||||||||
m.Register("test_plugin", &testPlugin{}) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please help me understand why we're registering this and how we're using it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to enable decision_logs . Looking at opa-envoy-plugin/envoyauth/evaluation_test.go Lines 212 to 220 in 064d640
Please suggest if there is any better way. |
||||||||||||||||||||
config, err := logs.ParseConfig([]byte(`{"plugin": "test_plugin"}`), nil, []string{"test_plugin"}) | ||||||||||||||||||||
|
||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
config.ConsoleLogs = true | ||||||||||||||||||||
|
||||||||||||||||||||
logPlugin := logs.New(config, m) | ||||||||||||||||||||
m.Register(logs.Name, logPlugin) | ||||||||||||||||||||
|
||||||||||||||||||||
if err := m.Start(ctx); err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you intend to use the console logger somewhere in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashutosh-narkar , yes.
I'm using it to capture the log entries, identify a decision log in them, and then assert for the presence of trace_id and span_id in the decision log.
see line 155 to 159