Skip to content

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

❌ Patch coverage is 33.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.64%. Comparing base (96d4763) to head (613b7c6).
⚠️ Report is 995 commits behind head on main.

Files with missing lines Patch % Lines
...ollected/files/collect_list/ruleTimestampFormat.go 25.00% 4 Missing and 2 partials ⚠️
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     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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