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

Code Health Score: Gamifying the Reduction of T...

Valera Zakharov
June 10, 2024
31

Code Health Score: Gamifying the Reduction of Technical Debt at Slack

Valera Zakharov

June 10, 2024
Tweet

Transcript

  1. SIMPLE HEALTH SCORE RECIPE ▸ Count problems ▸ Multiply each

    by how bad they are ▸ The score = 0 – (the sum of weighted problems)
  2. A NAIVE IMPLEMENTATION ▸ Examine each fi le in the

    codebase ▸ For each check, return weighted score ▸ Aggregate by fi le & upload to a backend ▸ Display in a pretty dashboard
  3. MY CODEBASE IS LARGE HELP CRAWLER DO LESS WORK WITH

    FILTERS TAKES 55 SEC TO CALCULATE FOR ~30K KOTLIN FILES WITH ~2M LOC
  4. TECH DEBT BY FUNCTIONAL AREA CODE OWNERSHIP ▸ Every fi

    le in codebase is mapped (ensured by breaking PR check)
  5. GOING FURTHER WITH STATIC ANALYSIS ANDROID LINT .sarif fi le

    https://github.com/slackhq/slack-lints
  6. GOING FURTHER WITH STATIC ANALYSIS V1 ANDROID HEALTH SCORE: BUILT

    ENTIRELY ON LINT “SickFile.kt”: { “DeprecatedCall”: -100, }
  7. GOING FURTHER WITH STATIC ANALYSIS V1 LINT-BASED ANDROID HEALTH SCORE

    ▸ Advantages ▸ Easy to wire up dependencies (lint must produce output for health score) ▸ Ecosystem around lint ▸ Lots of existing checks ▸ Violations show up in IDE ▸ Issues ▸ New check = new lint rule = friction. ▸ Platform/build-system speci fi c ▸ Lint is slow ▸ Warnings are suppressible
  8. V3?

  9. GOING FURTHER WITH STATIC ANALYSIS LINT++: BASELINES NEED TO BE

    MERGED https://github.com/slackhq/kotlin-cli- util/blob/main/src/main/kotlin/slack/ cli/lint/LintBaselineMergerCli.kt LINT-BASELINES-MERGED.SARIF
  10. GOING FURTHER WITH STATIC ANALYSIS LINT++ RUNS WITHOUT APPLYING DETEKT

    BASELINE CONTINUES THE RUN AND LET’S IT PASS EVEN WITH ERRORS MERGES ALL THE SERIFS INTO 1 FILE
  11. PREVENTING NEW TECH DEBT FROM ENTERING THE SYSTEM PULL REQUEST

    IMPACT ON HEALTH SCORE: V1 ▸ On dev branch build ▸ Get a list of [modi fi ed, added, deleted] ▸ Calculate local score for only these fi les ▸ Check out main branch and do the same ▸ Diff main score vs dev score ▸ Report to GitHub via PR comment
  12. PREVENTING NEW TECH DEBT FROM ENTERING THE SYSTEM PROBLEMS WITH

    V1 ▸ Doesn’t work well with lint (sarif output fi les are not in source control) ▸ Doesn’t show diffs if health score itself changes ▸ Mutates git state on CI nodes
  13. PREVENTING NEW TECH DEBT FROM ENTERING THE SYSTEM PULL REQUEST

    IMPACT ON HEALTH SCORE: V2 ▸ Store health score output from main branch build in a json payload ▸ On dev build ▸ Download main branch health score from merge_base_commit ▸ Run health score on dev branch ▸ Diff main vs dev ▸ Post to GitHub
  14. PREVENTING NEW TECH DEBT FROM ENTERING THE SYSTEM ` with

    skippy https://slackhq.github.io/slack-gradle-plugin/changelog/#project-skippy w/o skippy
  15. PREVENT MOVING TARGET FREEZE HEALTH SCORE RECIPE FOR A PERIOD

    (E.G. QUARTER) ▸ Maintain 2 versions at the same time ▸ [Current]: used to track progress for this quarter ▸ [Next]: used to experiment with new recipe for next quarter
  16. ALL OF TECH DEBT ALL OF TECH DEBT WHAT OUR

    CONFIG CAPTURES ▸ New tool versions ▸ New code deprecations ▸ Newly concluded feature fl ags ▸ New lint checks
  17. ALIGNING HEALTH SCORE WITH CURRENT PRIORITIES LIST OF CHECKS ▸

    Best with buy in from codebase contributors ▸ May take time to align ▸ Start the conversation and optimize ▸ Some ideas ▸ Disabled tests/lints ▸ Deprecated API usage ▸ A11y violations ▸ Number of fi les in app module (build time bottleneck) ▸ Large Files ▸ .java Files
  18. ALIGNING HEALTH SCORE WITH CURRENT PRIORITIES THOUGHTS ON WEIGHING ▸

    How bad is this thing? ▸ How hard is it to fi x? ▸ How much do you want people to fi x it?
  19. GAMIFICATION SUCCESS ▸ 4 quarters in a row with positive

    health score trend ▸ Removed all accessibility lint violations ▸ Large reduction in the use of mocks in favor of fakes ▸ Consistent removal of stale feature fl ags and disabled tests
  20. GENERALLY THE CODEBASE IS AMONG THE HIGHEST QUALITY IN TERMS

    OF QUALITY. I WOULD RECOMMEND IT TO PEOPLE OF ALL SKILL LEVEL TO WORK ON IT. Quote from latest devxp survey
  21. USING HEALTH SCORE FUTURE ▸ Migrate back into the build

    system ▸ Shift left ▸ Faster lint, please