opening the black box - cornell universityopening the black box. howdy! dustin younse @milsyobtaf...

63
DrupalCamp Cornell 10/20/2017 Opening The Black Box

Upload: others

Post on 04-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

DrupalCamp Cornell 10/20/2017

Opening The Black Box

Page 2: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Howdy!

Dustin Younse @milsyobtaf

I’m an engineer at Acquia

https://github.com/milsyobtaf/prez

Page 3: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

What Is Debugging?

Page 4: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 5: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 6: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 7: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 8: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 9: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

What Is Debugging?

Page 10: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Nothing But Text?

Page 11: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• CSS aggregated but not cached

• JS blocked in the browser

• File permissions in sites/default/files

Nothing But Text?

Page 12: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Mostly a semantic difference

• 5 minutes vs 5 hours?

• “Fixed” vs understood and corrected

Debugging vs Troubleshooting

Page 13: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

What Is The Black Box?

Page 14: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Non-technical education

• Self taught web skills

• Above average Googling abilities

• Late nights staring at error messages

A Familiar Story?

Page 15: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

What Is Drupal?

Page 16: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 17: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 18: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 19: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 20: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 21: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Mental Model of Drupal

Page 22: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Start At The Beginning

Page 23: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

When All You Have Is A Hammer

CC by 2.0 https://www.flickr.com/photos/raindrift/7095238893/

Page 24: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Text Editors• “Text Editors”

• Text Editors

• IDEs

Page 25: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Notepad (Windows)

• Text Edit (Mac)

• Nano (Linux / Mac)

“Text Editors”

Page 26: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Notepad++ (Windows)

• Dreamweaver (Mac / Windows)

• Sublime Text (Mac / Linux / Windows)

• Atom (Mac / Linux / Windows)

• vim (Mac / Linux)

Text Editors

Page 27: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• PHPStorm (Mac / Linux / Windows)

• Eclipse (Mac / Linux / Windows)

• Komodo (Mac / Linux / Windows)

Integrated Development Environments

Page 28: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• emacs (Mac / Linux / Unix / Everything else)

Operating Systems With Built In Text Editors

Page 29: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Development Environments

• On your server

• On your machine

• On your machine, but it acts like the server

Page 30: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Development Environments• FTP Development

• “Cowboy coding”

• Local Environments

• MAMP / LAMP / Vagrant

• Next generation

• Kalabox / Lando CLI

• DrupalVM

Page 31: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• FTP Development

• “Cowboy coding”

• No version control up front

• Little debugging visibility

• Log files (maybe), debug statements

• Watchdog logs (maybe)

FTP Development

Page 32: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• print_r()

• Raw dump of a variable or context, no formatting

• print_r($node);

• <pre><?php print_r($node); ?></pre>

• dsm() / kint()

• Formatted dump of a variable or context

• dsm($node);

Debug Statements in Code

Page 33: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• MAMP / Dev Desktop / Native LAMP

• Code runs entirely locally

• Added bonus of offline work, no internet required

• print_r(), dsm(), kint(), but also more

• xdebug

Local Development

Page 34: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Kalabox / Lando with Pantheon / Acquia integration

• DrupalVM and other custom Vagrant boxes

• print_r(), dsm(), kint(), xdebug

• Very accurate performance profiling

• XHProf

• Blackfire

• Tidewater

Local Development: The Next Generation

Page 35: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

What’s xdebug?

Page 36: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Hitting pause on code execution

• Inspecting the current state of “the stack”

• Modifying values live

xdebug: Step Through Debugging

Page 37: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Something Is Broken!

Page 38: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 39: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Relax.

Page 40: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 41: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Relax.

Page 42: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Remember Cobble’s Knot

Page 43: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Is something not showing up?

• New content - is it published?

• Old content - are permissions set properly?

• Is something showing up that shouldn’t?

• Raw HTML and Javascript in a WYSIWYG field?

What’s Broken?

Page 44: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Log Files

• You should learn how to find your log files before you need your log files

• multitail

• Linux / Mac utility to easily view logswith more options than tail

Work From The Bottom Up

Page 45: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Custom Module

• template.php / .theme file

• Theme Template

Where Is It Broken?

Page 46: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •
Page 47: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

The Scientific Method

Page 48: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Change one thing at a time

• Test that change

• Repeat

Finally, Debugging

Page 49: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Save your progress as you work

• Recreate your Features or config yml

• Makes rabbit holes manageable

git Is Your Friend

Page 50: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Let’s you isolate changes between commits

git bisect Is Your Friend

Page 51: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

git bisect Is Your Friend

Page 52: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

git bisect Is Your Friend

Page 53: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Remove your debug statements

• Ensure you only changed as much as you needed to change

• You only commit dsm(‘Butts’); to master once

git diff Is Your Friend

Page 54: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

git blame Finds Your Enemies

Page 55: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

git blame Finds Your Enemies

Page 56: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

git blame Is Your Friend

Page 57: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Can help you track down who wrote the offending code

• This should not be a witch hunt

• This should be a chance to find context for the issue

git annotate Is Your Friend

Page 58: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Other Debugging Methods

Page 59: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• Walk away. Seriously.

• Talk to a coworker.

• Talk to a rubber duck.

• Write it down. By hand.

Debugging Techniques

Page 60: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Make The Future Easier

Page 61: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• watchdog() (D7)

• \Drupal::logger() (D8)

• syslog Module

• https://www.elastic.co/blog/heya-elastic-stack-and-x-pack

• https://loggly.com

• https://www.sumologic.com

• Write a test!

• Simpletest

• Behat

Proactive Debugging

Page 62: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

• The Art of Troubleshooting by Jason Maxham

• https://artoftroubleshooting.com/book/

• Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems by David Agans

• http://debuggingrules.com

• Debugging During Development in Drupal 8 by Allie Jones

• https://www.gitbook.com/book/zivtech/debug-tools-for-drupal8/

• Using the PhpStorm Debugger by JetBrains

• https://confluence.jetbrains.com/x/_idqAw

• Maniac Magee by Jerry Spinelli

• https://www.worldcat.org/oclc/20422223

FurtherReading

Page 63: Opening The Black Box - Cornell UniversityOpening The Black Box. Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia ... • \Drupal::logger() (D8) • syslog Module ... •

Thanks!Questions?War stories?@milsyobtaf

https://github.com/milsyobtaf/prez