Slide 1

Slide 1 text

25.09.24 Richard Gross (he/him) Archaeology + Health Checks richargh.de/ speakerdeck.com/richargh @arghrich Hypermedia TestDSLs Continuous Delivery for Legacy Code

Slide 2

Slide 2 text

richargh.de Slide 2 by richargh.de from What are the properties of low- quality software?

Slide 3

Slide 3 text

richargh.de Slide 3 by richargh.de from Dave Farely, author of the best-selling book ā€œContinuous Deliveryā€ The Quality of a System is Defined by Our Ability to Change it! Dave Farley @davefarley77

Slide 4

Slide 4 text

richargh.de Slide 4 by richargh.de from Bad (legacy) software is software where we no longer have any options

Slide 5

Slide 5 text

richargh.de Slide 5 by richargh.de from A story of the worst software I have ever and you will never see. And we still got to Continuous Delivery ā˜ŗ

Slide 6

Slide 6 text

richargh.de Slide 6 by richargh.de from Along comes a customer ā€¦ Icons by Franziska Haaf binarykitten.de COTS ā€žApocalyptoā€œ Please Health Check Customer Me

Slide 7

Slide 7 text

richargh.de Slide 7 by richargh.de from 4M LoC Delivery Excel Webservice Website Fat Client Jobs Database T-SQL JavaScript VBA C# Asp.NET + C# Classic Asp + VBScript WinForms + C# MIA 5M No Code delivered

Slide 8

Slide 8 text

richargh.de Slide 8 by richargh.de from Copy-Based Version ControlTM with production server as origin File tree from actual project

Slide 9

Slide 9 text

richargh.de Slide 9 by richargh.de from Cycle Time of 6 months weeks Dev Machine Cp from Prod Develop Compile Donā€˜t Test Release Cp to Prod 1 hour Bugfixing Return to Start 5 months 6 months

Slide 10

Slide 10 text

richargh.de Slide 10 by richargh.de from Too much to fix Icon by Franziska Haaf binarykitten.de Not Versioned & Doesnā€˜t Compile ā€žInterestingā€œ Deployment Horrible Cycle Time No Tests Conflated Logic, UI & SQL 15 years of Uncontrolled growth

Slide 11

Slide 11 text

richargh.de Slide 11 by richargh.de from Icons by Franziska Haaf binarykitten.de COTS ā€žApocalyptoā€œ In-house ā€žFenixā€œ Buy Iā€˜ll Customer Money

Slide 12

Slide 12 text

richargh.de Slide 12 by richargh.de from Icons by Franziska Haaf binarykitten.de In-house ā€žFenixā€œ Please Fix Me Customer

Slide 13

Slide 13 text

Oh Boy

Slide 14

Slide 14 text

richargh.de Slide 14 by richargh.de from Ken Mugrage @kmugrage Legacy Code is code thatā€™s too scary to update and too profitable to delete. Itā€˜s not CD if you canā€˜t deploy to production right now Dylan Beattie @dylanbeattie

Slide 15

Slide 15 text

richargh.de Slide 15 by richargh.de from Can we deploy this to production right now? Nope

Slide 16

Slide 16 text

richargh.de Slide 16 by richargh.de from Icon by Franziska Haaf binarykitten.de 15 years of Uncontrolled growth

Slide 17

Slide 17 text

richargh.de Slide 17 by richargh.de from Where would I even start? If Iā€™m lucky I have a long list of issues: ā€¢ Issue 1 in file x ā€¢ Issue 2 in file y ā€¢ Issue 3 in file z ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue ā€¦ ā€¢ Issue 9001

Slide 18

Slide 18 text

richargh.de Slide 18 by richargh.de from Donā€™t Fix everything Everyhwere All at once

Slide 19

Slide 19 text

richargh.de Slide 19 by richargh.de from Map your code. Extract your insights. Master your Legacy.

Slide 20

Slide 20 text

richargh.de Slide 20 by richargh.de from Art by Zaufishan

Slide 21

Slide 21 text

richargh.de Slide 21 by richargh.de from Visualize metrics with CodeCharta buildings Open-Source Tool CodeCharta: https://maibornwolff.github.io/codecharta/ SomeService.kt Lines of Code f.ex. Complexity f.ex. Number of authors

Slide 22

Slide 22 text

richargh.de Slide 22 by richargh.de from Find potential hotspots Open-Source Tool CodeCharta: https://maibornwolff.github.io/codecharta/ Lotā€˜s of code, very complex, and everyone has to change it

Slide 23

Slide 23 text

richargh.de Slide 23 by richargh.de from We know what to focus on Not Versioned & Doesnā€˜t Compile

Slide 24

Slide 24 text

richargh.de Slide 24 by richargh.de from Put everything into version control ā€¢ Code ā€¢ Configuration ā€¢ Deployment scripts ā€¢ Infrastructure Provisioning ā€¢ Alerting ā€¢ Monitoring ā€¢ Documentation ā€¢ Onboarding.sh Scripts ā€¢ ā€¦ Git

Slide 25

Slide 25 text

richargh.de Slide 25 by richargh.de from Establish a Pipeline Commit Stage Compile Git

Slide 26

Slide 26 text

richargh.de Slide 26 by richargh.de from We know what to focus on Versioned & Automated Compilation ā€žInterestingā€œ Deployment

Slide 27

Slide 27 text

richargh.de Slide 27 by richargh.de from Scripts to Provision Infrastructure Same but parameterized Scripts for TST, STG and PRD ā€¢ Machine ā€¢ Web Server ā€¢ Application Server ā€¢ Database ā€¢ Email Server ā€¢ FTP Server ā€¢ Pipeline Server Phoenix Infra: With one click we can (re)create any infrastructure Gives us

Slide 28

Slide 28 text

richargh.de Slide 28 by richargh.de from Deploy via Pipeline to Test Env Commit Stage Compile Git Deploy To TST (Cont.) STG (Click) Smoke Test

Slide 29

Slide 29 text

richargh.de Slide 29 by richargh.de from Can we deploy this to production right now? We have a button to do it, but do we want to?

Slide 30

Slide 30 text

richargh.de Slide 30 by richargh.de from No Tests Conflated Logic, UI & SQL We know what to focus on Versioned & Automated Compilation ā€žInterestingā€œ Deployment

Slide 31

Slide 31 text

richargh.de Slide 31 by richargh.de from Characterization test1: Write Tests for code that you donā€™t understand 1 Also called approval or golden master test. 2 Put system in a known (database) state is also an input. 3 Log messages you add are also an output. vX - redesigned v1 - legacy Input for UI/API/DB 2 Output 3 Output 3 Continuous Compare

Slide 32

Slide 32 text

richargh.de Slide 32 by richargh.de from Start with tests for critical use cases and hotspots ā€¢ ~10 E2E Tests For critical use cases ā€¢ DB-Integration Tests For direct-db-access hotspots that you will refactor ā€¢ Unit tests (should give 80% confidence) For refactored hotspots For no-direct-db-access hotspots For new code

Slide 33

Slide 33 text

richargh.de Slide 33 by richargh.de from The tests guide the way 1. Establish a test dsl1,2 ( the easy part) 2. Try to unit test legacy element and ā€¦ fail 3. Realize that coupling prevents you from proper testing 4. Write a too-big integration test 5. Fix coupling problems ( the hard part) 6. Use Dsl to switch integration to unit test 1 https://github.com/Richargh/testdsl 2 Structure-cementing tests and how to avoid them (in German )

Slide 34

Slide 34 text

richargh.de Slide 34 by richargh.de from Understand Coupling and Cohesion High Coupling Low Cohesion Low Coupling High Cohesion Unknown source

Slide 35

Slide 35 text

richargh.de Slide 35 by richargh.de from Uncouple your Code 1 https://www.maibornwolff.de/en/know-how/strangler-fig-pattern/ Delete Obsolete (unreachable or unused) Code Characterization Test, then Refactor Code Sprout new tested Code Break Dependencies (Seams) Strangler Fig1 Unfixable code Feature Flag Legacy Code Write ArchUnit Tests

Slide 36

Slide 36 text

richargh.de Slide 36 by richargh.de from Can we deploy this to production right now? Hmm, itā€™s somewhat tested but can we really be sure nothing breaks in production?

Slide 37

Slide 37 text

richargh.de Slide 37 by richargh.de from Separated Logic, UI & Data in Hotspots Critical Use Case Tests Growing Unit Tests Unit tested new code Horrible Cycle Time We know what to focus on Versioned & Automated Compilation ā€žInterestingā€œ Deployment

Slide 38

Slide 38 text

richargh.de Slide 38 by richargh.de from Do Monitor in Production

Slide 39

Slide 39 text

richargh.de Slide 39 by richargh.de from RED Metrics 1 https://thenewstack.io/monitoring-microservices-red-method/ Community Dashboard https://community.grafana.com/t/how-can-i-configure-red-dashboard/69885 R -> Request Rate E -> Errors / second D -> Duration per request

Slide 40

Slide 40 text

richargh.de Slide 40 by richargh.de from New Cycle Time, without bug-cycle Slide adapted from Dave Farley Commit Stage Compile Unit Test Lint Security Docker Release Git Monitor Logs Events Metrics Alerts Automated Performance testing 20 min Deploy To TST (Cont.) STG (Click) Smoke Test <1 min Manual Testing 30 min Automated Acceptance Testing User Acceptance Test DB-Integration Test 20 min 5 min 60 min

Slide 41

Slide 41 text

richargh.de Slide 42 by richargh.de from Can we deploy this to production right now? Yes. Depending on where we make the change, even within 30min.

Slide 42

Slide 42 text

richargh.de Slide 43 by richargh.de from But there is still a problemā€¦

Slide 43

Slide 43 text

richargh.de Slide 44 by richargh.de from How did the previous developers get here?

Slide 44

Slide 44 text

richargh.de Slide 45 by richargh.de from Healthy Software Ideas Product Process Culture Predicts

Slide 45

Slide 45 text

richargh.de Slide 46 by richargh.de from GIGO Ideas Product Process Culture Predicts

Slide 46

Slide 46 text

richargh.de Slide 47 by richargh.de from A Feature Factory helps no one https://cutlefish.substack.com/p/tbm-4952-your-calendar-your-priorities

Slide 47

Slide 47 text

richargh.de Slide 48 by richargh.de from Henrik Kniberg @henrikkniberg Culture is the sum of everyone's attitude and actions, so model the behaviour you want to see! Observe behavior: ā€¢ Who does the management promote? ā€¢ Is there fear of failure? ā€¢ Is quality appreciated or story points or ā€¦? ā€¢ What is the delivery ā€žprocessā€œ? ā€¢ Is there some kind of learning exchange?

Slide 48

Slide 48 text

richargh.de Slide 49 by richargh.de from Make the desired behavior ā€¦ Obvious ā€¢ Define Principles together ā€¢ Shared purpose Attractive ā€¢ Reduce (time) pressure ā€¢ (Refactoring) score Atomic Habits 4 Laws of behavior change Easy ā€¢ Tech-coach ā€¢ Reduce friction Satisfying ā€¢ Pair up ā€¢ Never break the chain (twice)

Slide 49

Slide 49 text

richargh.de Slide 50 by richargh.de from CD is a change in mindset

Slide 50

Slide 50 text

richargh.de Slide 51 by richargh.de from CD = Working in a way that software is always in a releasable state Itā€™s not about the tools, even though they are getting better all the time

Slide 51

Slide 51 text

richargh.de Slide 52 by richargh.de from Separated logic, UI & data in hotspots Critical E2E Tests; Growing unit test suite; New code always unit tested We know what to focus on Versioned & Automated Compilation ā€žInterestingā€œ Deployment Nice Cycle Time In case you need some help hereā€¦

Slide 52

Slide 52 text

richargh.de Slide 53 by richargh.de from Code Quality Insights Scan to get your insights

Slide 53

Slide 53 text

richargh.de Slide 54 by richargh.de from Thank you @arghrich Richard Gross (he/him) IT Archaeology + Health Checks Hypermedia TestDSLs Works for maibornwolff.de/ Slides, Code, Videos Contact me . at maibornwolff de Contact Ask me about these topics ā˜ŗ richargh.de/ rigross Code Quality Insights

Slide 54

Slide 54 text

richargh.de Slide 55 by richargh.de from Backup

Slide 55

Slide 55 text

richargh.de Slide 56 by richargh.de from

Slide 56

Slide 56 text

richargh.de Slide 57 by richargh.de from 10 customer installations Frobozz Co. Oceanic Airlines ā€¦ Umbrella Corp Soylent Corp

Slide 57

Slide 57 text

richargh.de Slide 58 by richargh.de from And also 10 separate codebases ā€¦ Oceanic Airlines Soylent Corp Frobozz Co. Umbrella Corp Similar C/P Copy/ Paste Feature Copy/Paste

Slide 58

Slide 58 text

richargh.de Slide 59 by richargh.de from 10 codebases And 10 database schemata Similar Similar

Slide 59

Slide 59 text

richargh.de Slide 60 by richargh.de from Our Legacy CD Principles ā€¢ Build quality in ā€¢ Focus on current tree, not on the forest ā€¢ Tackle fear head on ā€¢ Focus on reducing batch size ā€¢ Decouple Deployment and Release ā€¢ Computers perform repetitive tasks, people solve problems CD Principles by Jez Humble Four Principles of Low-Risk Software Releases by Jez Humble

Slide 60

Slide 60 text

richargh.de Slide 61 by richargh.de from Our branching strategy ā€¢ Donā€˜t Branch ā€¢ Donā€˜t Even Branch ā€¢ Branch and youā€™re screwed ā€¢ Never Branch to Refactor ā€¢ Branches indicate Ci =Continuous Isolation

Slide 61

Slide 61 text

richargh.de Slide 62 by richargh.de from The True Cost of Rewrites Original Article by Doug Bradbury The True Cost of Rewrites Features Releases over time Catch Up Missing Features Sub-Par Parity Enhancements Planned Rewrite Actual Features Old App Adoption