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

Add support for Monolog 2.x #2302

Merged
merged 4 commits into from
Sep 11, 2019
Merged

Conversation

jeromegamez
Copy link
Contributor

@jeromegamez jeromegamez commented Sep 5, 2019

Hey everyone 👋

This is a follow up to #2293 and aims to add support for both monolog/monolog 1.x and 2.x.

Monolog 2.x was released on August 30th, 2019 and requires PHP ^7.2 whereas google/cloud keeps supporting PHP 5.6.

The specific issue is that Monolog 2.x adds method return types which are not supported by PHP 5.x. On the other hand, leaving the return type declarations out causes PHP 7.x to throw errors.

AppEngineFlexHandler and AppEngineFlexFormatter remain the implementation for Monolog 1.x.

AppEngineFlexV2Handler and AppEngineFlexV2Formatter are the new implementations for Monolog 2.x.

The new classes are the same as the old ones with the only difference being added return type declarations.

Notes

  • I thought about extracting the common code instead of duplicating it, but I didn't want to go overboard in the very first iteration of the PR, I first wanted to check if you would consider merging the change at all :)
  • The Monolog\Logger::API constant has been added in Monolog 1.6, which requires the version bump for the 1.x constraint. Monolog 1.6 has been released in 2013, so I don't think this should be a real-world issue compared to the previous ~1 constraint.
  • The only place where I could find the handlers referenced is on https://cloud.google.com/php/getting-started/logging-application-events?hl=de (switching to English via the language switcher resulted in a 404 for me).

:octocat:

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 5, 2019
@jeromegamez jeromegamez force-pushed the monolog-v2 branch 2 times, most recently from 14e46f9 to 735cf37 Compare September 6, 2019 09:20
@jdpedrie jdpedrie added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
Copy link
Contributor

@jdpedrie jdpedrie left a comment

Choose a reason for hiding this comment

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

Perhaps a factory class would be useful as well? LoggerFactory::getFormatter() and LoggerFactory::getHandler(), both detect which version of monolog is available and construct an implementation?

@jeromegamez
Copy link
Contributor Author

Perhaps a factory class would be useful as well? LoggerFactory::getFormatter() and LoggerFactory::getHandler(), both detect which version of monolog is available and construct an implementation?

I thought about this as well, similar to the HttpHandlerFactory in google/auth, right?

@codecov
Copy link

codecov bot commented Sep 6, 2019

Codecov Report

Merging #2302 into master will decrease coverage by 0.11%.
The diff coverage is 89.74%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2302      +/-   ##
============================================
- Coverage      92.6%   92.48%   -0.12%     
- Complexity     4467     4477      +10     
============================================
  Files           307      311       +4     
  Lines         13323    13352      +29     
============================================
+ Hits          12338    12349      +11     
- Misses          985     1003      +18
Impacted Files Coverage Δ Complexity Δ
Core/src/Logger/AppEngineFlexHandler.php 0% <0%> (-83.34%) 3 <0> (ø)
Core/src/Logger/AppEngineFlexFormatter.php 0% <0%> (-77.78%) 2 <0> (-1)
Core/src/Logger/AppEngineFlexFormatterV2.php 100% <100%> (ø) 2 <2> (?)
Core/src/Logger/AppEngineFlexHandlerV2.php 100% <100%> (ø) 3 <3> (?)
Core/src/Logger/FormatterTrait.php 100% <100%> (ø) 2 <2> (?)
Core/src/Logger/AppEngineFlexHandlerFactory.php 71.42% <71.42%> (ø) 4 <4> (?)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee34ce2...37de613. Read the comment docs.

@jdpedrie
Copy link
Contributor

jdpedrie commented Sep 6, 2019

@jeromegamez yep!

@jeromegamez
Copy link
Contributor Author

Just added an additional commit with the factory \o/ - I had to fix the lower version to ^1.1 because Monolog 1.0.* didn't have an autoloader 😅

Copy link
Contributor

@jdpedrie jdpedrie left a comment

Choose a reason for hiding this comment

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

Thanks again @jeromegamez, appreciate the quick changes! A couple more things I see, and I'm also wondering whether the name format is ambiguous. AppEngineFlexV2Handler seems to me that it could imply it's talking about App Engine Flex V2. Perhaps AppEngineFlexHandlerV2 would be better? What do you think?

@jeromegamez
Copy link
Contributor Author

Thank you @jdpedrie, I appreciate the fast responses! I made the changes and hope this looks better now. Once you are happy with the changes, I would like to squash the changes into a single commit, if you agree.

@jdpedrie jdpedrie added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@jeromegamez
Copy link
Contributor Author

jeromegamez commented Sep 6, 2019

I'm looking into the build failures right now, it seems I missed something in the other test suites.

@jdpedrie
Copy link
Contributor

jdpedrie commented Sep 6, 2019

@jeromegamez it's not your fault, it's an issue with the parser we use to extract and test code snippets. Since it scans the entire project, it fails when it runs into the scalar type hints and return types (in PHP 5) and when those declarations are missing and the interface isn't properly fulfilled (in PHP 7.2+).

Modify Google\Cloud\Core\Testing\Snippet\Coverage\Coverage lines 30-33 to the following:

    private static $snippetExcludeList = [
        '/\\\GcTestListener/',
        '/\\\Google\\\Cloud\\\Core\\\Logger/',
        '/\\\Google\\\Cloud\\\Core\\\PhpArray/',
    ];

@jdpedrie jdpedrie added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@jeromegamez
Copy link
Contributor Author

Whew, I'm relieved 😌! I couldn't get it to work and was already running out of possible workarounds ^^ Thanks!

@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@jeromegamez
Copy link
Contributor Author

Uh, I just realized that I totally misread your Factory proposal... shall I rewrite the factory again?

@jdpedrie
Copy link
Contributor

jdpedrie commented Sep 6, 2019

No, I like how you did it. I don't believe there is generally a need to directly instantiate a formatter, so the single method for the handler is sufficient.

As to the latest build failures, it's the same issue as the previous one, but related to the doc generator. I'll need to investigate workarounds a bit further.

@jeromegamez
Copy link
Contributor Author

jeromegamez commented Sep 6, 2019

@jdpedrie I added something to the doc generator that hopefully can solve the problem - at least executing dev/google-cloud doc -c cloud-core didn't throw a parse error anymore, and the JSON files are generated... as always: on my machine™ 😅 and I haven't had a deeper look into the files to check if they make sense - but they are JSON files \o/

image

@jeromegamez jeromegamez force-pushed the monolog-v2 branch 4 times, most recently from eb3d126 to 4f9a07e Compare September 6, 2019 17:21
@jdpedrie jdpedrie added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 6, 2019
@jeromegamez
Copy link
Contributor Author

I had to update the PR again because I noticed that the class-to-file map in the CodeParser was incorrect - the V2 classes pointed to the V1 files 😓

@jdpedrie jdpedrie added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2019
Copy link
Contributor

@dwsupplee dwsupplee left a comment

Choose a reason for hiding this comment

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

@jeromegamez

You, my friend, are awesome.

This is very well thought out and implemented, I can't thank you enough for taking the time to contribute 👏.

@dwsupplee dwsupplee merged commit 621ec6f into googleapis:master Sep 11, 2019
@jeromegamez
Copy link
Contributor Author

Thank you @dwsupplee, this makes me happy 🥰, and thank you @jdpedrie for the fruitful interaction, this was a lot of fun!

@jeromegamez jeromegamez deleted the monolog-v2 branch September 12, 2019 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants