Skip to content
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

"container_created_at" and "label" fields require extra handling when relaying from Docker to GELF #19114

Open
avollmerhaus opened this issue Nov 10, 2023 · 2 comments
Labels
domain: codecs Anything related to Vector's codecs (encoding/decoding) meta: confirmed A bug that has been reproduced or confirmed. type: bug A code related bug.

Comments

@avollmerhaus
Copy link

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

I'm trying to forward logs from my Docker installation to a Graylog server.
I pasted my vector.yaml file into the "configuration" input field down below.
Using that config, the following errors constantly pop up in Vector's logs:

 vector[19725]: 2023-11-06T15:32:32.746403Z ERROR sink{component_kind="sink" component_id=graylog component_type=socket component_name=graylog}: vector::internal_events::codecs: Failed serializing frame. error=LogEvent contains a value with an invalid type. field = "container_created_at" type = "timestamp" expected type = "string or number" error_type="encoder_failed" stage="sending" internal_log_rate_limit=true
vector[3511422]: 2023-11-10T07:49:13.240877Z ERROR sink{component_kind="sink" component_id=graylog component_type=socket}: vector::internal_events::codecs: Failed serializing frame. error=LogEvent contains a value with an invalid type. field = "label" type = "map" expected type = "string or number" error_code="encoder_serialize" error_type="encoder_failed" stage="sending" internal_log_rate_limit=true

I was able to work around this by using this VRL source:

.container_created_at = to_unix_timestamp(timestamp!(.container_created_at))
del(.label)

I'm not entirely sure what I'm loosing by deleting the "label" field.
I brought the problem up at #19072 and was advised to open a GitHub issue, so here we are :)

Configuration

sources:
  dockerd:
    type: docker_logs

sinks:
  graylog:
    type: "socket"
    inputs: ["dockerd"]
    address: "graylog.example.com:12201"
    mode: "tcp"
    encoding:
      codec: "gelf"

Version

vector 0.34.0 (x86_64-unknown-linux-gnu c909b66 2023-11-07 15:07:26.748571656)

Debug Output

No response

Example Data

No response

Additional Context

No response

References

No response

@avollmerhaus avollmerhaus added the type: bug A code related bug. label Nov 10, 2023
@avollmerhaus avollmerhaus changed the title "container_created_at" field requires extra handling when relaying from Docker to GELF "container_created_at" and "label" fields require extra handling when relaying from Docker to GELF Nov 10, 2023
@bruceg bruceg added source: docker_logs Anything `docker_logs` source related domain: codecs Anything related to Vector's codecs (encoding/decoding) labels Nov 17, 2023
@bruceg
Copy link
Member

bruceg commented Nov 17, 2023

I can reproduce this with the following configuration:

sources:
  stdin:
    type: stdin
    decoding:
      codec: json
sinks:
  console:
    type: console
    inputs: [stdin]
    encoding:
      codec: gelf

With any of the following input:

{"message":"test","label":{}}
{"message":"test","label":true}

Worse yet, this malformed input causes Vector to immediately exit, which is unexpected:

2023-11-17T02:58:14.550332Z ERROR sink{component_kind="sink" component_id=console component_type=console}: vector::internal_events::codecs: Failed serializing frame. error=LogEvent contains a value with an invalid type. field = "label" type = "map" expected type = "string or number" error_code="encoder_serialize" error_type="encoder_failed" stage="sending" internal_log_rate_limit=true
2023-11-17T02:58:14.550639Z ERROR sink{component_kind="sink" component_id=console component_type=console}: vector_common::internal_event::component_events_dropped: Events dropped intentional=false count=1 reason="Failed serializing frame." internal_log_rate_limit=true
2023-11-17T02:58:14.550853Z ERROR sink{component_kind="sink" component_id=console component_type=console}: vector::topology: An error occurred that Vector couldn't handle: the task completed with an error.

As such, the docker_logs source is just one possible trigger for this behavior and is a more generic issue with the gelf codec.

@bruceg bruceg added meta: confirmed A bug that has been reproduced or confirmed. and removed source: docker_logs Anything `docker_logs` source related labels Nov 17, 2023
@MartinEmrich
Copy link
Contributor

Similar problem here. Indeed the vector GELF sink expects the whole event already to be GELF compliant.

(#18008 (comment))

I am making progress with this remap, flattening out everything except timestamp to single-depth string key-value pairs:

            # timestamp MUST be set and be a "timestamp" type, preserve.
            old_timestamp = .timestamp
            if (is_timestamp(.observed_timestamp)) {
              old_timestamp = .observed_timestramp
              del(.observed_timestamp)
            }

            # all other stuff MUST be number or string, no complex data structures. flatten!
            stuff = flatten(., "_")
            stuff = map_keys(stuff, recursive: true) -> |key| { replace(key, ".", "_") }
            stuff = map_values(stuff, true) -> |value| { if is_timestamp(value) { value } else if is_float(value) { value } else if is_integer(value) { value } else { join(value, ", ") ?? to_string(value) ?? value } }
            . = stuff

            # restore non_string timestamp
            if (is_timestamp(old_timestamp) || is_integer(old_timestamp)) {
              .timestamp = old_timestamp
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: codecs Anything related to Vector's codecs (encoding/decoding) meta: confirmed A bug that has been reproduced or confirmed. type: bug A code related bug.
Projects
None yet
Development

No branches or pull requests

3 participants