Skip to content

Conversation

@maxday
Copy link
Contributor

@maxday maxday commented Nov 1, 2021

What does this PR do?

Support the extension by :

  • sending metrics to the extension

  • adding the file detection + hello + flush route calls

  • heavy dependence on finish

  • fix a bug where metrics could have been sent even if disabled

Screen Shot 2021-11-01 at 12 56 29 PM

Screen Shot 2021-11-01 at 4 12 56 PM

Motivation

Start the extension support/tests without being blocked by the flush removal task.

Testing Guidelines

Deploy a function, be able to see logs for instance.

Additional Notes

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Checklist

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@maxday maxday requested a review from a team as a code owner November 1, 2021 17:05
@maxday maxday changed the title [Do Not Merge] Support for the extension - Add hello and flush routes [Do Not Merge] Support for the extension - Add hello and flush routes and metric support Nov 1, 2021
build.gradle Outdated
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
testImplementation 'com.amazonaws:aws-java-sdk-kinesis:1.11.980'

// Use wiremock for stubing http calls
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: stubing -> stubbing
Also, do we need this comment at all?

}
}

public static boolean isExtensionRuning(final String extensionPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isExtensionRuning -> isExtensionRunning

if(hitHelloRoute(AGENT_URL, HELLO_PATH)) {
shouldUseExtension = true;
} else {
DDLogger.getLoggerImpl().debug("Impossible to call the hello route");
Copy link
Contributor

Choose a reason for hiding this comment

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

Impossible to call -> Could not call (throughout file)

"Impossible" would generally mean that there is no way this could ever happen, rather than there was an error this one time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it! thanks 🙏

@nhinsch
Copy link
Contributor

nhinsch commented Nov 1, 2021

LGTM, I just left some spellcheck comments, you should get a review from someone who actually knows Java though

Copy link
Contributor

@agocs agocs left a comment

Choose a reason for hiding this comment

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

This looks good to me too. I think that hitFlush and hitHello should be protected, but the long rant in CustomMetricTest is a nit.

return (f.exists() && !f.isDirectory());
}

public static boolean hitHelloRoute(final String agentUrl, final String helloPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to make hitHelloRoute and hitFlushRoute protected instead of public. That way they'll still be accessible from the tests, but not from the user's code.

I'm debating whether or not it makes sense to remove their arguments and have them access AGENT_URL and HELLO_PATH directly. I think you're doing it this way to support testing. I guess this is one of the best ways of going about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 You're absolutely right, I've made all of them protected.
Yeah I've passed the values for unit testing so I can control the input.

}

@Test public void testExtensionMetricWriter() {
Map<String, Object> map = new LinkedHashMap<>(); // to save the order to avoid flaky test
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

e.printStackTrace();
} finally {
if (ds != null) {
ds.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

awesome

ddm.write();

try {
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably work, but there's a chance any test that relies on something happening in one thread before a sleep in another expires has a chance of failure. I've had similar tests become suddenly flaky, but have only been able to make it fail by running tests in a docker container with .01 cpu.

It might be more stable to communicate the status of our DatagramSocket thread by setting the value of text[0]. E.g. (pseudocode)

final String[] text = new String[1];
text[0] = "not started"

new thread(new runnable() {
blahblah...
try {
  text[0] = "nothing received"
  ds = new DatagramSocket(8125);
  ds.receive(dp);
  text[0] = new String(dp.getData())

} catch .....
  text[0] = "failure"
} finally {
  .....
}
}
}
}.start())

while (true) {
  if ( !text[0].charAt(0).equals("not started") &&  !text[0].charAt(0).equals("nothing received") && !text[0].charAt(0).equals("failure") ) {
  // then we've actually gotten something
  break;
// otherwise loop until the test times out
}
}

This also might be overly complicated, so feel free to disregard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've adjusted the test

@maxday maxday changed the title [Do Not Merge] Support for the extension - Add hello and flush routes and metric support Support for the extension - Add hello and flush routes and metric support Nov 8, 2021
@maxday maxday merged commit 817a416 into main Nov 30, 2021
@maxday maxday deleted the maxday/add-hello-flush-routes branch November 30, 2021 14:48
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