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

Constructor guards #115

Open
Lewiscowles1986 opened this issue Jan 27, 2022 · 3 comments · May be fixed by #116
Open

Constructor guards #115

Lewiscowles1986 opened this issue Jan 27, 2022 · 3 comments · May be fixed by #116

Comments

@Lewiscowles1986
Copy link
Contributor

Due to a mis-configuration at work, our agent host was in some cases not being set.

This led to (luckily dev/qa time) discovering a PHP warning is thrown at runtime if the class is constructed with an incorrect value.

Like a lot of 12-factor apps, we get our value from ENV, which in our case resulted in no errors and a booting app. But warnings silently output.

I think the constructor of DogStatsTimer should throw if the host configuration is not a valid hostname or IP address. In our case it was false 😂

I Know people SHOULD NOT have warnings output in QA or production environments. But separate to that issue, I would be interesting in contributing this change if the authors are amenable.

@gh123man
Copy link
Member

Sounds reasonable to me.
Feel free to open a PR or if you feel like the contribution is non-trivial we can discuss the approach here.

@Lewiscowles1986
Copy link
Contributor Author

Lewiscowles1986 commented Jan 29, 2022

Okay, so I have a candidate proposal that does not mess with the existing logic, but reorganizes it a bit, gets coverage of new code based upon that; I Hope it not too adventurous, and has some (separated commits) for other things that came up in solving this, but are entirely optional, and can be dropped.

https://github.com/Lewiscowles1986/php-datadogstatsd/tree/feature/injectable-transport

  • Proposed code changes (minimal, interface based)
  • Test fix (I was authoring on Windows, and it was a pain, I could not run tests. It's 2-liner)
  • GitHub actions (until I'd fixed, I actually had a really slow feedback loop)
  • Editor config and git attributes
  • Proposed Documentation (words are hard, forgive me if it's not perfect).
  • Update to support PHP 8.0 & 8.1 thanks to Yoast

Tests

  • PHP 5.6 - PHP 8.1
  • Linting, Code-Style

The actual guard portion of this, doesn't have to be owned by this repo. In the README.md I added a section with example to bypass the magic, re-using the Ipv4Udp transport that is part of this PR, so that an example of instrumenting the control I was looking for (bypassing the magic in current constructor) is available.

I'm not 💯 sure about the construct with single method interface, but felt that opening and closing the socket separately to the functionality; could make some future testing easier. I Also didn't want to open a long-lived socket (although the classes don't hint at that, the way they are used in one place enforces for-now).

The interfaces are pretty stripped-back to deal with PHP 5.6 minimum. Not sure where DataDog is going with that, but I think users would get a lot of benefit rolling up to only 7.4 & 8+ in a future release.

@Lewiscowles1986 Lewiscowles1986 linked a pull request Jan 29, 2022 that will close this issue
@gh123man
Copy link
Member

Thanks for the comprehensive work. For our record keeping, can you please update the PR description with everything you mentioned above?

Also thanks for including the fixes for php 8 + PHPUnit.

Ill leave the rest of my feedback in the PR itself.

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 a pull request may close this issue.

2 participants