Skip to content

Commit

Permalink
fix(81): Fix bug report #90 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarari authored Jan 15, 2023
1 parent c5c43c5 commit 3fb11ea
Show file tree
Hide file tree
Showing 112 changed files with 469 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package io.github.janbarari.gradle.analytics.data

import io.github.janbarari.gradle.analytics.database.Database
import io.github.janbarari.gradle.analytics.database.DatabaseResultMigrationPipeline
import io.github.janbarari.gradle.analytics.database.ResetAutoIncremental
import io.github.janbarari.gradle.analytics.database.table.MetricTable
import io.github.janbarari.gradle.analytics.database.table.SingleMetricTable
Expand Down Expand Up @@ -50,7 +51,8 @@ class DatabaseRepositoryImp(
private val branch: String,
private val requestedTasks: String,
private val buildMetricJsonAdapter: BuildMetricJsonAdapter,
private val temporaryMetricsMemoryCache: MemoryCache<List<BuildMetric>>
private val temporaryMetricsMemoryCache: MemoryCache<List<BuildMetric>>,
private val databaseResultMigrationPipeline: DatabaseResultMigrationPipeline
) : DatabaseRepository {

companion object {
Expand Down Expand Up @@ -95,8 +97,13 @@ class DatabaseRepositoryImp(
(MetricTable.branch eq branch) and
(MetricTable.requestedTasks eq requestedTasks)
}.single()

val buildMetric = databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(queryResult[MetricTable.value])!!
)

return@transaction Pair(
buildMetricJsonAdapter.fromJson(queryResult[MetricTable.value])!!, queryResult[MetricTable.number]
buildMetric, queryResult[MetricTable.number]
)
}
}
Expand Down Expand Up @@ -127,7 +134,9 @@ class DatabaseRepositoryImp(
(MetricTable.requestedTasks eq requestedTasks)
}.orderBy(MetricTable.number, SortOrder.ASC).forEach {
result.add(
buildMetricJsonAdapter.fromJson(it[MetricTable.value])!!
databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(it[MetricTable.value])!!
)
)
}
return@transaction result
Expand Down Expand Up @@ -212,9 +221,10 @@ class DatabaseRepositoryImp(
(TemporaryMetricTable.requestedTasks eq requestedTasks)
}
queryResult.toList().forEach {
buildMetricJsonAdapter.fromJson(it[value])?.let { metric ->
metrics.add(metric)
}
val metric = databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(it[value])!!
)
metrics.add(metric)
}
temporaryMetricsMemoryCache.write(metrics)
return@transaction metrics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* MIT License
* Copyright (c) 2022 Mehdi Janbarari (@janbarari)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.janbarari.gradle.analytics.data

import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.extension.whenEach

/**
* **v1.0.0-beta6 Database Result Migration State**
*
* The migration stage supports the older versions till mentioned version.
*/
class V100B6DatabaseResultMigrationStage(
private val modules: Set<String>
): Stage<BuildMetric, BuildMetric> {

override fun process(input: BuildMetric): BuildMetric {
// Assign the current available modules when modules are empty in old JSON.
if (input.modules.isEmpty()) {
input.modules = modules
}

// `averageDuration` and `averageParallelDuration` are deprecated, replace their value into
// `medianExecInMillis` and `medianParallelExecInMillis`.
input.modulesExecutionProcessMetric?.modules?.whenEach {
medianExecInMillis = averageDuration
medianParallelExecInMillis = averageParallelDuration
}

return input
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* MIT License
* Copyright (c) 2022 Mehdi Janbarari (@janbarari)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.janbarari.gradle.analytics.database

import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Pipeline
import io.github.janbarari.gradle.core.Stage

class DatabaseResultMigrationPipeline(firstStage: Stage<BuildMetric, BuildMetric>):
Pipeline<BuildMetric, BuildMetric>(firstStage)
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ data class BuildMetric(
var createdAt: Long,

@Json(name = "git_head_commit_hash")
var gitHeadCommitHash: String,
var gitHeadCommitHash: String = "Unset",

@Json(name = "modules")
var modules: List<String>,
var modules: Set<String> = emptySet(),

@Json(name = "initialization_process_metric")
var initializationProcessMetric: InitializationProcessMetric? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ data class ModuleExecutionProcess(
@Json(name = "path")
val path: String,
@Json(name = "median")
val medianExecInMillis: Long,
var medianExecInMillis: Long = 0L,
@Json(name = "median_parallel")
val medianParallelExecInMillis: Long,
var medianParallelExecInMillis: Long = 0L,
@Json(name = "parallel_rate")
val parallelRate: Float,
@Json(name = "coverage")
val coverageRate: Float
val coverageRate: Float,

@Deprecated("`averageDuration` deprecated in version `1.0.0-beta4`, replaced with `medianExecInMillis`")
@Json(name = "average_duration")
val averageDuration: Long = 0L,
@Deprecated("`averageParallelDuration` deprecated in version `1.0.0-beta4`, " +
"replaced with `medianParallelExecInMillis`")
@Json(name = "average_parallel_duration")
val averageParallelDuration: Long = 0L
) : java.io.Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ data class ModulesDependencyGraphReport(
@Json(name = "dependencies")
var dependencies: List<ModuleDependency>,
@Json(name = "modules")
var modules: List<String>
var modules: Set<String>
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
package io.github.janbarari.gradle.analytics.domain.usecase

import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Pipeline
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendPipeline
import io.github.janbarari.gradle.core.SuspendStage

class UpdateMetricPipeline(firstStage: Stage<BuildMetric, BuildMetric>): Pipeline<BuildMetric, BuildMetric>(firstStage)
class UpdateMetricPipeline(firstStage: SuspendStage<BuildMetric, BuildMetric>):
SuspendPipeline<BuildMetric, BuildMetric>(firstStage)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package io.github.janbarari.gradle.analytics.metric.buildstatus.report
import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.analytics.domain.model.report.BuildStatusReport
import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.isNotNull
import io.github.janbarari.gradle.extension.millisToSeconds
import io.github.janbarari.gradle.logger.Tower
Expand All @@ -34,7 +34,7 @@ import io.github.janbarari.gradle.utils.MathUtils
class CreateBuildStatusReportStage(
private val tower: Tower,
private val metrics: List<BuildMetric>
) : Stage<Report, Report> {
) : SuspendStage<Report, Report> {

companion object {
private val clazz = CreateBuildStatusReportStage::class.java
Expand Down Expand Up @@ -152,5 +152,4 @@ class CreateBuildStatusReportStage(
}
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package io.github.janbarari.gradle.analytics.metric.buildstatus.report

import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.isNull
import io.github.janbarari.gradle.extension.round
import io.github.janbarari.gradle.extension.whenNotNull
Expand All @@ -34,7 +34,7 @@ import io.github.janbarari.gradle.utils.HtmlUtils
class RenderBuildStatusReportStage(
private val tower: Tower,
private val report: Report
): Stage<String, String> {
): SuspendStage<String, String> {

companion object {
private const val BUILD_STATUS_METRIC_TEMPLATE_ID = "%build-status-metric%"
Expand Down Expand Up @@ -82,7 +82,4 @@ class RenderBuildStatusReportStage(
}
return renderedTemplate
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ package io.github.janbarari.gradle.analytics.metric.cachehit.create

import io.github.janbarari.gradle.analytics.domain.model.BuildInfo
import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage

class CreateCacheHitMetricStage(
private val buildInfo: BuildInfo,
private val createCacheHitMetricUseCase: CreateCacheHitMetricUseCase
): Stage<BuildMetric, BuildMetric> {
): SuspendStage<BuildMetric, BuildMetric> {

override suspend fun process(input: BuildMetric): BuildMetric {
return input.apply {
Expand All @@ -38,5 +38,4 @@ class CreateCacheHitMetricStage(
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import io.github.janbarari.gradle.analytics.domain.model.report.CacheHitReport
import io.github.janbarari.gradle.analytics.domain.model.report.ModuleCacheHit
import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.analytics.domain.model.TimespanPoint
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.diffPercentageOf
import io.github.janbarari.gradle.extension.hasMultipleItems
import io.github.janbarari.gradle.extension.hasSingleItem
Expand All @@ -39,7 +39,7 @@ import io.github.janbarari.gradle.logger.Tower
class CreateCacheHitReportStage(
private val tower: Tower,
private val metrics: List<BuildMetric>
) : Stage<Report, Report> {
) : SuspendStage<Report, Report> {

companion object {
private val clazz = CreateCacheHitReportStage::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package io.github.janbarari.gradle.analytics.metric.cachehit.report

import io.github.janbarari.gradle.analytics.domain.model.report.ModuleCacheHit
import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.isNull
import io.github.janbarari.gradle.extension.mapToChartPoints
import io.github.janbarari.gradle.extension.toArrayRender
Expand All @@ -36,7 +36,7 @@ import io.github.janbarari.gradle.utils.HtmlUtils
class RenderCacheHitReportStage(
private val tower: Tower,
private val report: Report
) : Stage<String, String> {
) : SuspendStage<String, String> {

companion object {
private const val CACHE_HIT_METRIC_TEMPLATE_ID = "%cache-hit-metric%"
Expand Down Expand Up @@ -160,5 +160,4 @@ class RenderCacheHitReportStage(
.mapToChartPoints()
.map { it.description }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
package io.github.janbarari.gradle.analytics.metric.cachehit.update

import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage

class UpdateCacheHitMetricStage(
private val updateCacheHitMetricUseCase: UpdateCacheHitMetricUseCase
): Stage<BuildMetric, BuildMetric> {
): SuspendStage<BuildMetric, BuildMetric> {

override suspend fun process(input: BuildMetric): BuildMetric {
return input.apply {
cacheHitMetric = updateCacheHitMetricUseCase.execute()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ package io.github.janbarari.gradle.analytics.metric.configurationprocess.create

import io.github.janbarari.gradle.analytics.domain.model.BuildInfo
import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage

class CreateConfigurationProcessMetricStage(
private val buildInfo: BuildInfo,
private val createConfigurationProcessMetricUseCase: CreateConfigurationProcessMetricUseCase
): Stage<BuildMetric, BuildMetric> {
): SuspendStage<BuildMetric, BuildMetric> {

override suspend fun process(input: BuildMetric): BuildMetric {
return input.apply {
Expand All @@ -38,5 +38,4 @@ class CreateConfigurationProcessMetricStage(
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package io.github.janbarari.gradle.analytics.metric.configurationprocess.report
import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.analytics.domain.model.report.ConfigurationProcessReport
import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.isBiggerEquals
import io.github.janbarari.gradle.extension.isNotNull
import io.github.janbarari.gradle.extension.mapToConfigurationMeanTimespanChartPoints
Expand All @@ -36,7 +36,7 @@ import io.github.janbarari.gradle.logger.Tower
class CreateConfigurationProcessReportStage(
private val tower: Tower,
private val metrics: List<BuildMetric>
) : Stage<Report, Report> {
) : SuspendStage<Report, Report> {

companion object {
private const val SKIP_THRESHOLD_IN_MS = 50L
Expand Down Expand Up @@ -68,5 +68,4 @@ class CreateConfigurationProcessReportStage(
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package io.github.janbarari.gradle.analytics.metric.configurationprocess.report

import io.github.janbarari.gradle.analytics.domain.model.report.Report
import io.github.janbarari.gradle.core.Stage
import io.github.janbarari.gradle.core.SuspendStage
import io.github.janbarari.gradle.extension.isNull
import io.github.janbarari.gradle.extension.mapToChartPoints
import io.github.janbarari.gradle.extension.maxValue
Expand All @@ -42,7 +42,7 @@ import io.github.janbarari.gradle.utils.MathUtils
class RenderConfigurationProcessReportStage(
private val tower: Tower,
private val report: Report
) : Stage<String, String> {
) : SuspendStage<String, String> {

companion object {
private const val CHART_MAX_COLUMNS = 12
Expand Down Expand Up @@ -102,5 +102,4 @@ class RenderConfigurationProcessReportStage(
fun getEmptyRender(): String {
return HtmlUtils.renderMessage("Configuration Process is not available!")
}

}
Loading

0 comments on commit 3fb11ea

Please sign in to comment.