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

Log Buckets #1310

Merged
merged 18 commits into from Aug 29, 2018
Merged

Log Buckets #1310

merged 18 commits into from Aug 29, 2018

Conversation

gbirke
Copy link
Member

@gbirke gbirke commented Aug 23, 2018

Add BucketLogWriter interface and a file-based implementation.
Add Logging events for adding donations and membership applications.
Explain how to process the log file for getting a CSV file.

Please do a "Squash and merge" for this PR.

'buckets' => array_reduce( $buckets, function ( array $bucketMap, Bucket $bucket ) {
$bucketMap[$bucket->getCampaign()->getName()] = $bucket->getName();
return $bucketMap;
}, [] )
Copy link
Contributor

Choose a reason for hiding this comment

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

One argument per line would be more readable here for me

gbirke and others added 4 commits August 28, 2018 10:40
Add BucketLogWriter interface and a file-based implementation.
Add the BucketLogWriter to "AddDonation" route.

TODO:
- Add central location for event names.
- Write E2E test case to make sure log is actually written
- Add Logging to creation of memberships.
Improve BucketLogger Creation
Add Edge2Edge test for adding donations.
Create proper value objects for the different logging events to enforce
having the correct metadata and name strings.
@gbirke gbirke changed the title [WIP] Log Buckets Log Buckets Aug 28, 2018
Copy link
Contributor

@timEulitz timEulitz left a comment

Choose a reason for hiding this comment

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

Checked the code ✅, tested it on my local ✅, worked through the documentation ✅; everything worked fine 🔥 and looks good 👀👌 to me.


$logWriter->writeEvent( 'testLogged', [], ...[] );

$this->assertLogValue( date( 'Y-m-d H:i' ), 'date', $logfile );
Copy link
Contributor

Choose a reason for hiding this comment

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

pretty neat that you extracted the assertion into a function 👍

public function testLogWriterAddsDate() {
$logfile = fopen( 'php://memory', 'a+' );
$logWriter = new StreamBucketLogger( $logfile );
$logWriter->setDateFormat( 'Y-m-d H:i' ); // Ignore seconds to avoid Heisentests
Copy link
Contributor

Choose a reason for hiding this comment

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

haha :)

Isn't the issue still there though? Just 60 times less likely to happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

The execution time where this is relevant is just a few milliseconds (maybe even less), so the odds of this being a problem is like a 1 in 60000 chance which should be good enough, otherwise we should start considering ditching Wikipedia and start playing the lottery.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to have this chance at all though

class StreamBucketLoggerTest extends TestCase {

public function testLogWriterAddsDate() {
$logfile = fopen( 'php://memory', 'a+' );
Copy link
Contributor

Choose a reason for hiding this comment

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

What about creating this in setUp? I did not check fully if that makes sense but noticed low level details in test method "arrange" part and repetition. Even if setUp is not suitable extracting this to avoid the low level details might be good.

);
}

public function setDateFormat( string $dateFormat ): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not a constructor parameter?

fwrite(
$this->stream,
json_encode( [
'date' => date( $this->dateFormat ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a global function that relies on global state that gets changed by the system. As you noticed this causes issues when trying to test this code. What about creating a TimeThinghy service? That way this code no longer binds to that changing global state and also no longer needs to know about the time format.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will make a PR into this one with a SuchSuperTimeThinghy

@JeroenDeDauw
Copy link
Contributor

I addressed my own comments in #1315, which is a PR into this one. So please review that one before merging this one, else we'll need to rebase and create a fresh PR, since GH does not handle that situation well.

@JeroenDeDauw JeroenDeDauw merged commit 184dfe2 into master Aug 29, 2018
@JeroenDeDauw JeroenDeDauw deleted the log-buckets branch August 29, 2018 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants