janbarari / gradle-analytics-plugin

A free Gradle plugin to analyze your project builds. It provides unique visual and text metrics in HTML format.
MIT License
158 stars 5 forks source link

Hard to adopt - example usage? #113

Closed zachgrayio closed 1 year ago

zachgrayio commented 1 year ago

Hi there,

A real project serving as more realistic example usage for the plugin might be helpful; I've spent a few hours trying to get some data out of the plugin and so far getting nothing written into either MySQL or sqlite, and nothing out of the report task. Is there another task or something I should be running perhaps that's not covered in docs? 🤔

I've been running on a mixture of popular open source projects all using gradle 7.x so I wouldn't think the upcoming gradle changes that seem to break all of these plugins has impacted this one in my case, but perhaps the project's I'm working on aren't supported somehow?

I've tested this with DuckDuckGo and PocketCasts Android so far and in both cases nothing is written to the database. In the case of pocketcasts I even went to the lengths of running a gradle tasks --all and adding all the tasks into the trackingTasks list (which should a wildcard like * or have a trackAllTasks=true property all probably?) to ensure I wasn't just missing tasks, but still no data is generated.

What might I be doing wrong here? is it something that might have been avoided with more examples, or are these projects really just not supported?

TY!

janbarari commented 1 year ago

Hi @zachgrayio,

I appreciate you sharing your experience with me. I wanted to let you know that I'm planning to create a video tutorial on how to set up and use the plugin in its simplest form. Initially, I held off on creating this video because the plugin was still undergoing development and I needed to conduct some testing. However, now that the metrics have been finalized, I believe it's the right time to make this video! Thank you for your support and I hope this tutorial will be helpful to you and others.

janbarari commented 1 year ago

The plugin is compatible with the latest version of Gradle, which as of now is v8.0.2. Could you please share the configuration for the plugin?

zachgrayio commented 1 year ago

The plugin is compatible with the latest version of Gradle, which as of now is v8.0.2. Could you please share the configuration for the plugin?

sure it was basically verbatim from the docs with a few bugfixes (the groovy version has kotlin syntax in it with the is/has bool accessor prefixes)

Here's the applied onto pocketcasts-android tag 7.34:

➜  pocket-casts-android git:(d079274b) ✗ git status
HEAD detached at 7.34
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   build.gradle

and the config:

diff --git build.gradle build.gradle
index 842d6941..d14a15e1 100644
--- build.gradle
+++ build.gradle
@@ -44,6 +44,7 @@ plugins {
     id 'com.github.ben-manes.versions' version '0.42.0'
     id 'com.diffplug.spotless' version '6.2.2'
     id 'io.sentry.android.gradle' version '3.1.5' apply false
+    id 'io.github.janbarari.gradle-analytics-plugin' version '1.0.0-beta8'
 }

 apply plugin: 'base'
@@ -87,3 +88,36 @@ allprojects {
     }
 }

+gradleAnalyticsPlugin {
+    enabled = true // Optional: By default it's True.
+
+    database {
+        local = sqlite {
+            path = System.getenv('DATABASE_PATH')
+            name = System.getenv('DATABASE_NAME') // Don't add `.db` in the database name.
+        }
+        ci = sqlite {
+            path = System.getenv('DATABASE_PATH')
+            name = System.getenv('DATABASE_NAME') // Don't add `.db` in the database name.
+        }
+    }
+
+    trackingTasks = [
+        // redacted - I tried last with ~9000 lines of targets, the output of `gradle tasks --all` wrapped
+        // in quotes and comma delimited since with standard targets like `assembleDebug` etc, nothing was tracked
+    ]
+
+    trackingBranches = [
+        // requested tasks only analyzed in the branches you add here, Example:
+        'master',
+        'develop'
+    ]
+
+    // Optional: Exclude modules that are not necessary like test or demo modules
+    excludeModules = []
+
+    trackAllBranchesEnabled = true // Optional: Default is False.
+
+    outputPath = System.getenv('OUTPUT_REPORT_PATH') + '/pocketcasts' // Optional: Default is project /build/ dir.
+}
+

roughly the same config with mysql had the same result, nothing written to DB and an output message saying there was no data to process.

and the build script is basically:

#!/usr/bin/env bash

set -a
source .env
set +a

export DATABASE_NAME=pocketcasts
./gradlew --version
./gradlew clean assembleDebug
./gradlew reportAnalytics --branch="$(git rev-parse --abbrev-ref HEAD)" --period="5m" --task="assembleDebug"
./gradlew --stop

and .env roughly

DATABASE_PATH=/tmp/gradledb
OUTPUT_REPORT_PATH=/tmp/gradledb/report
janbarari commented 1 year ago

There is a mistake, you ran clean assembleDebug but you want the assembleDebug report. You can get the report of task clean assembleDebug. Try --task="clean assembleDebug".

janbarari commented 1 year ago

make sure you put clean assembleDebug in the plugin tracking tasks config like below:

trackingTasks = [
    'clean assembleDebug'
]
zachgrayio commented 1 year ago

Oh, interesting! so its more of a "target" field than tasks. OK I'll give this another look, TY, this is very helpful

zachgrayio commented 1 year ago

actually i am running into this exact same problem again after moving a few scripts around but I do have the command identical this time, something else must have changed and broke the matching. i see the db is growing in size now but I cant get reports rendered. what else can I check?

janbarari commented 1 year ago

Hello, @zachgrayio. Could you please send me an email at mehdi.janbarari@outlook.com? Once you do, I'll be able to catch up with you and show you how to do it(via google meet). Thank you!

zachgrayio commented 1 year ago

I ended up solving the latest issue---the --branch=$(git rev-parse --abbrev-ref HEAD) value I was setting was getting evaluated strangely and causing misses, hard coding that to HEAD ended up solving it.

Ideally though maybe we can relax those matching requirements with some config settings