-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[encoding/googlecloudlogentry] Add support for request attributes and destination attributes in cloud audit logs #42160
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
Changes from all commits
4cf9e66
f70133d
12513f5
74f7493
f5be4f8
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: googlecloudlogentry_encoding | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Add support for request attributes and destination attributes in cloud audit logs | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [42160] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | ||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,6 +239,7 @@ func TestHandleRequestMetadata(t *testing.T) { | |
| tests := map[string]struct { | ||
| metadata *requestMetadata | ||
| expectedAttr map[string]any | ||
| expectsErr string | ||
| }{ | ||
| "nil": { | ||
| metadata: nil, | ||
|
|
@@ -256,13 +257,102 @@ func TestHandleRequestMetadata(t *testing.T) { | |
| gcpAuditRequestCallerNetwork: "//compute.googleapis.com/projects/elastic-apps-163815/global/networks/__unknown__", | ||
| }, | ||
| }, | ||
| "request attributes": { | ||
|
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. perhaps add a test with invalid payload to document the parsing failure? 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. Thanks @andrzej-stencel , I have added the test cases for the errors both in request attributes & destination attributes |
||
| metadata: &requestMetadata{ | ||
| RequestAttributes: &requestAttributes{ | ||
| ID: "req-12345", | ||
| Method: "GET", | ||
| Headers: map[string]string{ | ||
| "User-Agent": "test-client/1.0", | ||
| "Accept": "application/json", | ||
| }, | ||
| Path: "/test/path", | ||
| Host: "example.com", | ||
| Scheme: "https", | ||
| Query: "foo=bar&baz=qux", | ||
| Time: "2025-08-21T12:34:56Z", | ||
| Size: "1234", | ||
| Protocol: "HTTP/1.1", | ||
| Reason: "test-reason", | ||
| Auth: auth{ | ||
| Principal: "[email protected]", | ||
| Audiences: []string{"test-service", "another-service"}, | ||
| Presenter: "test-presenter", | ||
| AccessLevels: []string{"level1", "level2"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedAttr: map[string]any{ | ||
| string(semconv.HTTPRequestSizeKey): int64(1234), | ||
| string(semconv.HTTPRequestMethodKey): "GET", | ||
| string(semconv.URLQueryKey): "foo=bar&baz=qux", | ||
| string(semconv.URLPathKey): "/test/path", | ||
| string(semconv.URLSchemeKey): "https", | ||
| gcpAuditRequestTime: "2025-08-21T12:34:56Z", | ||
| "http.request.header.host": "example.com", | ||
| "http.request.header.user-agent": "test-client/1.0", | ||
| "http.request.header.accept": "application/json", | ||
| string(semconv.NetworkProtocolNameKey): "http/1.1", | ||
| gcpAuditRequestReason: "test-reason", | ||
| httpRequestID: "req-12345", | ||
| gcpAuditRequestAuthPrincipal: "[email protected]", | ||
| gcpAuditRequestAuthPresenter: "test-presenter", | ||
| gcpAuditRequestAuthAccessLevels: []any{"level1", "level2"}, | ||
| gcpAuditRequestAuthAudiences: []any{"test-service", "another-service"}, | ||
| }, | ||
| }, | ||
| "request attributes - invalid request size format": { | ||
| metadata: &requestMetadata{ | ||
| RequestAttributes: &requestAttributes{ | ||
| Size: "invalid", | ||
| }, | ||
| }, | ||
| expectsErr: "failed to add http request size", | ||
| }, | ||
| "destination attributes": { | ||
| metadata: &requestMetadata{ | ||
| DestinationAttributes: &destinationAttributes{ | ||
| IP: "10.0.0.1", | ||
| Port: "8080", | ||
| Principal: "serviceAccount:[email protected]", | ||
| RegionCode: "us-central1", | ||
| Labels: map[string]string{ | ||
| "env": "staging", | ||
| "team.owner": "devops", | ||
| }, | ||
| }, | ||
| }, | ||
| expectedAttr: map[string]any{ | ||
| string(semconv.ServerPortKey): int64(8080), | ||
| string(semconv.ServerAddressKey): "10.0.0.1", | ||
| gcpAuditDestinationPrincipal: "serviceAccount:[email protected]", | ||
| gcpAuditDestinationRegionCode: "us-central1", | ||
| gcpAuditDestinationLabels: map[string]any{ | ||
| "env": "staging", | ||
| "team.owner": "devops", | ||
| }, | ||
| }, | ||
| }, | ||
| "destination attributes - invalid port format": { | ||
| metadata: &requestMetadata{ | ||
| DestinationAttributes: &destinationAttributes{ | ||
| Port: "invalid", | ||
| }, | ||
| }, | ||
| expectsErr: "failed to add destination port", | ||
| }, | ||
| } | ||
|
|
||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
| attr := pcommon.NewMap() | ||
| handleRequestMetadata(tt.metadata, attr) | ||
| err := handleRequestMetadata(tt.metadata, attr) | ||
| if tt.expectsErr != "" { | ||
| require.ErrorContains(t, err, tt.expectsErr) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.expectedAttr, attr.AsRaw()) | ||
| }) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.