-
Notifications
You must be signed in to change notification settings - Fork 42
[journald_input] Write journald fields as attributes instead of body. #353
Changes from 1 commit
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 |
---|---|---|
|
@@ -72,46 +72,50 @@ func TestInputJournald(t *testing.T) { | |
require.NoError(t, err) | ||
defer op.Stop() | ||
|
||
expected := map[string]interface{}{ | ||
"_BOOT_ID": "c4fa36de06824d21835c05ff80c54468", | ||
"_CAP_EFFECTIVE": "0", | ||
"_TRANSPORT": "journal", | ||
"_UID": "1000", | ||
"_EXE": "/usr/lib/systemd/systemd", | ||
"_AUDIT_LOGINUID": "1000", | ||
"MESSAGE": "run-docker-netns-4f76d707d45f.mount: Succeeded.", | ||
"_PID": "13894", | ||
"_CMDLINE": "/lib/systemd/systemd --user", | ||
"_MACHINE_ID": "d777d00e7caf45fbadedceba3975520d", | ||
"_SELINUX_CONTEXT": "unconfined\n", | ||
"CODE_FUNC": "unit_log_success", | ||
"SYSLOG_IDENTIFIER": "systemd", | ||
"_HOSTNAME": "myhostname", | ||
"MESSAGE_ID": "7ad2d189f7e94e70a38c781354912448", | ||
"_SYSTEMD_CGROUP": "/user.slice/user-1000.slice/[email protected]/init.scope", | ||
"_SOURCE_REALTIME_TIMESTAMP": "1587047866229317", | ||
"USER_UNIT": "run-docker-netns-4f76d707d45f.mount", | ||
"SYSLOG_FACILITY": "3", | ||
"_SYSTEMD_SLICE": "user-1000.slice", | ||
"_AUDIT_SESSION": "286", | ||
"CODE_FILE": "../src/core/unit.c", | ||
"_SYSTEMD_USER_UNIT": "init.scope", | ||
"_COMM": "systemd", | ||
"USER_INVOCATION_ID": "88f7ca6bbf244dc8828fa901f9fe9be1", | ||
"CODE_LINE": "5487", | ||
"_SYSTEMD_INVOCATION_ID": "83f7fc7799064520b26eb6de1630429c", | ||
"PRIORITY": "6", | ||
"_GID": "1000", | ||
"_SYSTEMD_UNIT": "[email protected]", | ||
"_SYSTEMD_USER_SLICE": "-.slice", | ||
"__CURSOR": "s=b1e713b587ae4001a9ca482c4b12c005;i=1eed30;b=c4fa36de06824d21835c05ff80c54468;m=9f9d630205;t=5a369604ee333;x=16c2d4fd4fdb7c36", | ||
"__MONOTONIC_TIMESTAMP": "685540311557", | ||
"_SYSTEMD_OWNER_UID": "1000", | ||
expected := &entry.Entry{ | ||
Timestamp: time.UnixMicro(1587047866229555), | ||
Severity: entry.Info, | ||
SeverityText: "info", | ||
Body: "run-docker-netns-4f76d707d45f.mount: Succeeded.", | ||
Attributes: map[string]string{ | ||
"_BOOT_ID": "c4fa36de06824d21835c05ff80c54468", | ||
"_CAP_EFFECTIVE": "0", | ||
"_TRANSPORT": "journal", | ||
"_UID": "1000", | ||
"_EXE": "/usr/lib/systemd/systemd", | ||
"_AUDIT_LOGINUID": "1000", | ||
"_PID": "13894", | ||
"_CMDLINE": "/lib/systemd/systemd --user", | ||
"_MACHINE_ID": "d777d00e7caf45fbadedceba3975520d", | ||
"_SELINUX_CONTEXT": "unconfined\n", | ||
"CODE_FUNC": "unit_log_success", | ||
"SYSLOG_IDENTIFIER": "systemd", | ||
"_HOSTNAME": "myhostname", | ||
"MESSAGE_ID": "7ad2d189f7e94e70a38c781354912448", | ||
"_SYSTEMD_CGROUP": "/user.slice/user-1000.slice/[email protected]/init.scope", | ||
"_SOURCE_REALTIME_TIMESTAMP": "1587047866229317", | ||
"USER_UNIT": "run-docker-netns-4f76d707d45f.mount", | ||
"SYSLOG_FACILITY": "3", | ||
"_SYSTEMD_SLICE": "user-1000.slice", | ||
"_AUDIT_SESSION": "286", | ||
"CODE_FILE": "../src/core/unit.c", | ||
"_SYSTEMD_USER_UNIT": "init.scope", | ||
"_COMM": "systemd", | ||
"USER_INVOCATION_ID": "88f7ca6bbf244dc8828fa901f9fe9be1", | ||
"CODE_LINE": "5487", | ||
"_SYSTEMD_INVOCATION_ID": "83f7fc7799064520b26eb6de1630429c", | ||
"_GID": "1000", | ||
"_SYSTEMD_UNIT": "[email protected]", | ||
"_SYSTEMD_USER_SLICE": "-.slice", | ||
"__CURSOR": "s=b1e713b587ae4001a9ca482c4b12c005;i=1eed30;b=c4fa36de06824d21835c05ff80c54468;m=9f9d630205;t=5a369604ee333;x=16c2d4fd4fdb7c36", | ||
"__MONOTONIC_TIMESTAMP": "685540311557", | ||
"_SYSTEMD_OWNER_UID": "1000", | ||
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. All these fields are not compliant with OTel naming guidelines. I would rather recommend to make this change in one leap to the attribute names that will be used going forward than just moving all the fields to attributes as is and changing them after that. This would require semantic conventions PR first. Another concern I have is that I'm not sure we need all these fields. Many of them don't provide real value IMO. I think we can reduce number of attributes to essential ones. That's why I suggested to provide an option to not parse the journald payload in the issue, in case if user do want all of these fields as is . cc @djaglowski 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.
Unfortunately, I think waiting for the semantic conventions blocks most of this PR for now, as the body will have to remain structured in order to hold most of the fields. I am on board with waiting though, as this is the best way to ensure we are only moving in the right direction. Shall we:
@gregoryfranklin, are you on board with this? Are you willing to propose the semantic conventions? 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.
One design option that comes to mind is something like the # just the default set
- type: journald_input
# default set plus a few extra fields
- type: journald_input
fields:
- USER_INVOCATION_ID
- _SYSTEMD_USER_UNIT
# alternate predefined set plus a few extra fields
- type: journald_input
field_set: some_other_set
fields:
- USER_INVOCATION_ID
- _SYSTEMD_USER_UNIT
# only a few specific fields
- type: journald_input
field_set: none
fields:
- USER_INVOCATION_ID
- _SYSTEMD_USER_UNIT 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.
The plan looks good to me. And I think 1 should be just an additive change - we can keep the payload and do not remove PRIORITY for now.
This sounds good. Maybe even just fields would be enough. But would it mean that we have to come up with attribute names (semantic conventions) for all existing journald fields? 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.
True. If you leave it unspecified you get all that we have semantic conventions for, otherwise you get what you specify.
I suppose we could make - type: journald_input
fields:
_BOOT_ID: # has semconv => ok, defaults to semconv (e.g. "journald.boot.id")
_COMM: "custom.comm" # no semconv, but user named it => ok
_PID: "custom.pid" # has semconv, but user overrode it => ok
__CURSOR: # no semconv => unmarshal error 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 like this approach. I believe that not all the fields are going to be log attributes, some of them should be resource attributes, right? In that case this configuration model needs to be adjusted. 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. Yeah, makes sense. We can finalize design during implementation, but something to this effect should work well. 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'm fine with waiting for semantic conventions to be added to the spec. I've pushed a suggestion for what this could look like. Feedback is welcome. Some of the fields will be resource attributes, so I've added a For the moment, anything that does not have a semantic convention defined gets passed through unmodified. I've added a commented out list of all the fields defined in the documentation. Do we also want to specify a list of fields that we drop by default? There may be unknown fields, which I guess should be kept if they are unknown (passed through unmodified), so we should probably only drop known fields if they don't get assigned a semantic convention. |
||
}, | ||
} | ||
|
||
select { | ||
case e := <-received: | ||
require.Equal(t, expected, e.Body) | ||
require.Equal(t, expected, e) | ||
case <-time.After(time.Second): | ||
require.FailNow(t, "Timed out waiting for entry to be read") | ||
} | ||
|
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.
Should we try to convert common types to a string? I think all values are strings in the first place, but I think we should avoid silently dropping a field in the event it is not a string.
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.
Yep, can do. The options were to wait for #190 to be fixed (I've not looked at what is needed for this) at which point we'll be able to do this properly or convert everything to a string.