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

Refactor flint log format #263

Merged
merged 3 commits into from
Mar 8, 2024

Conversation

noCharger
Copy link
Collaborator

@noCharger noCharger commented Feb 29, 2024

Description

Standardize Flint log output format:

{
  "timestamp": "",
  "severityText": "INFO",
  "severityNumber": 2,
  "body": {
    "message": "",
    "statusCode": ""
  },
  "attributes": {
    "domainName": "",
    "clientId": "",
    "exception.type": "",
    "exception.message": "",
  }
}

Usage V2

  1. Emit log using CustomLogging class
@Override
  public boolean test(T result) throws Throwable {
    int statusCode = ((HttpResponse) result).getStatusLine().getStatusCode();
    logInfo("Checking if status code is retryable: " + statusCode);

    boolean isRetryable = retryableStatusCodes.contains(statusCode);
    logInfo("Status code " + statusCode + " check result: " + isRetryable);
    return isRetryable;
  }
  1. Example log
24/03/08 01:34:46 INFO OpenSearchUpdater: Checking if index exists: flint_ql_sessions
24/03/08 01:34:46 INFO CustomLogging: {"timestamp":1709861686263,"severityText":"INFO","severityNumber":9,"body":{"message":"Checking if status code is retryable: 200"},"attributes":{"clientId":"UNKNOWN","domainName":"UNKNOWN"}}
24/03/08 01:34:46 INFO CustomLogging: {"timestamp":1709861686270,"severityText":"INFO","severityNumber":9,"body":{"message":"Status code 200 check result: false"},"attributes":{"clientId":"UNKNOWN","domainName":"UNKNOWN"}}
24/03/08 01:34:47 INFO CustomLogging: {"timestamp":1709861687144,"severityText":"INFO","severityNumber":9,"body":{"message":"Checking if status code is retryable: 200"},"attributes":{"clientId":"UNKNOWN","domainName":"UNKNOWN"}}
24/03/08 01:34:47 INFO CustomLogging: {"timestamp":1709861687144,"severityText":"INFO","severityNumber":9,"body":{"message":"Status code 200 check result: false"},"attributes":{"clientId":"UNKNOWN","domainName":"UNKNOWN"}}
  1. Contributor insights
Screenshot 2024-03-07 at 6 00 36 PM

Issues Resolved

#235

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@noCharger noCharger marked this pull request as ready for review March 1, 2024 16:48
@YANG-DB
Copy link
Member

YANG-DB commented Mar 1, 2024

Hi
I suggest we follow the OTEL convention for such events - see https://opentelemetry.io/docs/specs/semconv/general/logs/

@noCharger noCharger force-pushed the flint-log-format branch 3 times, most recently from 49b13d7 to e85c8dc Compare March 1, 2024 23:21
*
*/
@Plugin(name = "CustomJsonLayout", category = "Core", elementType = Layout.ELEMENT_TYPE, printObject = true)
public class CustomJsonLayout extends AbstractStringLayout {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. do we need custom json layout? can we leverage Log4j json layout? https://logging.apache.org/log4j/2.x/manual/json-template-layout.html
  2. can we leverage Log4j env lookup for domain_name, client_id? https://logging.apache.org/log4j/2.x/manual/lookups.html#EnvironmentLookup

@noCharger
Copy link
Collaborator Author

noCharger commented Mar 4, 2024

Hi I suggest we follow the OTEL convention for such events - see https://opentelemetry.io/docs/specs/semconv/general/logs/

Propose a new log format following OTEL convention

{
  "timestamp": "",
  "severityText": "INFO",
  "severityNumber": 2,
  "body": {
    "message": "",
    "statusCode": ""
  },
  "attributes": {
    "domainName": "",
    "clientId": "",
    "exception.type": "",
    "exception.message": "",
  }
}

cc: @YANG-DB @penghuo @dai-chen @vamsi-amazon

@YANG-DB
Copy link
Member

YANG-DB commented Mar 5, 2024

Nice !
Can we also calculate the severityNumber ?

@noCharger
Copy link
Collaborator Author

To prevent overriding log4j properties, create a mock log file using the default pattern layout
Screenshot 2024-03-07 at 10 23 27 AM

Screenshot 2024-03-07 at 10 26 01 AM

@noCharger noCharger requested a review from penghuo March 8, 2024 02:01
@noCharger
Copy link
Collaborator Author

@YANG-DB @penghuo Resolved your comments. Please take another review. Thanks!

@penghuo penghuo merged commit 8e810e5 into opensearch-project:main Mar 8, 2024
4 checks passed
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.

4 participants