Explore Talaiot plugin: configure metrics

Svyatoslav Chatchenko
3 min readMar 21, 2020

--

Talaiot is a Plugin written in Kotlin that helps to track the information of the Gradle tasks executed in your project during the build.

Talaiot has notions of metrics (what to measure) and publishers (where to store/publish measurements https://github.com/cdsap/Talaiot/#publishers).

In this article, I will cover two topics:

  • how to customise what is measured
  • how to add additional metrics

Initial setup

For the initial setup, I just follow the readme and use JsonPublisher which stores all measurements in the build/reports/talaiot/data.json file.

Simple Talaiot configuration

After executing /.gradlew tasks data.json contains a lot of information like OS version, Java version, user name, etc.

Generated report

Customise what is measured

Depending on your use-case, you might need to disable some of the metrics. For example, username and gitUser are pretty much the same and you need only one of them. Or you simply might be not interested in some fields. Another example is when you store your measurement in InfluxDB/Prometheus and don’t want to blow up your storage with irrelevant data or fields with high cardinality.

Talaiot implements each measurement as a separate metric like GitUserMetric, UserMetric, OsMetric etc. Metrics are combined into groups: default, git, environment, performance and gradleSwitches. All that information is defined in MetricsConfiguration. By default all five groups are included. Important: default configuration is applied only if there is no customisation. It means that if you do customisation, then you have to specify all metrics that needs to be executed.

In our case, we want to include all metrics from groups default and perfomance and one specific metric GitBranchMetric. Talaiot configuration would look like

Talaiot config with specific metrics

After executing /.gradlew tasks data.json contains much fewer data.

Generated report with subset of metrics

Add custom metrics

Talaiot has a lot of different metrics, but sometimes you are interested to measure something specific to your project. For that you have two mechanisms:

I’ll focus only on the second option because the first one is straightforward and well documented.

Let’s track if the Gradle build was executed from IDE (Android Studio) or command line. As the second custom metric, we will identify the root folder of the project.

I implement custom metrics inside the buildSrc folder, but you can use the composite build for that purpose too. It’s important to add the dependency on the Talaiot plugin.

buildSrc/build.gradle

Custom metric has to implement Metric<T, in Context> and has to define provider and assigner function. provider is a function that performs the calculation and assigner is a function that assigns the value to the ExecutionReport. There are several predefined base metrics like GradleMetric, GradlePropertyMetric, CmdMetric, JvmArgsMetric etc. In our case we will extend GradleMetric which defines that provider function receives Gradle project as aninput.

AndroidStudioMetric will look like

Detect if build was executed from the IDE

I know that IDE adds android.injected.invoked.from.ide property to the build. Our metric simply checks if this property is present.

And ProjectFolderMetric will look like

Identify project folder

It’s even simpler. We just retrieve root directory of the project.

The final step is to adjust the Talaiot configuration

Talaiot config with new metrics

After executing ./gradlew tasks data.json contains two new fields under customProperties.buildProperties.

Generated report with custom metrics

Source code

Source code can be found https://github.com/MyDogTom/ConfigureTalaiot

Each step was added as a separate commit:

--

--