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

Skip Timestamp For Agent Log #885

Merged
merged 1 commit into from
Oct 16, 2023
Merged

Conversation

sethAmazon
Copy link
Contributor

@sethAmazon sethAmazon commented Oct 2, 2023

Description of the issue

The customer noticed the issue because we now log the toml output on start of agent. This includes a line with the date format that is old.
We keep logging the same entry for a bad time stamp config when recording agent logs.

    {
      "agent": {
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
      },
      "logs": {
        "logs_collected": {
          "files": {
            "collect_list": [
          {
                "file_path": "/var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
                "log_group_name": "stage-InstanceLogGroup",
                "log_stream_name": "(v124-1) - /var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
                "timestamp_format": "%Y-%m-%d%H:%M:%S"
              }
            ]
          }
        },
        "force_flush_interval" : 15
      }
    }

If we have a valid timestamp in the log we will not keep logging the same log line.

    {
      "agent": {
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
      },
      "logs": {
        "logs_collected": {
          "files": {
            "collect_list": [
          {
                "file_path": "/var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
                "log_group_name": "stage-InstanceLogGroup",
                "log_stream_name": "(v124-1) - /var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
                "timestamp_format": "%Y-%m-%dT%H:%M:%S"
              }
            ]
          }
        },
        "force_flush_interval" : 15
      }
    }

Description of changes

Do not use timestamp when reading agent log file.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Manual testing to see no log for invalid timestamp in logs with config

log out if time stamp is skipped in translation layer

timestamp_format set timesfile_path : /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log is the same as agent log file /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log thus do not use timestamp_regex
timestamp_format set file_path : /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log is the same as agent log file /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log thus do not use timestamp_layout
{
  "agent": {
    "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
  },
  "logs": {
    "logs_collected": {
      "files": {
        "collect_list": [
      {
            "file_path": "/var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
            "log_group_name": "stage-InstanceLogGroup",
            "log_stream_name": "(v124-1) - /var/log/amazon/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log",
            "timestamp_format": "%Y-%m-%dT%H:%M:%S"
          }
        ]
      }
    },
    "force_flush_interval" : 15
  }
}

# Requirements
_Before commit the code, please do the following steps._
1. Run `make fmt` and `make fmt-sh`
2. Run `make lint`




@sethAmazon sethAmazon requested a review from a team as a code owner October 2, 2023 20:39
@sethAmazon sethAmazon marked this pull request as draft October 2, 2023 20:39
@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2023

Codecov Report

Attention: 37 lines in your changes are missing coverage. Please review.

Comparison is base (96d4763) 57.58% compared to head (613b7c6) 62.64%.
Report is 422 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #885      +/-   ##
==========================================
+ Coverage   57.58%   62.64%   +5.05%     
==========================================
  Files         370      338      -32     
  Lines       17548    17016     -532     
==========================================
+ Hits        10105    10659     +554     
+ Misses       6848     5800    -1048     
+ Partials      595      557      -38     
Files Coverage Δ
cfg/commonconfig/commonconfig.go 8.00% <ø> (ø)
...md/amazon-cloudwatch-agent-config-wizard/wizard.go 59.55% <ø> (-8.51%) ⬇️
...amazon-cloudwatch-agent/amazon-cloudwatch-agent.go 2.64% <ø> (ø)
...oudwatch-agent/register_event_logger_notwindows.go 0.00% <ø> (ø)
...-cloudwatch-agent/register_event_logger_windows.go 0.00% <ø> (ø)
cmd/config-translator/translator.go 0.00% <ø> (ø)
cmd/xray-migration/commands_unix.go 42.50% <ø> (ø)
cmd/xray-migration/commands_windows.go 42.50% <ø> (ø)
cmd/xray-migration/xray-migration.go 30.28% <ø> (ø)
handlers/agentinfo/info.go 84.94% <ø> (ø)
... and 22 more

... and 207 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sethAmazon sethAmazon force-pushed the log-entry-outside branch 3 times, most recently from 6fd1144 to 81e3ecd Compare October 6, 2023 18:04
@sethAmazon sethAmazon changed the title Log Error When Entry Is Outside Of Acceptable Time Range And Debug Th… Skip Timestamp For Agent Log Oct 6, 2023
@sethAmazon sethAmazon force-pushed the log-entry-outside branch 3 times, most recently from 9d13f64 to c8d710a Compare October 6, 2023 18:29
@sethAmazon sethAmazon marked this pull request as ready for review October 6, 2023 18:30
okankoAMZ
okankoAMZ previously approved these changes Oct 9, 2023
Copy link
Contributor

@okankoAMZ okankoAMZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the branch with main, but except for that looks good to me!

Copy link
Contributor

@ymtaye ymtaye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I had PR which will modify the timestamp_layout and timestamp_regex. I can make the changes in my PR if this gets merged first but aside from that all good

Copy link
Contributor

@okankoAMZ okankoAMZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the branch with main, but except for that looks good to me!

@sethAmazon sethAmazon merged commit cfde177 into aws:main Oct 16, 2023
@sethAmazon sethAmazon deleted the log-entry-outside branch October 16, 2023 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants