Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WCEU 2020 - Everything is broken: an introducti...

WCEU 2020 - Everything is broken: an introduction to testing, logging, monitoring and metrics

‘You cannot make an omelette without breaking a few eggs.’ Things are inevitably going to break. And that’s stressful. If your triaging process involves manually seeking through log files or you only find out something is broken after a customer calls you, then you’re probably not fixing problems efficiently.

In this lightning talk Niels will discuss how to prevent, proactively detect and quickly react to issues. He will provide a short overview of tools that help with testing and preventing issues. The talk will cover logging frameworks and platforms that will actively alert you and help find out what’s going wrong. Finally, Niels will advise on adding metrics to your site in order to prevent future issues.

Avatar for Niels de Blaauw

Niels de Blaauw

June 05, 2020
Tweet

More Decks by Niels de Blaauw

Other Decks in Programming

Transcript

  1. My name is Niels de Blaauw. I’m lead developer at

    Level Level, a full-service WordPress Agency in the Netherlands. @nielsdeblaauw
  2. Industry Average: "about 15 - 50 errors per 1000 lines

    of delivered code." (Steve McConnell 2004)
  3. The bad news: You can’t prevent mistakes from happening. The

    good news: You can prepare for mistakes happening.
  4. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early.

    3. Define behaviour for exceptions. 4. Monitor the rest. 1. Log 2. Catch early 3. Define behaviour 4. Monitor Follow along!
  5. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early.

    3. Define behaviour for exceptions. 4. Monitor the rest. 1. Log 2. Catch early 3. Define behaviour 4. Monitor Follow along!
  6. Log event Message Context Level Output 1. Log 2. Catch

    early 3. Define behaviour 4. Monitor
  7. Log event Message Context Level Output 1. Log 2. Catch

    early 3. Define behaviour 4. Monitor What is happening?
  8. Log event Message Context Level Output 1. Log 2. Catch

    early 3. Define behaviour 4. Monitor When? Who? Where?
  9. Log event Message Context Level Output 1. Log 2. Catch

    early 3. Define behaviour 4. Monitor Informational? Warning? Critical?
  10. Log event Message Context Level Output 1. Log 2. Catch

    early 3. Define behaviour 4. Monitor Files Slack Text message
  11. <?php require_once( 'vendor/autoload.php' ); // Use statements skipped for clarity.

    // Create a log channel $log = new Logger( 'MyFirstLogger' ); $log->pushHandler( new SlackWebhookHandler( 'https://slack.com/SECRET' ) ); 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  12. <?php require_once( 'vendor/autoload.php' ); // Use statements skipped for clarity.

    // Create a log channel $log = new Logger( 'MyFirstLogger' ); $log->pushHandler( new SlackWebhookHandler( 'https://slack.com/SECRET' ) ); // Add URL, referrer, etc... $log->pushProcessor( new WebProcessor() ); 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  13. <?php require_once( 'vendor/autoload.php' ); // Use statements skipped for clarity.

    // Create a log channel $log = new Logger( 'MyFirstLogger' ); $log->pushHandler( new SlackWebhookHandler( 'https://slack.com/SECRET' ) ); // Add URL, referrer, etc... $log->pushProcessor( new WebProcessor() ); // Catch unhandled exceptions ErrorHandler::register( $logger ); 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  14. <?php require_once( 'vendor/autoload.php' ); // Use statements skipped for clarity.

    // Create a log channel $log = new Logger( 'MyFirstLogger' ); $log->pushHandler( new SlackWebhookHandler( 'https://slack.com/SECRET' ) ); // Add URL, referrer, etc... $log->pushProcessor( new WebProcessor() ); // Catch unhandled exceptions ErrorHandler::register( $logger ); UndefinedFunction(); ⚠ 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  15. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early.

    3. Define behaviour for exceptions. 4. Monitor the rest. 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  16. 1. Coding standards 2. Integration testing 3. Static analysis tool

    1. Log 2. Catch early 3. Define behaviour 4. Monitor
  17. 1. Coding standards register_post_type( 'author', array() ); // Bad. Reserved

    slug name. 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  18. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    € 15.00 product 2. Integration testing
  19. 2. Integration testing 1. Log 2. Catch early 3. Define

    behaviour 4. Monitor € 15.00 product Order 4x
  20. 2. Integration testing 1. Log 2. Catch early 3. Define

    behaviour 4. Monitor € 15.00 product Order 4x ✔ € 60.00
  21. 2. Integration testing 1. Log 2. Catch early 3. Define

    behaviour 4. Monitor € 15.00 product Order 4x Add 50% discount ⚠ € 30.00
  22. 3. Static analysis tools 1. Log 2. Catch early 3.

    Define behaviour 4. Monitor register_post_type()
  23. 3. Static analysis tools 1. Log 2. Catch early 3.

    Define behaviour 4. Monitor register_post_type() get_rest_controller() \WP_Post_Type ✔
  24. 3. Static analysis tools 1. Log 2. Catch early 3.

    Define behaviour 4. Monitor register_post_type() get_rest_controller() \WP_Post_Type \WP_Error ⚠
  25. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early.

    3. Define behaviour for exceptions. 4. Monitor the rest. 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  26. Failure: The XML document is well formed but the document

    is not valid (10002) 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  27. Two questions matter 1. What is the situation? 2. What

    can we do to resolve the situation? 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  28. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    register_post_type() get_rest_controller() \WP_Post_Type \WP_Error ✔
  29. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    register_post_type() get_rest_controller() \WP_Post_Type \WP_Error ✔ Log event Message, context, level.
  30. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early.

    3. Define behaviour for exceptions. 4. Monitor the rest. 1. Log 2. Catch early 3. Define behaviour 4. Monitor
  31. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    Access logs Error logs Application data System data
  32. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    Access logs Error logs Application data System data Data store
  33. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    Access logs Error logs Application data System data Data store Dashboards Alerts
  34. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    Stats.d $statsd->increment( ‘shop.orders’ );
  35. 1. Log 2. Catch early 3. Define behaviour 4. Monitor

    Stats.d Graphite Store time series data
  36. To recap: You can’t prevent mistakes from happening. You can

    prepare for mistakes happening. 4 milestones: 1. Log exceptions. 2. Catch undefined behaviour early. 3. Define behaviour for exceptions. 4. Monitor the rest.