-
Notifications
You must be signed in to change notification settings - Fork 77
[transformation_test] Add possibility to test a receiver and verify transformations defined within.
#1968
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
[transformation_test] Add possibility to test a receiver and verify transformations defined within.
#1968
Conversation
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.
Can we turn this into a constant? Not sure if its possible in go
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.
Now the transformationTest.Receiver is a pointer type, so we can just check for transformationTest.Receiver == nil instead of checking for an empty struct. Done!
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.
Can we serialize this into a yaml file, that can be declared optionally in each test?
Something like, resource.yaml
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.
I have considered serializing in a resource.yaml format, but since the use case is limited to choosing linux or windows platforms, i don't think it's worth it to implement here :
Some details on this :
- The purpose of mocking a platform here is to unmarshall the config correctly since "Windows" receiver types are not supported in "Linux". There is no other direct usage of this platform.
- The intention is to the "processors" (transformations) set within a "receiver" which are always platform agnostic.
- Setting this
platformconstants is merely a mirror of howconfgenerator_test.gosets constants for platforms which doesn't use an artifact like aresource.yamlfile.
ops-agent/confgenerator/confgenerator_test.go
Lines 54 to 147 in 951f3dc
| var winlogv1channels = []string{ | |
| "Application", | |
| "Security", | |
| "Setup", | |
| "System", | |
| } | |
| var ( | |
| // Set up the test environment with mocked data. | |
| testResource = resourcedetector.GCEResource{ | |
| Project: "test-project", | |
| Zone: "test-zone", | |
| Network: "test-network", | |
| Subnetwork: "test-subnetwork", | |
| PublicIP: "test-public-ip", | |
| PrivateIP: "test-private-ip", | |
| InstanceID: "test-instance-id", | |
| InstanceName: "test-instance-name", | |
| Tags: "test-tag", | |
| MachineType: "test-machine-type", | |
| Metadata: map[string]string{"test-key": "test-value", "test-escape": "$foo", "test-escape-parentheses": "${foo:bar}"}, | |
| Label: map[string]string{"test-label-key": "test-label-value"}, | |
| InterfaceIPv4: map[string]string{"test-interface": "test-interface-ipv4"}, | |
| ManagedInstanceGroup: gcp.ManagedInstanceGroup{ | |
| Name: "test-mig", | |
| Type: gcp.Zone, | |
| Location: "test-zone", | |
| }, | |
| } | |
| linuxTestPlatform = platformConfig{ | |
| name: "linux", | |
| defaultLogsDir: "/var/log/google-cloud-ops-agent", | |
| defaultStateDir: "/var/lib/google-cloud-ops-agent/fluent-bit", | |
| platform: platform.Platform{ | |
| Type: platform.Linux, | |
| HostInfo: &host.InfoStat{ | |
| OS: "linux", | |
| Platform: "linux_platform", | |
| PlatformVersion: "linux_platform_version", | |
| }, | |
| TestGCEResourceOverride: testResource, | |
| }, | |
| } | |
| testPlatforms = []platformConfig{ | |
| linuxTestPlatform, | |
| { | |
| name: "linux-gpu", | |
| defaultLogsDir: "/var/log/google-cloud-ops-agent", | |
| defaultStateDir: "/var/lib/google-cloud-ops-agent/fluent-bit", | |
| platform: platform.Platform{ | |
| Type: platform.Linux, | |
| HostInfo: &host.InfoStat{ | |
| OS: "linux", | |
| Platform: "linux_platform", | |
| PlatformVersion: "linux_platform_version", | |
| }, | |
| TestGCEResourceOverride: testResource, | |
| HasNvidiaGpu: true, | |
| }, | |
| }, | |
| { | |
| name: "windows", | |
| defaultLogsDir: `C:\ProgramData\Google\Cloud Operations\Ops Agent\log`, | |
| defaultStateDir: `C:\ProgramData\Google\Cloud Operations\Ops Agent\run`, | |
| platform: platform.Platform{ | |
| Type: platform.Windows, | |
| WindowsBuildNumber: "1", // Is2012 == false, Is2016 == false | |
| WinlogV1Channels: winlogv1channels, | |
| HostInfo: &host.InfoStat{ | |
| OS: "windows", | |
| Platform: "win_platform", | |
| PlatformVersion: "win_platform_version", | |
| }, | |
| TestGCEResourceOverride: testResource, | |
| }, | |
| }, | |
| { | |
| name: "windows-2012", | |
| defaultLogsDir: `C:\ProgramData\Google\Cloud Operations\Ops Agent\log`, | |
| defaultStateDir: `C:\ProgramData\Google\Cloud Operations\Ops Agent\run`, | |
| platform: platform.Platform{ | |
| Type: platform.Windows, | |
| WindowsBuildNumber: "9200", // Windows Server 2012 | |
| WinlogV1Channels: winlogv1channels, | |
| HostInfo: &host.InfoStat{ | |
| OS: "windows", | |
| Platform: "win_platform", | |
| PlatformVersion: "win_platform_version", | |
| }, | |
| TestGCEResourceOverride: testResource, | |
| }, | |
| }, | |
| } | |
| ) |
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.
NIT: Prefer const instead of "INPUT"
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.
Added a const flbINPUT = "INPUT" for this comparison. See 006a9d3 . Done!
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.
NIT: Add comment that there always be 1 receiver, per 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.
Addressed in fd41bfa. I've also added "test" validation for this. Done!
logging receiver.receiver and verify transformations defined within.
…d/or a `receiver`.
7a90db1 to
83c9789
Compare
| return nil, fmt.Errorf("test_receiver is required.") | ||
| } | ||
| // Append logging processors from receiver "post-processing" step. | ||
| receiverComponents := transformationTest.Receiver.TestReceiver.LoggingReceiver.Components(ctx, flbTag) |
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.
Manipulating the otel/fluent-bit components after they're already constructed feels like a giant hack. Can't we achieve the same result without any hacks by refactoring the receiver-under-test into a receiver + processor that is only registered in tests, and then using that processor in a transformation 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.
Thanks for the comment! I like the idea of registering processors only for the purpose of testing. This would avoid any need to update transformation_test.go. The current change present here seems to need further discussion in the design. I'll close this PR in favour of : #1977 .
We can discuss later if adding a receiver section is still needed.
|
Closing in favour of #1977. |
Description
Currently "transformations" done as post processing of receiver (e.g.
windows_event_log, 3P app receivers) can't be tested directly intransformation tests, since it only accepts a list of processors.This PR adds the possibility to test a
receiverin theconfig.yamlfile of a transformation test. The test will "substitute" the "INPUT" part of atest_receiverfrom the pipeline with a testfileslog receiver while keeping the "post-input" logging processors in the pipeline. Theconfig.yamlshould also provide aninput_log_parserto determine how theinput.logis going to be parsed to mock the "INPUT" data.Sample
config.yaml:Related issue
b/429241517
How has this been tested?
Checklist: