Skip to content

parse_json processor doesn't work with TCP receiver #1920

@ViliusS

Description

@ViliusS

Describe the bug
Apparently parse_json processor doesn't work when used with tcp receiver. I need to parse timestamp for a log. If I use the same parse_json configuration with files receiver with exactly the same log source everything works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. Start a GCE VM with image 'rocky-linux-9-v20240515'
  2. Install Ops Agent version 'google-cloud-ops-agent-2.55.0-1.el9.x86_64.rpm'
  3. Customize the agent with the following configuration' and restart the agent
logging:
  receivers:
    test_log:
      type: tcp
      format: json
  processors:
    parse_json:
      type: parse_json
      time_key: timestamp
      time_format: "%Y-%m-%dT%H:%M:%S.%LZ"
  service:
    pipelines:
      default_pipeline:
        processors: [parse_json]
        receivers: [test_log]
  1. Configure any of the Log4J sources with JSON logging. You can use GcpLayout template provided by the Log4J project.
rootLogger.level = INFO
rootLogger.appenderRef.json_log.ref = json_log
appender.json_log.type = Socket
appender.json_log.name = json_log
appender.json_log.host = localhost
appender.json_log.port = 5170
appender.json_log.layout.type = JsonTemplateLayout
appender.json_log.layout.eventTemplateUri = classpath:GcpLayout.json
  1. Observe that timestamp field is not parsed in Google Logs:
    Image

  2. Now change Google Ops Agent configuration to use files receiver:

logging:
  receivers:
    test_log:
      type: files
      include_paths:
      - /var/log/json/test.log
  processors:
    parse_json:
      type: parse_json
      time_key: timestamp
      time_format: "%Y-%m-%dT%H:%M:%S.%LZ"
  service:
    pipelines:
      default_pipeline:
        processors: [parse_json]
        receivers: [test_log]
  1. Set the source to log to the file, for example:
rootLogger.level = INFO
rootLogger.appenderRef.json_log.ref = json_log
appender.json_log.type = RollingFile
appender.json_log.name = json_log
appender.json_log.fileName = /var/log/json/test.log
appender.json_log.filePattern = /var/log/json/test.log.%i
appender.json_log.strategy.type = DefaultRolloverStrategy
appender.json_log.strategy.max = 1
appender.json_log.layout.type = JsonTemplateLayout
appender.json_log.layout.eventTemplateUri = classpath:GcpLayout.json
appender.json_log.policies.type = Policies
appender.json_log.policies.cron.type = CronTriggeringPolicy
appender.json_log.policies.cron.schedule = 0 0 0 * * ?
appender.json_log.policies.cron.evaluateOnStartup = true
  1. You will now see that timestamp is parsed correctly
    Image

Expected behavior
parse_json processor should be able to parse timestamps when logs is received via tcp receiver.

Environment (please complete the following information):

  • VM distro / OS: Rocky Linux 9.5
  • Ops Agent version 2.55

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions