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

[MIGRATIONS-1326] Add status code comparison metric #430

Conversation

mikaylathompson
Copy link
Collaborator

Description

This uses the metrics logging code (from #376 ) to add a new metric that contains the source and target response status codes and a "are they the same" value to make using this simpler.

It also fixes an issue discovered by sonarqube regarding outputting the entire stack trace in our metrics.

Issues Resolved

MIGRATIONS-1326

Testing

Manually tested

Check List

  • New functionality includes testing
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

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.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

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

Comparison is base (9eed2d7) 63.16% compared to head (d152448) 62.98%.

❗ Current head d152448 differs from pull request most recent head d5c57d5. Consider uploading reports for the commit d5c57d5 to get more accurate results

Files Patch % Lines
...ch/migrations/replay/SourceTargetCaptureTuple.java 7.14% 12 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #430      +/-   ##
============================================
- Coverage     63.16%   62.98%   -0.19%     
  Complexity      873      873              
============================================
  Files           100      100              
  Lines          4341     4355      +14     
  Branches        410      411       +1     
============================================
+ Hits           2742     2743       +1     
- Misses         1328     1340      +12     
- Partials        271      272       +1     
Flag Coverage Δ
unittests 62.98% <7.14%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@mikaylathompson mikaylathompson marked this pull request as ready for review November 15, 2023 05:08
@@ -76,7 +76,6 @@ public MetricsLogBuilder atError(MetricsEvent event, Throwable cause) {
}
return new MetricsLogBuilder(logger).atError(event)
.setAttribute(MetricsAttributeKey.EXCEPTION_MESSAGE, cause.getMessage())
.setAttribute(MetricsAttributeKey.EXCEPTION_STACKTRACE, cause.getStackTrace().toString())
Copy link
Collaborator

Choose a reason for hiding this comment

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

For future reference, this change is NOT required to add a new metric.

Comment on lines +130 to +131
String sourceResponseStatus = (String) meta.getJSONObject("sourceResponse").get("Status-Code");
String targetResponseStatus = (String) meta.getJSONObject("targetResponse").get("Status-Code");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The sourceResponse/targetResponse are filled in with code that runs through this function...

        private JSONObject jsonFromHttpData(@NonNull List<byte[]> data) {
            try {
                return jsonFromHttpDataUnsafe(data);
            } catch (Exception e) {
                log.warn("Putting what may be a bogus value in the output because transforming it " +
                        "into json threw an exception");
                return new JSONObject(Map.of("Exception", e.toString()));
            }
        }

That means that we might have the "Status-Code" values of null. That will be an issue down at line 137 where we'll throw an NPE.

Copy link
Collaborator

@gregschohn gregschohn left a comment

Choose a reason for hiding this comment

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

Still requesting changes.

@@ -119,6 +125,26 @@ private JSONObject toJSONObject(SourceTargetCaptureTuple tuple) {
.ifPresent(d-> meta.put("targetResponse", jsonFromHttpData(d, tuple.targetResponseDuration)));
meta.put("connectionId", tuple.uniqueRequestKey);
Optional.ofNullable(tuple.errorCause).ifPresent(e->meta.put("error", e));

if (meta.has("sourceResponse") && meta.has("targetResponse")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there was no response for the target (or even the source), we probably want to still emit the other status code, and especially the part that it doesn't match, right?

@@ -27,6 +31,8 @@
@Slf4j
public class SourceTargetCaptureTuple implements AutoCloseable {
public static final String OUTPUT_TUPLE_JSON_LOGGER = "OutputTupleJsonLogger";
private static final MetricsLogger metricsLogger = new MetricsLogger("SourceTargetCaptureTuple");
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be a lot cleaner if this were decomposed into separate responsibilities. Here's what we do with the raw requests/responses.
Some of those handlers may convert these to higher order messages.
When we have higher order messages, we should be able to attach consumers/listeners on top of those.
Right now, it's exceptionally easy to see how metrics would be completely suppressed if we decided NOT to log tuple outputs.

gregschohn added a commit to gregschohn/opensearch-migrations that referenced this pull request Nov 15, 2023
…des.

This code attempts to be a reasonable facsimile of the original commit.
A subsequent commit will refactor so that unit tests can be added.

Signed-off-by: Greg Schohn <[email protected]>
@gregschohn gregschohn mentioned this pull request Nov 15, 2023
4 tasks
@gregschohn
Copy link
Collaborator

This has been superceded by #433

@gregschohn gregschohn closed this Nov 16, 2023
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.

2 participants