<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by PRULE70 on Medium]]></title>
        <description><![CDATA[Stories by PRULE70 on Medium]]></description>
        <link>https://medium.com/@prule70?source=rss-d2d60539e44d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1WajXjFGPvIRzpPFydTpzg.jpeg</url>
            <title>Stories by PRULE70 on Medium</title>
            <link>https://medium.com/@prule70?source=rss-d2d60539e44d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:37:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prule70/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Counting down to…]]></title>
            <link>https://medium.com/@prule70/counting-down-to-962139b083c2?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/962139b083c2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[side-project]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Sat, 06 Sep 2025 01:18:30 GMT</pubDate>
            <atom:updated>2025-09-06T01:19:39.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*k1Y7ruPzLa0FIxapgjTSjg@2x.jpeg" /></figure><p>I created a simple web based count down.</p><p><a href="https://mycountdownto.com/">Countdown - Create Beautiful Countdown Timers</a></p><p>Pick a date, time and Timezone – and make it look great with a background image from Unsplash…</p><p>Use it to count down to your birthday, favourite sporting event, the end of your current agile sprint, project deadline – and share with your team/family/public…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*m2HEFzjz0x08K8CqpeAyFg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*A2vPUXX8iS7nsgP6y7y0lg@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962139b083c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using JSON5]]></title>
            <link>https://medium.com/@prule70/using-json5-053787906c2b?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/053787906c2b</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 10:32:58 GMT</pubDate>
            <atom:updated>2025-03-06T10:32:58.022Z</atom:updated>
            <content:encoded><![CDATA[<p>The thing about Json is that it’s hard to document — without comments you can only see the what, not the why. You could use “description” fields, but that’s not very flexible or clean.</p><p>Thank goodness for Json5!</p><p>Json5 is a superset of JSON that allows for comments and trailing commas. It’s a popular choice for configuration files due to its readability and flexibility.</p><p>From the web site:</p><blockquote>Formally, the JSON5 Data Interchange Format is a superset of JSON (so valid JSON files will always be valid JSON5 files) that expands its syntax to include some productions from ECMAScript 5.1 (ES5). It’s also a subset of ES5, so valid JSON5 files will always be valid ES5.*</blockquote><p>Read more about Json5 here: <a href="https://json5.org/">https://json5.org/</a></p><p>The main reason I’m using Json5 is to</p><ul><li>allow for comments</li><li>allow for trailing commas</li><li>avoid quoting property names — making it easy to use in JavaScript or TypeScript</li></ul><p>Lets take a simple Json file:</p><pre>sample.json<br><br>{<br>  &quot;title&quot;: &quot;json example&quot;,<br>  &quot;number&quot;: 123,<br>  &quot;boolean&quot;: true,<br>  &quot;nested&quot;: {<br>    &quot;a&quot;: &quot;b&quot;<br>  },<br>  &quot;multiLineString&quot;: &quot;not possible&quot;<br>}</pre><p>And convert it to Json5:</p><pre>sample-without-comments.json5<br><br>{<br>  title: &#39;json5 example&#39;,<br>  number: 123,<br>  boolean: true,<br>  nested: {<br>    a: &#39;b&#39;,<br>  },<br>  multiLineString: &quot;this is \<br>    a multi-line string&quot;,<br>}</pre><p>Let’s bling it up with comments so we can explain what’s going on:</p><pre>sample.json5<br><br>{<br>  // Main title of the document<br>  title: &#39;json5 example&#39;, // JSON5 allows single quotes<br>  number: 123,            // Numbers remain the same<br>  boolean: true,          // Booleans remain the same<br>  nested: {<br>    a: &#39;b&#39;,               // No need for quotes on simple property names<br>  },                      // Trailing commas are allowed<br>  multiLineString: &quot;this is \<br>    a multi-line string&quot;, // Multi-line strings<br>}</pre><p>Now lets pretend the snippet originated in a TypeScript or JavaScript file — we can copy it to a Json5 file without modification — the point being that we can easily copy from code into configuration without having to convert to Json format — eg quoting the property names:</p><pre>sample-typescript-json5.ts<br><br>// The value assigned to sample here is a direct copy of the json5 content<br>const sample = {<br>    // Main title of the document<br>    title: &#39;json5 example&#39;, // JSON5 allows single quotes<br>    number: 123,            // Numbers remain the same<br>    boolean: true,          // Booleans remain the same<br>    nested: {<br>        a: &#39;b&#39;,               // No need for quotes on simple property names<br>    },                      // Trailing commas are allowed<br>    multiLineString: &quot;this is \<br>    a multi-line string&quot;, // Multi-line strings<br>}<br>console.log(&quot;Sample: &quot;, sample);</pre><h3>How to use it</h3><p>You can use Json5 in your JavaScript or TypeScript code like this:</p><pre>npm install json5<br><br>import JSON5 from &#39;json5&#39;<br><br>const obj = JSON5.parse(json5String)<br>const str = JSON5.stringify(obj)</pre><p>To convert Json5 to Json use the cli:</p><pre>npm install --global json5<br>json5 --out-file sample.json sample.json5<br>json5 --validate sample.json5</pre><p>In Kotlin there is the json5k library: <a href="https://github.com/xn32/json5k">https://github.com/xn32/json5k</a></p><pre>Json5.decodeFromString&lt;Person&gt;(&quot;{ name: &#39;Carl&#39;, age: 42 }&quot;) // Person(name=Carl, age=42)<br>Json5.encodeToString(Person(&quot;John&quot;, 31u)) // {name:&quot;John&quot;,age:31}</pre><p>Intellij IDEA supports Json5 out of the box. Here’s a look at the editor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inuQfBd8DiYPOmxYtc49ow.png" /></figure><p>Here’s a real example of one of my renovate configurations:</p><pre>{<br>  $schema: &quot;https://docs.renovatebot.com/renovate-schema.json&quot;,<br>  extends: [<br>    &quot;config:recommended&quot;<br>  ],<br>  // specify timezone for scheduling<br>  timezone: &quot;Australia/Sydney&quot;,<br>  // run before the workday starts to save pipeline capacity during work hours<br>  schedule: &quot;after 6am and before 8am on Monday&quot;,<br>  packageRules: [<br>    // group minor and patch into one PR and automerge if build checks pass<br>    {<br>      automerge: true,<br>      groupName: &quot;all non-major dependencies&quot;,<br>      groupSlug: &quot;all-minor-patch&quot;,<br>      matchPackageNames: [<br>        &quot;*&quot;<br>      ],<br>      matchUpdateTypes: [<br>        &quot;minor&quot;,<br>        &quot;patch&quot;<br>      ]<br>    }<br>  ]<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=053787906c2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sharing gradle configuration]]></title>
            <link>https://medium.com/@prule70/sharing-gradle-configuration-69ba2e723fca?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/69ba2e723fca</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 08:52:02 GMT</pubDate>
            <atom:updated>2025-02-08T08:52:02.748Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sharing gradle configuration between modules</h3><blockquote><em>Source code for this project is available at </em><a href="https://github.com/prule/gradle-sample"><em>https://github.com/prule/gradle-sample</em></a></blockquote><p>When setting up multimodule gradle projects, we often need to share configuration — such as java toolkit version, plugins, junit platform etc…</p><p>Previously I would have used the allprojects or subprojects block to do this, but now we have convention plugins. These are locally defined plugins which contain the configuration we want to share. The submodules can then apply those plugins without needing to copy and paste the configuration - this makes it easy to selectively choose which plugins to apply to which module.</p><h3>Setting up a multi-module project</h3><p>Install the latest version of gradle using <a href="https://sdkman.io/">sdkman</a>:</p><pre>&gt; gradle-sample % sdk install gradle</pre><p>At time of writing this, the latest version of gradle is 8.12.1</p><pre>&gt; gradle-sample % gradle -v<br>------------------------------------------------------------<br>Gradle 8.12.1<br>------------------------------------------------------------<br>Build time:    2025-01-24 12:55:12 UTC<br>Revision:      0b1ee1ff81d1f4a26574ff4a362ac9180852b140<br>Kotlin:        2.0.21<br>Groovy:        3.0.22<br>Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024<br>Launcher JVM:  21.0.3 (Eclipse Adoptium 21.0.3+9-LTS)<br>Daemon JVM:    /Users/paulrule/.sdkman/candidates/java/21.0.3-tem (no JDK specified, using current Java home)<br>OS:            Mac OS X 15.2 aarch64</pre><p>Lets create a new project using gradle init:</p><pre>&gt; IdeaProjects % mkdir gradle-sample<br>&gt; IdeaProjects % cd gradle-sample<br>&gt; gradle-sample % gradle init<br><br>Select type of build to generate:<br>1: Application<br>2: Library<br>3: Gradle plugin<br>4: Basic (build structure only)<br>Enter selection (default: Application) [1..4] 1<br><br>Select implementation language:<br>1: Java<br>2: Kotlin<br>3: Groovy<br>4: Scala<br>5: C++<br>6: Swift<br>Enter selection (default: Java) [1..6] 2<br>Enter target Java version (min: 7, default: 21): 21<br>Project name (default: gradle-sample):<br><br>Select application structure:<br>1: Single application project<br>2: Application and library project<br>Enter selection (default: Single application project) [1..2] 2<br><br>Select build script DSL:<br>1: Kotlin<br>2: Groovy<br>Enter selection (default: Kotlin) [1..2] 1<br><br>Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no<br><br>&gt; Task :init<br>Learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.12.1/samples/sample_building_kotlin_applications_multi_project.html<br><br>BUILD SUCCESSFUL in 33s<br>1 actionable task: 1 executed</pre><p>Set up sdkman:</p><pre>&gt; gradle-sample % sdk env init<br>.sdkmanrc created.</pre><p>Add a renovate configuration:</p><pre>renovate.json5</pre><h3>Project structure</h3><p>Lets look at the project structure:</p><pre>&gt; gradle-sample % tree .<br>.<br>├── .sdkmanrc<br>├── .gitignore<br>├── renovate.json5<br>├── app<br>│   ├── build.gradle.kts<br>│   └── src<br>│       ├── main<br>│       │   ├── kotlin<br>│       │   │   └── org<br>│       │   │       └── example<br>│       │   │           └── app<br>│       │   │               ├── App.kt<br>│       │   │               └── MessageUtils.kt<br>│       │   └── resources<br>│       └── test<br>│           ├── kotlin<br>│           │   └── org<br>│           │       └── example<br>│           │           └── app<br>│           │               └── MessageUtilsTest.kt<br>│           └── resources<br>├── buildSrc<br>│   ├── build.gradle.kts<br>│   ├── settings.gradle.kts<br>│   └── src<br>│       └── main<br>│           └── kotlin<br>│               ├── buildlogic.kotlin-application-conventions.gradle.kts<br>│               ├── buildlogic.kotlin-common-conventions.gradle.kts<br>│               └── buildlogic.kotlin-library-conventions.gradle.kts<br>├── gradle<br>│   ├── libs.versions.toml<br>│   └── wrapper<br>│       ├── gradle-wrapper.jar<br>│       └── gradle-wrapper.properties<br>├── gradle.properties<br>├── gradlew<br>├── gradlew.bat<br>├── list<br>│   ├── build.gradle.kts<br>│   └── src<br>│       ├── main<br>│       │   ├── kotlin<br>│       │   │   └── org<br>│       │   │       └── example<br>│       │   │           └── list<br>│       │   │               └── LinkedList.kt<br>│       │   └── resources<br>│       └── test<br>│           ├── kotlin<br>│           │   └── org<br>│           │       └── example<br>│           │           └── list<br>│           │               └── LinkedListTest.kt<br>│           └── resources<br>├── settings.gradle.kts<br>└── utilities<br>├── build.gradle.kts<br>└── src<br>├── main<br>│   ├── kotlin<br>│   │   └── org<br>│   │       └── example<br>│   │           └── utilities<br>│   │               ├── JoinUtils.kt<br>│   │               ├── SplitUtils.kt<br>│   │               └── StringUtils.kt<br>│   └── resources<br>└── test<br>└── resources</pre><h3>Convention plugins</h3><p>This project demonstrates how to use convention plugins located in the buildSrc directory. These plugins centralize common build configurations and dependencies, eliminating duplication across modules while allowing for consistent standards.</p><p>In this example, three key convention plugins handle different aspects of the build:</p><ul><li>buildlogic.kotlin-common-conventions: Sets up core Kotlin configuration, repositories, and testing infrastructure shared by all modules</li><li>buildlogic.kotlin-library-conventions: Configures library modules with the java-library plugin and common library settings</li><li>buildlogic.kotlin-application-conventions: Configures the application module with executable settings and application plugin</li></ul><p>This modular plugin structure allows each project module to simply declare which convention plugin it needs. For more information see <a href="https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html">https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html</a></p><p>Here I’ve opted to create an Application with libraries project — we’ve got:</p><pre>1. `app` - the application<br>    1. uses `buildlogic.kotlin-application-conventions`<br>        1. which uses `buildlogic.kotlin-common-conventions`<br>2. `utilities` - a library<br>    1. uses `buildlogic.kotlin-library-conventions`<br>        1. which uses `buildlogic.kotlin-common-conventions`<br>3. `list` - a library<br>    1. uses `buildlogic.kotlin-library-conventions`<br>        1. which uses `buildlogic.kotlin-common-conventions`</pre><h3>Gradle build logic</h3><p>In our modules:</p><pre>- app<br>    - `build.gradle.kts` uses the `buildlogic.kotlin-application-conventions` plugin:<br>      <br>      plugins {<br>        id(&quot;buildlogic.kotlin-application-conventions&quot;)<br>      }<br>      <br>- utilities and list<br>    - `build.gradle.kts` uses the `buildlogic.kotlin-library-conventions` plugin:<br>      <br>      plugins {<br>        id(&quot;buildlogic.kotlin-library-conventions&quot;)<br>      }</pre><h3>Summary</h3><p>By using the plugins, we’ve avoided copying and pasting the configurations (which are now in the conventions plugins) or using the allprojects and subprojects blocks. With the plugins being local to the project we can easily modify them as we need to, and easily provide consistency across the project.</p><blockquote><em>Tip: Use the latest version of gradle to create a new project so you can learn what the default project layout looks like — this is how I found out about the </em><em>libs.versions.toml file!</em></blockquote><p>Depending on your project you might want to create different convention plugins for things like:</p><p>buildlogic.kotlin-test-conventions:</p><ul><li>Configure test frameworks like Mockk, Kotest</li><li>Set up test reporting</li><li>Define test sets (integration, e2e, performance)</li></ul><p>buildlogic.documentation-conventions:</p><ul><li>Configure Dokka for Kotlin documentation</li><li>Set up README validation</li><li>Manage API documentation generation</li></ul><p>buildlogic.quality-conventions:</p><ul><li>Set up Detekt for static analysis</li><li>Configure ktlint for code formatting</li><li>Add SonarQube integration</li><li>Define code coverage thresholds</li></ul><p>buildlogic.publishing-conventions:</p><ul><li>Configure Maven publication</li><li>Set up signing</li><li>Manage artifact metadata</li></ul><p>buildlogic.platform-conventions:</p><ul><li>Define a version catalog platform</li><li>Manage dependency constraints</li><li>Handle cross-platform configurations</li></ul><p>buildlogic.performance-conventions:</p><ul><li>Configure build cache</li><li>Set up parallel execution</li><li>Define optimization rules</li></ul><p>Each of these would fit nicely into the existing buildSrc structure and follow the same pattern of separating concerns while promoting reuse across modules.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69ba2e723fca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Renovate to manage dependencies]]></title>
            <link>https://medium.com/@prule70/using-renovate-to-manage-dependencies-27eb4c2e52b9?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/27eb4c2e52b9</guid>
            <category><![CDATA[renovate]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 07:26:01 GMT</pubDate>
            <atom:updated>2025-02-02T07:26:01.865Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automated Dependency Management Made Simple</h3><p>In modern software development, managing dependencies is a critical yet often overlooked aspect of maintaining healthy codebases. Enter Renovate: an open-source tool that automates dependency updates, making your project maintenance both easier and more secure.</p><h3>What is Renovate?</h3><p>Renovate is an automated dependency management tool that monitors your repository’s dependencies and automatically creates pull requests when updates become available. Think of it as your personal assistant that constantly checks for new versions of the libraries and packages your project uses.</p><h3>Why Your Team Needs Renovate</h3><h3>1. Security Through Timeliness</h3><p>Outdated dependencies are security vulnerabilities waiting to happen. Renovate ensures you’re promptly notified of security patches and updates, allowing you to maintain a secure codebase proactively rather than reactively.</p><h3>2. Reduced Manual Work</h3><p>Gone are the days of manually checking for updates or running npm audit periodically. Renovate automates this process, creating pull requests that: - Update dependencies to their latest versions - Include release notes and changelogs - Can be configured to auto-merge for minor updates</p><h3>3. Gradual Updates</h3><p>Instead of facing a mountain of outdated dependencies every few months, Renovate helps you stay current through small, manageable updates. This approach: — Reduces the risk of breaking changes — Makes debugging easier when issues occur — Keeps technical debt from accumulating</p><h3>Getting Started</h3><p>Setting up Renovate is straightforward:</p><ol><li>Install Renovate in your repository (through GitHub App or self-hosted)</li><li>Add a basic configuration file (renovate.json)</li><li>Let Renovate create its first “onboarding” pull request</li></ol><p>A minimal configuration might look like this:</p><pre>{<br>  &quot;$schema&quot;: &quot;https://docs.renovatebot.com/renovate-schema.json&quot;,<br>  &quot;extends&quot;: [&quot;config:base&quot;]<br>}</pre><h3>Best Practices</h3><p>To get the most out of Renovate, consider these best practices:</p><ul><li>Start with the default configuration and customize gradually</li><li>Use preset configurations for your specific ecosystem</li><li>Configure auto-merging for patch updates</li><li>Set up scheduled updates to avoid overwhelming your CI pipeline</li><li>Group related dependencies to minimize PR noise</li></ul><h3>Example</h3><p>Here’s a simple example of a Renovate configuration file:</p><p>renovate.json5 configuration</p><pre>{<br>  &quot;$schema&quot;: &quot;https://docs.renovatebot.com/renovate-schema.json&quot;,<br>  &quot;extends&quot;: [<br>    &quot;config:recommended&quot;<br>  ],<br>  // specify timezone for scheduling<br>  &quot;timezone&quot;: &quot;Australia/Sydney&quot;,<br>  // run before the workday starts to save pipeline capacity during work hours<br>  &quot;schedule&quot;: &quot;after 6am and before 8am on Monday&quot;,<br>  &quot;packageRules&quot;: [<br>    // group minor and patch into one PR and automerge if build checks pass<br>    {<br>      &quot;automerge&quot;: true,<br>      &quot;groupName&quot;: &quot;all non-major dependencies&quot;,<br>      &quot;groupSlug&quot;: &quot;all-minor-patch&quot;,<br>      &quot;matchPackageNames&quot;: [<br>        &quot;*&quot;<br>      ],<br>      &quot;matchUpdateTypes&quot;: [<br>        &quot;minor&quot;,<br>        &quot;patch&quot;<br>      ]<br>    }<br>  ]<br>}</pre><p>Key points to note:</p><p>Scheduled to run on Monday mornings</p><ul><li>Conveniently runs before the workday starts, leaving pipeline capacity free for your team when they need it most</li><li>Also helps if you have automated deployments — less interruption/change during your work day</li></ul><p>Groups minor and patch updates together into one PR</p><ul><li>This reduces the number of PRs and makes it easier to review and minimises noise</li><li>example: <a href="https://github.com/prule/rest-hateoas/pull/54">https://github.com/prule/rest-hateoas/pull/54</a></li></ul><p>Automatically merges minor/patch updates (if CI checks pass)</p><ul><li>This helps keep the repository up-to-date without manual intervention — less PRs to review!</li></ul><p>Example pull requests from one of my repositories:</p><ul><li><a href="https://github.com/prule/rest-hateoas/pulls?q=is%3Apr+is%3Aclosed+renovate">https://github.com/prule/rest-hateoas/pulls?q=is%3Apr+is%3Aclosed+renovate</a></li></ul><p>You’ll want to have CI checks configured so that Renovate can merge PRs automatically. I use a github action to run ./gradlew build to ensure the project compiles and passes all tests:</p><p>Github action to build project</p><pre># This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time<br># For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle<br>name: Java CI with Gradle<br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]<br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    permissions:<br>      contents: read<br>    steps:<br>    - uses: actions/checkout@v4<br>    - name: Set up JDK<br>      uses: actions/setup-java@v4<br>      with:<br>        java-version: &#39;21&#39;<br>        distribution: &#39;temurin&#39;<br>    # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.<br>    # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md<br>    - name: Setup Gradle<br>      uses: gradle/actions/setup-gradle@94baf225fe0a508e581a564467443d0e2379123b # v4.3.0<br>    - name: Build with Gradle Wrapper<br>      run: ./gradlew build</pre><p>example: <a href="https://github.com/prule/rest-hateoas/actions/runs/13094941863/job/36536104338">https://github.com/prule/rest-hateoas/actions/runs/13094941863/job/36536104338</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbd2fJiIBBJRUM3Nciu8Aw.png" /><figcaption>Figure 1. Github build output</figcaption></figure><p>If the build fails with compile errors or tests failing, Renovate will not merge the PR, and you’ll need to fix the issue and merge the PR manually.</p><p>In some corporate environments you may have standards for branch naming and commit messages. You can configure Renovate to use a specific branch name and commit message format using the branchPrefix, prHeader and commitMessage options.</p><p>See <a href="https://docs.renovatebot.com/configuration-options/">https://docs.renovatebot.com/configuration-options/</a> for more details.</p><p>To get started with Renovate on Github, follow the instructions on the official documentation: <a href="https://docs.renovatebot.com/getting-started/installing-onboarding/#hosted-githubcom-app">https://docs.renovatebot.com/getting-started/installing-onboarding/#hosted-githubcom-app</a></p><p>Once up and running, you’ll see an issue in your repository with a link to the Renovate dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFYcGnpuS7zyXQHlXdDdyw.png" /><figcaption>Figure 2. Renovate dashboard</figcaption></figure><p>If you view the dashboard, you’ll see a checkbox that lets you trigger renovate to run again on the repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R26oqF8iU5A6WrVnAdljuQ.png" /><figcaption>Figure 3. Renovate dashboard detail</figcaption></figure><p>This is particularly useful if you’ve changed the configuration and don’t want to wait for the next scheduled run.</p><p>So there it is! Keep your dependencies up to date with Renovate. It’s a great way to keep your codebase healthy and your team productive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27eb4c2e52b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use SDKMAN! to manage your projects SDKs]]></title>
            <link>https://medium.com/@prule70/use-sdkman-to-manage-your-projects-sdks-3c3ebb38d799?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c3ebb38d799</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sdkman]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 01:52:51 GMT</pubDate>
            <atom:updated>2024-09-15T01:52:51.724Z</atom:updated>
            <content:encoded><![CDATA[<p>SDKMAN! lets you install, manage and work with multiple versions of software development kits (SDKs) on most Unix-like systems.</p><p>This means for example, you can install multiple versions of Java, Kotlin, Scala, Groovy, Gradle, Maven, Grails, Spring Boot, and many more. See the full list as of mid 2024 <a href="https://github.com/prule/blogging/blob/main/posts/sdkman/sdk-list.txt">here</a>.</p><h3>Installation</h3><p>For installation instructions see the SDKMAN! website <a href="https://sdkman.io/install">here</a>.</p><h3>Usage</h3><p>For common usage demonstration, using JAVA as an example:</p><p>To find all available versions of Java, run:</p><pre>sdk list java</pre><p>This will show a list of available versions:</p><pre>================================================================================<br>Available Java Versions for macOS ARM 64bit<br>================================================================================<br> Vendor        | Use | Version      | Dist    | Status     | Identifier<br>--------------------------------------------------------------------------------<br> Corretto      |     | 22.0.2       | amzn    |            | 22.0.2-amzn<br>               |     | 21.0.4       | amzn    |            | 21.0.4-amzn<br>               |     | 17.0.12      | amzn    |            | 17.0.12-amzn<br>               |     | 11.0.24      | amzn    |            | 11.0.24-amzn<br>               |     | 8.0.422      | amzn    |            | 8.0.422-amzn<br>               |     | 8.0.412      | amzn    | local only | 8.0.412-amzn<br> Gluon         |     | 22.1.0.1.r17 | gln     |            | 22.1.0.1.r17-gln<br>               |     | 22.1.0.1.r11 | gln     |            | 22.1.0.1.r11-gln<br> GraalVM CE    |     | 22.0.2       | graalce |            | 22.0.2-graalce<br>               |     | 21.0.2       | graalce |            | 21.0.2-graalce<br>               |     | 17.0.9       | graalce |            | 17.0.9-graalce<br> GraalVM Oracle|     | 24.ea.11     | graal   |            | 24.ea.11-graal<br>               |     | 24.ea.9      | graal   |            | 24.ea.9-graal<br>               |     | 24.ea.8      | graal   |            | 24.ea.8-graal<br><br>... (the list goes on)</pre><p>See <a href="https://github.com/prule/blogging/blob/main/posts/sdkman/sdk-list-java.txt">sdk-list-java.txt</a> for the full list as of mid 2024.</p><p>To install java, choose the identifier (e.g. 22.0.1-open) for the version you want, and run:</p><pre>% sdk install java 22.0.1-open<br><br>Downloading: java 22.0.1-open<br><br>In progress...<br><br>######################################################################################################################################################################################################################################################### 100.0%<br>Repackaging Java 22.0.1-open...<br>Done repackaging...<br>Cleaning up residual files...<br>Installing: java 22.0.1-open<br>Done installing!<br>Do you want java 22.0.1-open to be set as default? (Y/n): n</pre><p>To see what versions of java you have installed, run:</p><pre>% sdk list java | grep -E &quot;installed|local only&quot;<br>|     | 8.0.412      | amzn    | local only | 8.0.412-amzn<br>|     | 22.0.1       | open    | installed  | 22.0.1-open<br>| &gt;&gt;&gt; | 21.0.3       | tem     | local only | 21.0.3-tem<br>|     | 17.0.7       | tem     | local only | 17.0.7-tem<br>|     | 11.0.24      | tem     | installed  | 11.0.24-tem<br>|     | 11.0.19      | tem     | local only | 11.0.19-tem</pre><p>To use a specific version of java, run:</p><pre>% sdk use java 22.0.1-open<br><br>Using java version 22.0.1-open in this shell.</pre><p>Confirm with `java -version`</p><pre>% java -version<br><br>openjdk version &quot;22.0.1&quot; 2024-04-16<br>OpenJDK Runtime Environment (build 22.0.1+8-16)<br>OpenJDK 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)</pre><p>When you are in the root of your java project, set the appropriate java version using sdk use java &lt;id&gt; and then run:</p><pre>% sdk env init<br><br>.sdkmanrc created.</pre><p>This creates a .sdkmanrc file in the root of your project, which contains the following:</p><pre># Enable auto-env through the sdkman_auto_env config<br># Add key=value pairs of SDKs to use below<br>java=21.0.3-tem</pre><p>Intellij supports sdkman so your project should be configured to use the correct version of java.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jquKGXylH7BlN2Zq.png" /></figure><p>Enable auto switching of java versions as you switch between projects on the command line by setting sdkman_auto_env=true in ~/.sdkman/etc/config. Now as you `cd` into a directory, the correct version of java will be enabled.</p><pre>% cd posts/sdkman <br><br>Using java version 21.0.3-tem in this shell.<br><br>% cd ../..<br><br>Using java version 22.0.1-open in this shell.</pre><p>If you checkout a project, use `sdk env install` to ensure you have the right SDKs installed and activated.</p><pre>% sdk env install<br><br>java 21.0.3-tem is already installed.<br><br>Using java version 21.0.3-tem in this shell.</pre><p>See the full documentation at <a href="https://sdkman.io/usage/">https://sdkman.io/usage/</a></p><h3>Summary</h3><p>When starting a new project, install specific versions of the tools you need using SDKMAN!.</p><p>Make sure to commit an .sdkmanrc file to the root of your project so that your team members can use the same versions of the tools you are using. They can easily install the correct versions using sdk env install.</p><p>This will ensure that you have a consistent development environment, regardless of the machine you are working on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c3ebb38d799" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week in review — 2024–08–25]]></title>
            <link>https://medium.com/@prule70/week-in-review-2024-08-25-d534c77e83a3?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d534c77e83a3</guid>
            <category><![CDATA[week-in-review]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Wed, 11 Sep 2024 00:58:40 GMT</pubDate>
            <atom:updated>2024-09-11T00:58:40.545Z</atom:updated>
            <content:encoded><![CDATA[<h3>Week in review — 2024–08–25</h3><p>Week 34 of 2024 in review</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TaptikbWJktI7QlBvLKO0Q.jpeg" /></figure><p><a href="https://roadmap.sh/">https://roadmap.sh</a></p><ul><li>roadmap.sh is a community effort to create roadmaps, guides and other educational content to help guide developers in picking up a path and guide their learnings.</li><li>Roadmaps based on Role or Skill, plus best practice and questions to test your knowledge</li></ul><p><a href="https://www.startdataengineering.com/">https://www.startdataengineering.com</a></p><ul><li>An interesting blog with lots of data engineering information</li></ul><p>For example:</p><ul><li>What are the types of data quality checks?</li><li>How to implement data quality checks with great expectations</li><li>Why use Apache Airflow (or any orchestrator)?</li></ul><p><a href="https://switowski.com/blog/i-have-built-my-first-successful-side-project-and-i-hate-it/">https://switowski.com/blog/i-have-built-my-first-successful-side-project-and-i-hate-it/</a></p><ul><li>The trials and tribulations of making money from a side project — it’s not all plain sailing.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d534c77e83a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding a unit test to DBT]]></title>
            <link>https://medium.com/@prule70/adding-a-unit-test-to-dbt-fa8216350462?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa8216350462</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-build-tool]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 02:17:29 GMT</pubDate>
            <atom:updated>2024-08-30T02:17:29.416Z</atom:updated>
            <content:encoded><![CDATA[<h4>Testing logic in a model by adding a test with mock data and expected output</h4><blockquote>The source code for this article is available at <a href="https://github.com/prule/dbt-spike/tree/main">github</a>.</blockquote><p>In the <a href="https://github.com/prule/dbt-spike/blob/66c2a31bdd0374dbfdda582f39eeca7569c7ad14/spike_postgres/models/solve_any_data_analysis_problem_ch2/addresses_silver.sql">addresses_silver.sql</a> model I’ve got some logic where it adds a city column, and it tries to find a matching value from the cities table — if nothing matches, then city should be set to “OTHER”.</p><pre>coalesce(<br>        (select city from {{ ref(&#39;cities_silver&#39;) }} where UPPER(address) like &#39;%&#39;||chr(10)||city||&#39;,%&#39; order by city desc limit 1),<br>         &#39;OTHER&#39;<br>    ) as city</pre><p>I’m going to add a unit test to check that this logic works as expected.</p><p>Since I’m using DBT 1.8 I can add unit tests as described <a href="https://docs.getdbt.com/reference/resource-properties/unit-tests">here</a> — I just need a YAML file in the models folder which:</p><ul><li>has a unique name for each unit test</li><li>identifies the model being tested</li><li>defines some input data (unit tests don’t use the real data as we are testing LOGIC)</li><li>defines the expected output</li></ul><p>So in <a href="https://github.com/prule/dbt-spike/blob/0e10323781d921b5c25cd82abc520e9db1e722ad/spike_postgres/models/solve_any_data_analysis_problem_ch2/addresses_silver_unit_test.yml">models/solve_any_data_analysis_problem_ch2/addresses_silver_unit_test.yml</a> I define a test when_no_city_is_mapped_city_should_be_other.</p><p>Since the model under test references cities_silver and addresses_bronze I define the contents of these views as mock data:</p><ul><li>the contents of the cities_silver view contains 1 row,</li><li>and 2 rows for the addresses_bronze view</li><li>The first row will find a city, the second won’t so should result in city being set to OTHER.</li></ul><pre>unit_tests:<br>  - name: when_no_city_is_mapped_city_should_be_other # this is the unique name of the test<br>    model: addresses_silver # name of the model I&#39;m unit testing<br>    given: # the mock data for your inputs<br>      - input: ref(&#39;cities_silver&#39;)<br>        rows:<br>          - {city: &#39;CITY1&#39;}<br>      - input: ref(&#39;addresses_bronze&#39;)<br>        rows:<br>          - {company_id: &#39;id1&#39;, address: &quot;addr1,\ncity1, country&quot;, total_spend: 1}<br>          - {company_id: &#39;id2&#39;, address: &quot;addr2, \ncity2, country&quot;, total_spend: 2}<br>    expect: # the expected output given the inputs above<br>      rows:<br>        - {company_id: &#39;id1&#39;, address: &quot;ADDR1,\nCITY1, COUNTRY&quot;, total_spend: 1, city: &#39;CITY1&#39;}<br>        - {company_id: &#39;id2&#39;, address: &quot;ADDR2, \nCITY2, COUNTRY&quot;, total_spend: 2, city: &#39;OTHER&#39;}</pre><p>I can run the unit test with ../run test:unit to get</p><pre>% ../run test:unit<br>Running unit tests<br>22:52:03  Running with dbt=1.8.4<br>22:52:03  Registered adapter: postgres=1.8.2<br>22:52:03  Found 5 models, 6 data tests, 417 macros, 1 unit test<br>22:52:03  <br>22:52:03  Concurrency: 1 threads (target=&#39;dev&#39;)<br>22:52:03  <br>22:52:03  1 of 1 START unit_test addresses_silver::when_no_city_is_mapped_city_should_be_other  [RUN]<br>22:52:03  1 of 1 PASS addresses_silver::when_no_city_is_mapped_city_should_be_other ...... [PASS in 0.13s]<br>22:52:03  <br>22:52:03  Finished running 1 unit test in 0 hours 0 minutes and 0.30 seconds (0.30s).<br>22:52:03  <br>22:52:03  Completed successfully<br>22:52:03  <br>22:52:03  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1</pre><p>If I want I can run all tests (data and unit) with ../run test:</p><pre>% ../run test     <br>Running tests<br>22:58:47  Running with dbt=1.8.4<br>22:58:47  Registered adapter: postgres=1.8.2<br>22:58:48  Found 5 models, 6 data tests, 417 macros, 1 unit test<br>22:58:48  <br>22:58:48  Concurrency: 1 threads (target=&#39;dev&#39;)<br>22:58:48  <br>22:58:48  1 of 7 START test not_null_addresses_silver_address ............................ [RUN]<br>22:58:48  1 of 7 PASS not_null_addresses_silver_address .................................. [PASS in 0.09s]<br>22:58:48  2 of 7 START test not_null_addresses_silver_city ............................... [RUN]<br>22:58:53  2 of 7 PASS not_null_addresses_silver_city ..................................... [PASS in 5.41s]<br>22:58:53  3 of 7 START test not_null_addresses_silver_company_id ......................... [RUN]<br>22:58:53  3 of 7 PASS not_null_addresses_silver_company_id ............................... [PASS in 0.03s]<br>22:58:53  4 of 7 START test not_null_addresses_silver_total_spend ........................ [RUN]<br>22:58:53  4 of 7 PASS not_null_addresses_silver_total_spend .............................. [PASS in 0.03s]<br>22:58:53  5 of 7 START test not_null_cities_silver_city .................................. [RUN]<br>22:58:53  5 of 7 PASS not_null_cities_silver_city ........................................ [PASS in 0.02s]<br>22:58:53  6 of 7 START test unique_cities_silver_city .................................... [RUN]<br>22:58:53  6 of 7 PASS unique_cities_silver_city .......................................... [PASS in 0.02s]<br>22:58:53  7 of 7 START unit_test addresses_silver::when_no_city_is_mapped_city_should_be_other  [RUN]<br>22:58:54  7 of 7 PASS addresses_silver::when_no_city_is_mapped_city_should_be_other ...... [PASS in 0.16s]<br>22:58:54  <br>22:58:54  Finished running 6 data tests, 1 unit test in 0 hours 0 minutes and 5.93 seconds (5.93s).<br>22:58:54  <br>22:58:54  Completed successfully<br>22:58:54  <br>22:58:54  Done. PASS=7 WARN=0 ERROR=0 SKIP=0 TOTAL=7</pre><p>And just for completeness, this is what it looks like if a unit test fails:</p><pre>% ../run test:unit<br>Running unit tests<br>23:00:09  Running with dbt=1.8.4<br>23:00:09  Registered adapter: postgres=1.8.2<br>23:00:09  Found 5 models, 6 data tests, 417 macros, 1 unit test<br>23:00:09  <br>23:00:09  Concurrency: 1 threads (target=&#39;dev&#39;)<br>23:00:09  <br>23:00:09  1 of 1 START unit_test addresses_silver::when_no_city_is_mapped_city_should_be_other  [RUN]<br>23:00:09  1 of 1 FAIL 1 addresses_silver::when_no_city_is_mapped_city_should_be_other .... [FAIL 1 in 0.16s]<br>23:00:09  <br>23:00:09  Finished running 1 unit test in 0 hours 0 minutes and 0.32 seconds (0.32s).<br>23:00:10  <br>23:00:10  Completed with 1 error and 0 warnings:<br>23:00:10  <br>23:00:10  Failure in unit_test when_no_city_is_mapped_city_should_be_other (models/solve_any_data_analysis_problem_ch2/addresses_silver_unit_test.yml)<br>23:00:10    <br>actual differs from expected:<br>@@,company_id,address                 ,total_spend,city<br>→ ,id1       ,&quot;ADDR1,<br>CITY1, COUNTRY&quot; ,1          ,CITY1→OTHER<br>  ,id2       ,&quot;ADDR2, <br>CITY2, COUNTRY&quot;,2          ,OTHER<br>23:00:10  <br>23:00:10    compiled code at target/compiled/spike_postgres/models/solve_any_data_analysis_problem_ch2/addresses_silver_unit_test.yml/models/solve_any_data_analysis_problem_ch2/when_no_city_is_mapped_city_should_be_other.sql<br>23:00:10  <br>23:00:10  Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1</pre><h3>Resources:</h3><ul><li>Learn more about dbt <a href="https://docs.getdbt.com/docs/introduction">in the docs</a></li><li>Check out <a href="https://discourse.getdbt.com/">Discourse</a> for commonly asked questions and answers</li><li>Join the <a href="https://community.getdbt.com/">chat</a> on Slack for live discussions and support</li><li>Find <a href="https://events.getdbt.com/">dbt events</a> near you</li><li>Check out <a href="https://blog.getdbt.com/">the blog</a> for the latest news on dbt’s development and best practices</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa8216350462" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with DBT]]></title>
            <link>https://medium.com/@prule70/getting-started-with-dbt-65e49eccd4c3?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/65e49eccd4c3</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-build-tool]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 02:11:39 GMT</pubDate>
            <atom:updated>2024-08-28T02:11:39.128Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using DBT with Postgres to do some simple data transformation</h4><h4>Introduction</h4><p>In this <a href="https://github.com/prule/dbt-spike/tree/main">project</a>, I’ll be taking my first steps with <a href="https://www.getdbt.com/">DBT</a>. I’ll be following the use case from <a href="https://github.com/davidasboth/solve-any-data-analysis-problem/blob/main/chapter-2/Chapter%202%20example%20solution.ipynb">Solve any data analysis problem, Chapter 2</a> as I did <a href="https://open.substack.com/pub/paulr70/p/data-processing-experiment-part-17?r=3ieyr&amp;utm_campaign=post&amp;utm_medium=web">before</a>, but this time I’ll be using DBT.</p><p>DBT allows me to implement data transforms as a collection of SQL scripts which can be easily run in a simple and consistent manner. I’ll use DBT with postgres since that’s an easy starting point for me.</p><blockquote><em>I already have postgres running in a docker container and python 3 installed.</em></blockquote><blockquote><em>python --version Python 3.10.12</em></blockquote><p>To start with, I’ll set up my environment:</p><pre>python -m venv venv<br>source ./venv/bin/activate<br>python -m pip install dbt-core dbt-postgres<br>pip install --upgrade pip</pre><p>This creates a python virtual environment for this project, activates it, and installs DBT with the postgres extension.</p><p>Then I’ll create a new DBT project:</p><pre>(venv) paul@Pauls-MacBook-Air dbt-spike % dbt init<br>02:49:07  Running with dbt=1.8.4<br>Enter a name for your project (letters, digits, underscore): spike_postgres<br>02:49:26<br>Your new dbt project &quot;spike_postgres&quot; was created!<br>For more information on how to configure the profiles.yml file,<br>please consult the dbt documentation here:<br>  https://docs.getdbt.com/docs/configure-your-profile<br>One more thing:<br>  Need help? Don&#39;t hesitate to reach out to us via GitHub issues or on Slack:<br>  https://community.getdbt.com/<br>Happy modeling!<br>02:49:26  Setting up your profile.<br>Which database would you like to use?<br>[1] postgres<br>(Don&#39;t see the one you want? https://docs.getdbt.com/docs/available-adapters)<br>Enter a number: 1<br>host (hostname for the instance): localhost<br>port [5432]:<br>user (dev username): postgres<br>pass (dev password):<br>dbname (default database that dbt will build objects in): postgres<br>schema (default schema that dbt will build objects in): public<br>threads (1 or more) [1]:<br>02:50:05  Profile spike_postgres written to /Users/paul/.dbt/profiles.yml using target&#39;s profile_template.yml and your supplied values. Run &#39;dbt debug&#39; to validate the connection.</pre><p>A new DBT project is created in the directory spike_postgres. These details have been saved in /Users/paul/.dbt/profiles.yml and I can verify the connection with dbt debug:</p><pre>% cd spike_postgres<br>% dbt debug       <br>00:15:02  Running with dbt=1.8.4<br>00:15:02  dbt version: 1.8.4<br>00:15:02  python version: 3.10.12<br>00:15:02  python path: /Users/paul/IdeaProjects/dbt-spike/venv/bin/python<br>00:15:02  os info: macOS-14.5-arm64-arm-64bit<br>00:15:02  Using profiles dir at /Users/paul/.dbt<br>00:15:02  Using profiles.yml file at /Users/paul/.dbt/profiles.yml<br>00:15:02  Using dbt_project.yml file at /Users/paul/IdeaProjects/dbt-spike/spike_postgres/dbt_project.yml<br>00:15:02  adapter type: postgres<br>00:15:02  adapter version: 1.8.2<br>00:15:02  Configuration:<br>00:15:02    profiles.yml file [OK found and valid]<br>00:15:02    dbt_project.yml file [OK found and valid]<br>00:15:02  Required dependencies:<br>00:15:02   - git [OK found]<br>00:15:02  Connection:<br>00:15:02    host: localhost<br>00:15:02    port: 5432<br>00:15:02    user: postgres<br>00:15:02    database: postgres<br>00:15:02    schema: dbt_postgres<br>00:15:02    connect_timeout: 10<br>00:15:02    role: None<br>00:15:02    search_path: None<br>00:15:02    keepalives_idle: 0<br>00:15:02    sslmode: None<br>00:15:02    sslcert: None<br>00:15:02    sslkey: None<br>00:15:02    sslrootcert: None<br>00:15:02    application_name: dbt<br>00:15:02    retries: 1<br>00:15:02  Registered adapter: postgres=1.8.2<br>00:15:02    Connection test: [OK connection ok]<br>00:15:02  All checks passed!</pre><p>The project is initialised with some example ‘models’ in spike_postgres/models/examples/ and I can use dbt run to check these work okay:</p><pre>% dbt run<br>01:42:36  Running with dbt=1.8.4<br>01:42:36  Registered adapter: postgres=1.8.2<br>01:42:36  Unable to do partial parsing because saved manifest not found. Starting full parse.<br>01:42:37  Found 2 models, 4 data tests, 417 macros<br>01:42:37<br>01:42:37  Concurrency: 1 threads (target=&#39;dev&#39;)<br>01:42:37<br>01:42:37  1 of 2 START sql table model public.my_first_dbt_model ......................... [RUN]<br>01:42:37  1 of 2 OK created sql table model public.my_first_dbt_model .................... [SELECT 2 in 0.09s]<br>01:42:37  2 of 2 START sql view model public.my_second_dbt_model ......................... [RUN]<br>01:42:37  2 of 2 OK created sql view model public.my_second_dbt_model .................... [CREATE VIEW in 0.04s]<br>01:42:37<br>01:42:37  Finished running 1 table model, 1 view model in 0 hours 0 minutes and 0.40 seconds (0.40s).<br>01:42:37<br>01:42:37  Completed successfully<br>01:42:37<br>01:42:37  Done. PASS=2 WARN=0 ERROR=0 SKIP=0 TOTAL=2</pre><p>First I need my raw data in postgres tables:</p><pre># download data from github<br>../run data:download<br># load CSV files into postgres tables<br>../run data:load</pre><p>See <a href="https://github.com/prule/dbt-spike/blob/main/run">run</a> for details on how this is done. Now my raw data exists in postgres tables addresses and cities in a schema called dbt_postgres.</p><p>I’ll delete the examples models and create new models:</p><pre>models<br>└── solve_any_data_analysis_problem_ch2<br>    ├── addresses_bronze.sql<br>    ├── addresses_silver.sql<br>    ├── cities_bronze.sql<br>    ├── cities_silver.sql<br>    ├── schema.yml<br>    └── spend_by_city_gold.sql</pre><p>I’ve followed a bronze/silver/gold approach to modelling — perhaps a little unnecessary here but it illustrates how it works:</p><ul><li><a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/cities_bronze.sql">cities_bronze.sql</a> simply selects everything from the raw table</li></ul><pre>{{ config(schema=&#39;bronze&#39;)}}<br>select * from dbt_postgres.&quot;cities&quot;</pre><p>This produces a view in the dbt_postgres_bronze schema called cities_bronze</p><ul><li><a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/addresses_bronze.sql">addresses_bronze.sql</a> simply selects everything from the raw table</li></ul><pre>{{ config(schema=&#39;bronze&#39;)}}<br>select * from dbt_postgres.&quot;addresses&quot;</pre><p>This produces a view in the dbt_postgres_bronze schema called addresses_bronze</p><p>The silver models do some cleaning and transformation:</p><ul><li><a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/cities_silver.sql">cities_silver.sql</a></li></ul><pre>{{ config(schema=&#39;silver&#39;)}}<br>-- trim and uppercase city<br>-- remove &#39;*&#39;<br>-- remove rows where city is empty<br>-- remove rows where city is in specified list<br>SELECT<br>    distinct trim(upper(<br>        replace(city, &#39;*&#39;, &#39;&#39;)<br>    )) as city<br>FROM {{ ref(&#39;cities_bronze&#39;) }}<br>where city is not null<br>and not city in (&#39;England&#39;, &#39;Scotland&#39;, &#39;Wales&#39;, &#39;Northern Ireland&#39;)</pre><p>This produces a view in the dbt_postgres_silver schema called cities_silver</p><ul><li><a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/addresses_silver.sql">addresses_silver.sql</a></li></ul><pre>{{ config(schema=&#39;silver&#39;)}}<br>-- upper case address<br>-- cast total_spend to decimal<br>-- match the address to a city from the cities table<br>-- remove rows with no address<br>-- use OTHER when no match for city<br>SELECT<br>    company_id,<br>    upper(address) as address,<br>    cast (total_spend as decimal) AS total_spend,<br>    coalesce(<br>        (select city from {{ ref(&#39;cities_silver&#39;) }} where UPPER(address) like &#39;%&#39;||chr(10)||city||&#39;,%&#39; order by city desc limit 1),<br>         &#39;OTHER&#39;<br>    ) as city<br>FROM {{ ref(&#39;addresses_bronze&#39;) }}<br>where address is not null</pre><p>This produces a view in the dbt_postgres_silver schema called addresses_silver</p><p>And finally in gold, we have the aggregated data which can be used to answer the business question.</p><ul><li><a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/spend_by_city_gold.sql">spend_by_city_gold.sql</a></li></ul><pre>{{ config(schema=&#39;gold&#39;)}}<br>select city, sum(total_spend) from {{ ref(&#39;addresses_silver&#39;) }} group by city</pre><p>this produces a view in the dbt_postgres_gold schema called spend_by_city_gold</p><p>After executing dbt run the database now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/0*yawb_BYWxgwGnER_.png" /></figure><pre>% dbt run<br>06:41:53  Running with dbt=1.8.4<br>06:41:53  Registered adapter: postgres=1.8.2<br>06:41:53  Unable to do partial parsing because a project config has changed<br>06:41:54  Found 5 models, 5 data tests, 417 macros<br>06:41:54  <br>06:41:54  Concurrency: 1 threads (target=&#39;dev&#39;)<br>06:41:54  <br>06:41:54  1 of 5 START sql view model dbt_postgres_bronze.addresses_bronze ............... [RUN]<br>06:41:54  1 of 5 OK created sql view model dbt_postgres_bronze.addresses_bronze .......... [CREATE VIEW in 0.08s]<br>06:41:54  2 of 5 START sql view model dbt_postgres_bronze.cities_bronze .................. [RUN]<br>06:41:54  2 of 5 OK created sql view model dbt_postgres_bronze.cities_bronze ............. [CREATE VIEW in 0.03s]<br>06:41:54  3 of 5 START sql view model dbt_postgres_silver.cities_silver .................. [RUN]<br>06:41:54  3 of 5 OK created sql view model dbt_postgres_silver.cities_silver ............. [CREATE VIEW in 0.03s]<br>06:41:54  4 of 5 START sql view model dbt_postgres_silver.addresses_silver ............... [RUN]<br>06:41:54  4 of 5 OK created sql view model dbt_postgres_silver.addresses_silver .......... [CREATE VIEW in 0.03s]<br>06:41:54  5 of 5 START sql view model dbt_postgres_gold.spend_by_city_gold ............... [RUN]<br>06:41:54  5 of 5 OK created sql view model dbt_postgres_gold.spend_by_city_gold .......... [CREATE VIEW in 0.03s]<br>06:41:54  <br>06:41:54  Finished running 5 view models in 0 hours 0 minutes and 0.42 seconds (0.42s).<br>06:41:55  <br>06:41:55  Completed successfully<br>06:41:55  <br>06:41:55  Done. PASS=5 WARN=0 ERROR=0 SKIP=0 TOTAL=5</pre><p>Now, I know the raw data has quality problems, since those are addressed in the cleaning and transforming in the silver models. So I don’t necessarily want to validate the bronze models at the moment, but I do want to validate the silver models so I know I’ve done the cleaning properly.</p><p>I’ve added <a href="https://github.com/prule/dbt-spike/blob/main/spike_postgres/models/solve_any_data_analysis_problem_ch2/schema.yml">schema.yml</a> and added a few column level checks — this is also where I can add some documentation.</p><p>For example:</p><pre>models:<br>  - name: addresses_silver<br>    description: &quot;addresses&quot;<br>    columns:<br>      - name: company_id<br>        description: &quot;Company&quot;<br>        data_tests:<br>          - not_null</pre><p>Run the tests with dbt test:</p><pre>% dbt test<br>07:28:00  Running with dbt=1.8.4<br>07:28:00  Registered adapter: postgres=1.8.2<br>07:28:00  Found 5 models, 6 data tests, 417 macros<br>07:28:00  <br>07:28:00  Concurrency: 1 threads (target=&#39;dev&#39;)<br>07:28:00  <br>07:28:00  1 of 6 START test not_null_addresses_silver_address ............................ [RUN]<br>07:28:00  1 of 6 PASS not_null_addresses_silver_address .................................. [PASS in 0.09s]<br>07:28:00  2 of 6 START test not_null_addresses_silver_city ............................... [RUN]<br>07:28:06  2 of 6 PASS not_null_addresses_silver_city ..................................... [PASS in 5.20s]<br>07:28:06  3 of 6 START test not_null_addresses_silver_company_id ......................... [RUN]<br>07:28:06  3 of 6 PASS not_null_addresses_silver_company_id ............................... [PASS in 0.03s]<br>07:28:06  4 of 6 START test not_null_addresses_silver_total_spend ........................ [RUN]<br>07:28:06  4 of 6 PASS not_null_addresses_silver_total_spend .............................. [PASS in 0.03s]<br>07:28:06  5 of 6 START test not_null_cities_silver_city .................................. [RUN]<br>07:28:06  5 of 6 PASS not_null_cities_silver_city ........................................ [PASS in 0.02s]<br>07:28:06  6 of 6 START test unique_cities_silver_city .................................... [RUN]<br>07:28:06  6 of 6 FAIL 1 unique_cities_silver_city ........................................ [FAIL 1 in 0.02s]<br>07:28:06  <br>07:28:06  Finished running 6 data tests in 0 hours 0 minutes and 5.59 seconds (5.59s).<br>07:28:06  <br>07:28:06  Completed with 1 error and 0 warnings:<br>07:28:06  <br>07:28:06  Failure in test unique_cities_silver_city (models/solve_any_data_analysis_problem_ch2/schema.yml)<br>07:28:06    Got 1 result, configured to fail if != 0<br>07:28:06  <br>07:28:06    compiled code at target/compiled/spike_postgres/models/solve_any_data_analysis_problem_ch2/schema.yml/unique_cities_silver_city.sql<br>07:28:06  <br>07:28:06  Done. PASS=5 WARN=0 ERROR=1 SKIP=0 TOTAL=6</pre><p>We see that the unique test for the city column in the cities_silver view failed. This is good, because I can now fix that in the cities_silver.sql model.</p><p>After fixing that, and doing a dbt run to recreate the views, a dbt test now passes.</p><pre>% dbt test<br>07:30:11  Running with dbt=1.8.4<br>07:30:11  Registered adapter: postgres=1.8.2<br>07:30:11  Found 5 models, 6 data tests, 417 macros<br>07:30:11  <br>07:30:11  Concurrency: 1 threads (target=&#39;dev&#39;)<br>07:30:11  <br>07:30:11  1 of 6 START test not_null_addresses_silver_address ............................ [RUN]<br>07:30:11  1 of 6 PASS not_null_addresses_silver_address .................................. [PASS in 0.09s]<br>07:30:11  2 of 6 START test not_null_addresses_silver_city ............................... [RUN]<br>07:30:16  2 of 6 PASS not_null_addresses_silver_city ..................................... [PASS in 5.21s]<br>07:30:16  3 of 6 START test not_null_addresses_silver_company_id ......................... [RUN]<br>07:30:16  3 of 6 PASS not_null_addresses_silver_company_id ............................... [PASS in 0.03s]<br>07:30:16  4 of 6 START test not_null_addresses_silver_total_spend ........................ [RUN]<br>07:30:16  4 of 6 PASS not_null_addresses_silver_total_spend .............................. [PASS in 0.03s]<br>07:30:16  5 of 6 START test not_null_cities_silver_city .................................. [RUN]<br>07:30:16  5 of 6 PASS not_null_cities_silver_city ........................................ [PASS in 0.02s]<br>07:30:16  6 of 6 START test unique_cities_silver_city .................................... [RUN]<br>07:30:16  6 of 6 PASS unique_cities_silver_city .......................................... [PASS in 0.02s]<br>07:30:16  <br>07:30:16  Finished running 6 data tests in 0 hours 0 minutes and 5.55 seconds (5.55s).<br>07:30:16  <br>07:30:16  Completed successfully<br>07:30:16  <br>07:30:16  Done. PASS=6 WARN=0 ERROR=0 SKIP=0 TOTAL=6</pre><p>And now to check the results against the reference implementation:</p><pre>select sum(SUM) from dbt_postgres_gold.spend_by_city_gold ;<br>-- expected 490374100<br>-- actual   490374100<br>select sum(SUM) from dbt_postgres_gold.spend_by_city_gold where city in (&#39;LONDON&#39;);<br>-- EXPECTED 103042800<br>-- ACTUAL   103042800<br>select sum(SUM) from dbt_postgres_gold.spend_by_city_gold where city not in (&#39;LONDON&#39;);<br>-- expected 387331300<br>-- actual   387331300<br>select sum(SUM) from dbt_postgres_gold.spend_by_city_gold where city not in (&#39;LONDON&#39;,&#39;OTHER&#39;)<br>-- expected 119468400<br>-- actual   118044200</pre><p>There is a small discrepancy in the last number which warrants looking into in more detail — but there’s still a lot more to do, and that’s enough for today’s post.</p><h3>Resources:</h3><ul><li>Learn more about dbt <a href="https://docs.getdbt.com/docs/introduction">in the docs</a></li><li>Check out <a href="https://discourse.getdbt.com/">Discourse</a> for commonly asked questions and answers</li><li>Join the <a href="https://community.getdbt.com/">chat</a> on Slack for live discussions and support</li><li>Find <a href="https://events.getdbt.com/">dbt events</a> near you</li><li>Check out <a href="https://blog.getdbt.com/">the blog</a> for the latest news on dbt’s development and best practices</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65e49eccd4c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Experimenting with Deequ data validation]]></title>
            <link>https://medium.com/@prule70/experimenting-with-deequ-data-validation-7ef468cf3fcb?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ef468cf3fcb</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[deequ]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 02:01:49 GMT</pubDate>
            <atom:updated>2024-08-27T02:01:49.748Z</atom:updated>
            <content:encoded><![CDATA[<h4>Setting up a simple project so that I can exercise deequ and investigate its potential</h4><blockquote>The source code for this article is available at <a href="https://github.com/prule/deequ-spike">github</a>.</blockquote><p>From the <a href="https://github.com/awslabs/deequ">Deequ</a> repository:</p><ul><li>Deequ is a library built on top of Apache Spark for defining “unit tests for data”, which measure data quality in large datasets.</li><li>Most applications that work with data have implicit assumptions about that data, e.g., that attributes have certain types, do not contain NULL values, and so on. If these assumptions are violated, your application might crash or produce wrong outputs. <strong><em>The idea behind deequ is to explicitly state these assumptions in the form of a “unit-test” for data, which can be verified on a piece of data at hand.</em></strong></li></ul><p>In my new <a href="https://github.com/prule/deequ-spike">repository</a> is an experiment to set up a main Kotlin module where the application will reside, and a Scala library where the Deequ/Spark code will reside. Since Deequ and Spark are Scala first it might make it easier to use Scala for these parts.</p><p>See</p><ul><li><a href="https://github.com/prule/deequ-spike/blob/main/app/src/main/kotlin/org/example/App.kt">./app/src/main/kotlin/org/example/App.kt</a></li><li><a href="https://github.com/prule/deequ-spike/blob/main/lib/src/main/scala/org/example/Spike1.scala">./lib/src/main/scala/org/example/Spike1.scala</a></li></ul><pre>├── app (kotlin - calls the library)<br>│   ├── build.gradle.kts<br>│   └── src<br>│       ├── main<br>│       │   ├── kotlin<br>│       │       └── org<br>│       │           └── example<br>│       │               └── App.kt<br>├── lib (scala - invokes deequ)<br>│   ├── build.gradle.kts<br>│   └── src<br>│       ├── main<br>│       │   └── scala<br>│       │       └── org<br>│       │           └── example<br>│       │               └── Spike1.scala</pre><p>The main dependencies are:</p><pre>\--- com.amazon.deequ:deequ:2.0.7-spark-3.5<br>     +--- org.scala-lang:scala-library:2.12.10 -&gt; 2.12.18<br>     +--- org.apache.spark:spark-core_2.12:3.5.0</pre><p>To run the application use</p><pre>./gradlew clean app:run</pre><p>When it starts it will print out the important versions:</p><pre>% ./gradlew clean app:run</pre><pre>&gt; Task :app:run</pre><pre>----------------------------------------------<br>Java version: 21.0.3<br>Kotlin version: 2.0.0<br>Scala version: version 2.12.18<br>----------------------------------------------<br>...<br>24/07/09 22:16:16 INFO SparkContext: Running Spark version 3.5.0<br>24/07/09 22:16:16 INFO SparkContext: OS info Mac OS X, 14.5, aarch64</pre><p>Running the application will execute the Scala Deequ code. Here, I’m using one of the <a href="https://github.com/awslabs/deequ/blob/master/src/main/scala/com/amazon/deequ/examples/KLLCheckExample.scala">examples</a> provided in the Deequ repository as a basis for a starting point.</p><p>With verification rules which are satisfied by the data:</p><pre>val verificationResult = VerificationSuite()<br>  .onData(newData)<br>  .addCheck(<br>    Check(CheckLevel.Error, &quot;integrity checks&quot;)<br>      // we expect 5 records<br>      .hasSize(_ == 6)<br>      // we expect the maximum of tips to be not more than 10<br>      .hasMax(&quot;numViews&quot;, _ &lt;= 8)<br>      // we expect the sketch size to be at least 16<br>      .kllSketchSatisfies(&quot;numViews&quot;, _.parameters(1) &gt;= 16,<br>        kllParameters = Option(KLLParameters(2, 0.64, 2)))<br>  )<br>  .run()</pre><p>we will see success:</p><pre>The data passed the test, everything is fine!</pre><p>If we change the verification so the data violates the rules:</p><pre>val verificationResult = VerificationSuite()<br>    .onData(newData)<br>    .addCheck(<br>      Check(CheckLevel.Error, &quot;integrity checks&quot;)<br>        // we expect 5 records<br>        .hasSize(_ == 6)<br>        // we expect the maximum of tips to be not more than 10<br>        .hasMax(&quot;numViews&quot;, _ &lt;= 9)<br>    ).run()</pre><p>We’ll see corresponding output:</p><pre>We found errors in the data, the following constraints were not satisfied:<br>SizeConstraint(Size(None)) failed: Value: 5 does not meet the constraint requirement!<br>MaximumConstraint(Maximum(numViews,None,None)) failed: Value: 10.0 does not meet the constraint requirement!</pre><p>How we handle the verification results is up to us:</p><pre>if (verificationResult.status == CheckStatus.Success) {<br>    println(&quot;The data passed the test, everything is fine!&quot;)<br>  } else {<br>    println(&quot;We found errors in the data, the following constraints were not satisfied:\n&quot;)<br>    val resultsForAllConstraints = verificationResult.checkResults<br>      .flatMap { case (_, checkResult) =&gt; checkResult.constraintResults }<br>    resultsForAllConstraints<br>      .filter {<br>        _.status != ConstraintStatus.Success<br>      }<br>      .foreach { result =&gt;<br>        println(s&quot;${result.constraint} failed: ${result.message.get}&quot;)<br>      }<br>  }</pre><p>The Deequ code can then be experimented with in order to see how it works. See <a href="https://github.com/awslabs/deequ/tree/master/src/main/scala/com/amazon/deequ/examples">https://github.com/awslabs/deequ/tree/master/src/main/scala/com/amazon/deequ/examples</a> for more examples.</p><p>Notes:</p><ul><li>Spark and Scala dependencies are inherited from Deequ.</li><li>I see an error in the logs which don’t seem to harm anything but needs looking into</li></ul><pre>Caused by: org.codehaus.commons.compiler.CompileException: File &#39;generated.java&#39;, Line 102, Column 1: failed to compile: org.codehaus.commons.compiler.CompileException: File &#39;generated.java&#39;, <br>Line 102, Column 1: Expression &quot;isNull_6&quot; is not an rvalue</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ef468cf3fcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A code pattern for Datadog logging]]></title>
            <link>https://medium.com/@prule70/a-code-pattern-for-datadog-logging-082e7446a5a6?source=rss-d2d60539e44d------2</link>
            <guid isPermaLink="false">https://medium.com/p/082e7446a5a6</guid>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[datadog]]></category>
            <dc:creator><![CDATA[PRULE70]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 01:57:32 GMT</pubDate>
            <atom:updated>2024-08-26T01:57:32.086Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple pattern to help reduce the risk of accidentally breaking external dependencies</h4><p>DataDog is a great tool for monitoring your services. By <a href="https://docs.datadoghq.com/agent/?tab=Linux">deploying your application with an agent</a> your logs can be published to Datadog — after which you can view, search and monitor your logs through the Datadog web application.</p><p>The first thing to do is <a href="https://docs.datadoghq.com/logs/log_collection/java/?tab=log4j">get your application logging in JSON format</a>. This is needed so any <strong>multi-line</strong> log statements are recognised as one event, not many events (stack traces etc)</p><p>Once the agent is configured and running, you’ll be able to see your logs in Datadog — similar to the screen shot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BP0r8OObRoDfu1iN.png" /></figure><p>When configured correctly, Datadog will be able to parse the log entries so you can filter and search by host, environment, service, log level (error, warn, info etc), <a href="https://www.baeldung.com/mdc-in-log4j-2-logback">MDC variables</a> etc.</p><blockquote><em>If you aren’t using the logging MDC in your application yet, it’s worth looking into — you can provide contextual information to all of the log messages in a thread easily — the simplest example might be that you can add a user identifier to the MDC in your REST controller so that all log statements for the duration of that request contain the user id. Add any other contextual information that helps improve the monitoring your application.</em></blockquote><p>You can also set up <a href="https://docs.datadoghq.com/monitors/types/log/">monitors based on log entries</a> — and then notifications based off these monitors — so for example you could receive a slack notification when the count of errors in your application exceeds a threshold.</p><p>In some cases monitors will be set up based on the content of a log message. Let’s say we have some code that looks like this:</p><pre>// something something<br>logger.warn(&quot;I&#39;m Givin&#39; Her All She&#39;s Got, Captain!&quot;)<br>// something something</pre><p>Now we can set up a monitor to count log occurrences containing `I’m Givin’ Her All She’s Got` and we can then configure it to send a slack message if it exceeds a threshold…</p><p>But what happens if someone comes along and makes a change to that message — without realising that an external monitor is using that exact phrase? (maybe they don’t like your <a href="https://www.mentalfloss.com/article/50607/origins-11-famous-star-trek-lines#">Star Trek references</a>…)</p><p>We could add a comment to warn them:</p><pre>// something something<br>// this is used by a Datadog monitor, please don&#39;t change<br>// &lt;link to monitor goes here&gt;<br>logger.warn(&quot;I&#39;m Givin&#39; Her All She&#39;s Got, Captain!&quot;)<br>// something something</pre><p>But we can probably do better than that. One problem is that we can’t easily/reliably find occurrences of this across the code base — “Find Usages” is one of the best IDE capabilities for navigating code bases and it would be nice to be able to use it in this use case.</p><p>In order to make it more robust, we could introduce CODES instead of arbitrary strings — there would never be a reason to change a code, so we can set it and forget it, and use it (and only the code) in the monitor definition.</p><p>And what better way to define a code than an enum?</p><pre>enum class LogEvent(val description: String) {<br>    LE001(&quot;I&#39;m Givin&#39; Her All She&#39;s Got&quot;),<br>    LE002(&quot;Live Long and Prosper&quot;),<br>    LE003(&quot;Make It So&quot;);</pre><pre>    override fun toString(): String {<br>        return &quot;$name/$description: &quot;<br>    }<br>}</pre><p>In this case I’ve given the enum a description so the log message can be self contained — you don’t need to go look up the enum to find out what the code means.</p><p>Now it can be used as follows:</p><pre>logger.warn { &quot;${LogEvent.LE001} and any other information goes here&quot; }</pre><p>This will result in a log entry that looks something like (depends on your logger configuration)</p><pre>14:55:54.172 [main] WARN  c.e.d.app.LoggerExample MDC= - LE001/I&#39;m Givin&#39; Her All She&#39;s Got:  and any other information goes here</pre><p>And the monitor in Datadog can now reference “LE001” — a code that should never change.</p><blockquote><em>It’s at this point that the code becomes slightly more self-describing — people working with this codebase can now look at the LogEvent enum to see what significant events might occur, and use “Find Usages” to navigate to those places.</em></blockquote><p>There is one more thing that we might consider — if someone were to change the logging level for a package in the logger configuration, they might risk turning off these log messages — the logger used in the above example is the logger associated with the class that wants to emit the log statement!</p><p>A simple change can reduce this risk — we can define a central class that is responsible for emitting these log messages, and update the logging configuration with a commented statement to set the logging level for this class:</p><pre>object LogMgr {<br>    private val logger = KotlinLogging.logger {}<br><br>    fun log(event: LogEvent, msg: () -&gt; kotlin.Any?) {<br>        logger.info { &quot;$event - ${msg()}&quot; }<br>    }<br>}</pre><p>We can use it like this:</p><pre>LogMgr.log(LogEvent.LE001) { &quot;and any other information goes here ${LocalDateTime.now()}&quot; }</pre><p>And in the logging configuration we can ensure LogMgr is enabled:</p><pre>&lt;!-- <br>LogMgr is used to emit logs that are referenced by external systems eg log monitoring and notification. <br>Do not disable this class.<br>--&gt;<br>&lt;logger name=&quot;com.example.dataprocessingexperiment.app.LogMgr&quot; level=&quot;TRACE&quot; /&gt;</pre><p>Summary</p><ul><li>Important messages are enumerated in LogEvent</li><li>Calls to log important messages used by external systems are centralised into LogMgr</li><li>IDE “Find usages” allows us to find where these important events happen</li><li>This somewhat increases the “self-documenting” aspect of the system</li><li>Chance of unknowingly breaking monitoring is slightly reduced.</li></ul><p>What do you think? Does it improve the codebase or just convolute it unnecessarily?</p><blockquote><em>Note: Datadog monitors can be defined via Terraform and allows you to implement </em><strong><em>monitoring as code </em></strong><em>— beside the obvious benefits, this has the added bonus of being able to search your codebase for the logging code (eg “LE001”) to find where it is used — eg it will expose the monitor configuration easily.</em></blockquote><blockquote><em>Datadog only gives you a short free trial to try the product out. It’d be great if you could just use it free with small quotas, but no — So unfortunately it’s not useful for small side projects. There are other options — one I know of is </em><a href="https://www.papertrail.com/"><em>Papertrail</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=082e7446a5a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>