-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Component(s)
pkg/translator/azurelogs
Describe the issue you're reporting
This is an issue that should ideally be done before #39119, if both would move forward.
Currently, some of the unit tests only check a few fields to see if the extraction was successful. Example:
opentelemetry-collector-contrib/pkg/translator/azurelogs/resourcelogs_to_logs_test.go
Lines 687 to 696 in 4e84b33
| func TestAppServiceConsoleLog(t *testing.T) { | |
| logs, err := loadJSONLogsAndApplySemanticConventions("log-appserviceconsolelogs.json") | |
| assert.NoError(t, err) | |
| record := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().Map().AsRaw() | |
| assert.Equal(t, "CONTAINER_ID", record["container.id"]) | |
| assert.Equal(t, "HOST", record["host.id"]) | |
| } |
Instead, we could follow a similar approach to what AWS Logs encoding extension does. By using files, we can compare that everything in the logs matches what is expected a bit like this:
Lines 135 to 144 in 4e84b33
| logs, err := unmarshalerCW.UnmarshalLogs(test.record) | |
| if test.expectedErr != "" { | |
| require.ErrorContains(t, err, test.expectedErr) | |
| return | |
| } | |
| require.NoError(t, err) | |
| expectedLogs, err := golden.ReadLogs(filepath.Join(filesDirectory, test.logsExpectedFilename)) | |
| require.NoError(t, err) | |
| require.NoError(t, plogtest.CompareLogs(expectedLogs, logs)) |
This way we can ensure that any changes done to the code will not affect results, instead of checking that just a few fields won't be changed.
If this change is approved, I volunteer to make these changes.