Skip to content

Commit 2b70da3

Browse files
authored
Process git branch metric only when publish (#411)
* deferring the process metrics to the publisher * removing test value source * Processign Git Branch metrics at the publishing phase * fixing failing tests
1 parent 01acb13 commit 2b70da3

File tree

8 files changed

+69
-30
lines changed

8 files changed

+69
-30
lines changed

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/Talaiot.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.github.cdsap.talaiot.provider.PublisherConfigurationProvider
1313
import io.github.cdsap.talaiot.publisher.TalaiotPublisher
1414
import io.github.cdsap.talaiot.publisher.TalaiotPublisherImpl
1515
import io.github.cdsap.talaiot.util.ConfigurationPhaseObserver
16+
import io.github.cdsap.valuesourceprocess.CommandLineWithOutputValue
1617
import io.github.cdsap.valuesourceprocess.jInfo
1718
import io.github.cdsap.valuesourceprocess.jStat
1819
import org.gradle.api.Project
@@ -63,6 +64,14 @@ class Talaiot<T : TalaiotExtension>(
6364

6465
ConfigurationPhaseObserver.init()
6566

67+
// ValueSources invoked as metrics invalidate the configuration cache when the value changes.
68+
// https://github.com/cdsap/Talaiot/issues/408
69+
// To avoid this issue we need to create the provider that wouldn't be retrieved
70+
// until the publishing phase and if the metric is enabled
71+
val gitBranch = target.providers.of(CommandLineWithOutputValue::class.java) {
72+
it.parameters.commands.set("git rev-parse --abbrev-ref HEAD")
73+
}
74+
6675
val serviceProvider: Provider<TalaiotBuildService> =
6776
target.gradle.sharedServices.registerIfAbsent(
6877
"talaiotService",
@@ -80,6 +89,8 @@ class Talaiot<T : TalaiotExtension>(
8089
spec.parameters.jInfoKotlin = target.jInfo("KotlinCompileDaemon")
8190
spec.parameters.dictionary.set(dictionary)
8291
spec.parameters.processes.set(extension.metrics.processMetrics)
92+
spec.parameters.gitBranchMetric = gitBranch
93+
spec.parameters.processGitBranchMetric.set(extension.metrics.gitMetrics)
8394
}
8495
target.serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(serviceProvider)
8596
}

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/TalaiotBuildService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ abstract class TalaiotBuildService :
5151
var jInfoKotlin: Provider<String>
5252
val dictionary: MapProperty<String, String>
5353
val processes: Property<Boolean>
54+
val processGitBranchMetric: Property<Boolean>
55+
var gitBranchMetric: Provider<String>
5456
}
5557

5658
private val taskLengthList = mutableListOf<TaskLength>()
@@ -80,6 +82,8 @@ abstract class TalaiotBuildService :
8082
}
8183

8284
val processProcessMetrics = parameters.processes.get()
85+
val processGitBranchMetric = parameters.processGitBranchMetric.get()
86+
val gitBranchMetric = if (processGitBranchMetric) parameters.gitBranchMetric.get().replace("\n", "") else ""
8387

8488
parameters.publisher.get().publish(
8589
taskLengthList = taskLengthList,
@@ -96,7 +100,9 @@ abstract class TalaiotBuildService :
96100
kotlinStat = if (processProcessMetrics) parameters.jstatKotlin.get() else "",
97101
gradleInfo = if (processProcessMetrics) parameters.jInfoGradle.get() else "",
98102
gradleStat = if (processProcessMetrics) parameters.jstatGradle.get() else "",
99-
processProcessMetrics = processProcessMetrics
103+
processProcessMetrics = processProcessMetrics,
104+
processGitBranchMetric = processGitBranchMetric,
105+
gitBranchMetric = gitBranchMetric
100106
)
101107
}
102108

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/configuration/MetricsConfiguration.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.github.cdsap.talaiot.configuration
33
import io.github.cdsap.talaiot.entities.ExecutionReport
44
import io.github.cdsap.talaiot.metrics.BuildIdMetric
55
import io.github.cdsap.talaiot.metrics.DefaultCharsetMetric
6-
import io.github.cdsap.talaiot.metrics.GitBranchMetric
76
import io.github.cdsap.talaiot.metrics.GitUserMetric
87
import io.github.cdsap.talaiot.metrics.GradleMaxWorkersMetric
98
import io.github.cdsap.talaiot.metrics.GradleRequestedTasksMetric
@@ -53,7 +52,6 @@ import org.gradle.api.Project
5352
*
5453
* [gitMetrics] includes:
5554
* [GitUserMetric]
56-
* [GitBranchMetric]
5755
*
5856
* [performanceMetrics] includes:
5957
* [UserMetric]
@@ -130,7 +128,6 @@ class MetricsConfiguration {
130128
private fun addGitMetrics(target: Project) {
131129
with(metrics) {
132130
add(GitUserMetric(target))
133-
add(GitBranchMetric(target))
134131
}
135132
}
136133

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/metrics/GitMetrics.kt renamed to library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/metrics/GitUserMetric.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ package io.github.cdsap.talaiot.metrics
33
import io.github.cdsap.valuesourceprocess.CommandLineWithOutputValue
44
import org.gradle.api.Project
55

6-
class GitBranchMetric(val project: Project) : SimpleMetric<String>(
7-
provider = {
8-
project.providers.of(CommandLineWithOutputValue::class.java) {
9-
it.parameters.commands.set("git rev-parse --abbrev-ref HEAD")
10-
}.get().replace("\n", "")
11-
},
12-
assigner = { report, value -> report.environment.gitBranch = value }
13-
)
14-
156
class GitUserMetric(val project: Project) : SimpleMetric<String>(
167
provider = {
178
project.providers.of(CommandLineWithOutputValue::class.java) {

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/publisher/TalaiotPublisher.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ interface TalaiotPublisher : java.io.Serializable {
2020
kotlinStat: String,
2121
gradleInfo: String,
2222
kotlinInfo: String,
23-
processProcessMetrics: Boolean
23+
processProcessMetrics: Boolean,
24+
processGitBranchMetric: Boolean,
25+
gitBranchMetric: String
2426
)
2527
}

library/core/talaiot/src/main/kotlin/io/github/cdsap/talaiot/publisher/TalaiotPublisherImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class TalaiotPublisherImpl(
3838
kotlinStat: String,
3939
gradleInfo: String,
4040
kotlinInfo: String,
41-
processProcessMetrics: Boolean
41+
processProcessMetrics: Boolean,
42+
processGitBranchMetric: Boolean,
43+
gitBranchMetric: String
4244
) {
4345
executionReport.tasks = taskLengthList.filter { taskFilterProcessor.taskLengthFilter(it) }
4446
executionReport.unfilteredTasks = taskLengthList
@@ -61,6 +63,9 @@ class TalaiotPublisherImpl(
6163
GradleProcessMetrics(gradleInfo).get(Unit, executionReport)
6264
KotlinProcessMetrics(kotlinInfo).get(Unit, executionReport)
6365
}
66+
if (processGitBranchMetric) {
67+
executionReport.environment.gitBranch = gitBranchMetric
68+
}
6469
publisherProvider.forEach {
6570
it.publish(executionReport)
6671
}

library/core/talaiot/src/test/kotlin/io/github/cdsap/talaiot/metrics/MetricsConfigurationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ private val environmentMetricsTypes = listOf(
279279
)
280280

281281
private val gitMetricsTypes = listOf(
282-
GitBranchMetric::class,
283282
GitUserMetric::class
284283
)
285284

library/plugins/talaiot-standard/src/test/kotlin/io/github/cdsap/talaiot/TalaiotPublisherImplTest.kt

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
6363
"",
6464
"",
6565
"",
66-
false
66+
false,
67+
false,
68+
""
6769
)
6870
then("outputPublisher is publishing one task result ") {
6971
assert(publishers.get().size == 1)
@@ -108,7 +110,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
108110
"",
109111
"",
110112
"",
111-
false
113+
false,
114+
false,
115+
""
112116
)
113117

114118
then("two publishers are processed ") {
@@ -165,7 +169,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
165169
"",
166170
"",
167171
"",
168-
false
172+
false,
173+
false,
174+
""
169175
)
170176

171177
then("two publishers are processed and one task has been filtered ") {
@@ -224,7 +230,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
224230
"",
225231
"",
226232
"",
227-
false
233+
false,
234+
false,
235+
""
228236
)
229237

230238
then("two publishers are processed and one task has been filtered ") {
@@ -273,7 +281,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
273281
"",
274282
"",
275283
"",
276-
false
284+
false,
285+
false,
286+
""
277287
)
278288

279289
then("successful build is published") {
@@ -317,7 +327,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
317327
"",
318328
"",
319329
"",
320-
false
330+
false,
331+
false,
332+
""
321333
)
322334

323335
then("failed build is not published") {
@@ -361,7 +373,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
361373
"",
362374
"",
363375
"",
364-
false
376+
false,
377+
false,
378+
""
365379
)
366380

367381
then("build with a different task is published") {
@@ -403,7 +417,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
403417
"",
404418
"",
405419
"",
406-
false
420+
false,
421+
false,
422+
""
407423
)
408424
then("no information is published") {
409425
verifyZeroInteractions(publishers.get()[0])
@@ -445,7 +461,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
445461
"",
446462
"",
447463
"",
448-
false
464+
false,
465+
false,
466+
""
449467
)
450468
then("build with a different task is not published") {
451469

@@ -487,7 +505,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
487505
"",
488506
"",
489507
"",
490-
false
508+
false,
509+
false,
510+
""
491511
)
492512
then("build with the same task is published") {
493513
verify(publishers.get()[0]).publish(any())
@@ -531,7 +551,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
531551
"",
532552
"",
533553
"",
534-
false
554+
false,
555+
false,
556+
""
535557
)
536558

537559
then("build with at least one task included is published") {
@@ -576,7 +598,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
576598
"",
577599
"",
578600
"",
579-
false
601+
false,
602+
false,
603+
""
580604
)
581605

582606
then("build with all tasks filtered out is not published") {
@@ -623,7 +647,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
623647
"",
624648
"",
625649
"",
626-
false
650+
false,
651+
false,
652+
""
627653
)
628654
then("should publish cache information for each task") {
629655
val reportCaptor = argumentCaptor<ExecutionReport>()
@@ -691,7 +717,9 @@ class TalaiotPublisherImplTest : BehaviorSpec({
691717
"",
692718
"",
693719
"",
694-
false
720+
false,
721+
false,
722+
""
695723
)
696724

697725
then("duration is the sum of execution and configuration") {

0 commit comments

Comments
 (0)