Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion admin-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ val microutilsLoggingVersion: String by parent!!.extra
val zaxxerHikaricpVersion: String by parent!!.extra
val postgresSqlVersion: String by parent!!.extra
val testContainersVersion: String by parent!!.extra
val junitJupiterVersion: String by parent!!.extra
val quartzVersion: String by parent!!.extra
val logbackVersion: String by parent!!.extra

Expand Down Expand Up @@ -67,7 +68,7 @@ dependencies {
implementation(project(":admin-metrics"))

testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter:5.5.2")
testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("org.testcontainers:testcontainers:$testContainersVersion")
Expand Down
4 changes: 4 additions & 0 deletions admin-app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ drill {
baseUrl = ${?DRILL_METRICS_UI_BASE_URL}
buildTestingReportPath = "/dashboard/2"
buildTestingReportPath = ${?DRILL_METRICS_UI_BUILD_TESTING_REPORT_PATH }
buildChangesReportPath = "/dashboard/5"
buildChangesReportPath = ${?DRILL_METRICS_UI_BUILD_CHANGES_REPORT_PATH }
impactedTestsReportPath = "/dashboard/13"
impactedTestsReportPath = ${?DRILL_METRICS_UI_IMPACTED_TESTS_REPORT_PATH }
}
}
testRecommendations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ package com.epam.drill.admin.metrics.config

import io.ktor.server.config.*

class MetricsServiceUiLinksConfig(
val baseUrl: String?,
val buildTestingReportPath: String?
) {
constructor(config: ApplicationConfig) : this(
baseUrl = config.propertyOrNull("baseUrl")?.getString(),
buildTestingReportPath = config.propertyOrNull("buildTestingReportPath")?.getString()
)
class MetricsServiceUiLinksConfig(private val config: ApplicationConfig) {

val baseUrl : String?
get() = config.propertyOrNull("baseUrl")?.getString()

val buildTestingReportPath : String?
get() = config.propertyOrNull("buildTestingReportPath")?.getString()

val buildChangesReportPath : String?
get() = config.propertyOrNull("buildChangesReportPath")?.getString()

val impactedTestsReportPath : String?
get() = config.propertyOrNull("impactedTestsReportPath")?.getString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ interface MetricsRepository {

suspend fun getBuildDiffReport(
buildId: String,
baselineBuildId: String
): Map<String, String?>
baselineBuildId: String,
coverageThreshold: Double,
): Map<String, Any?>

suspend fun getRecommendedTests(
targetBuildId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,59 +249,110 @@ class MetricsRepositoryImpl : MetricsRepository {

override suspend fun getBuildDiffReport(
buildId: String,
baselineBuildId: String
) = transaction {
executeQueryReturnMap(
"""
baselineBuildId: String,
coverageThreshold: Double,
): Map<String, Any?> = transaction {
val result = executeQueryReturnMap {
append(
"""
WITH
Changes AS (
SELECT
COUNT(CASE WHEN change_type = 'equal' THEN 1 END) AS equal,
SELECT
COUNT(CASE WHEN change_type = 'modified' THEN 1 END) AS modified,
COUNT(CASE WHEN change_type = 'new' THEN 1 END) AS added,
COUNT(CASE WHEN change_type = 'deleted' THEN 1 END) AS deleted
FROM metrics.get_changes(
input_build_id => ?,
input_baseline_build_id => ?,
include_deleted => true,
include_equal => true
include_deleted => true
) m
),
),
""".trimIndent(), buildId, baselineBuildId
)
append(
"""
TestedChanges AS (
SELECT
change_type,
COUNT(*) AS tested_methods
FROM metrics.get_changes_with_coverage(
input_build_id => ?,
input_baseline_build_id => ?,
input_coverage_test_results => array['PASSED']
)
WHERE aggregated_covered_probes > ?
GROUP BY change_type
),
""".trimIndent(), buildId, baselineBuildId, coverageThreshold
)
append(
"""
Coverage AS (
SELECT
isolated_probes_coverage_ratio,
aggregated_probes_coverage_ratio,
isolated_tested_methods,
isolated_missed_methods,
aggregated_tested_methods,
aggregated_missed_methods
aggregated_probes_coverage_ratio
FROM metrics.get_builds_with_coverage(
input_build_id => ?,
input_baseline_build_id => ?
)
),
RecommendedTests AS (
SELECT count(*) AS tests_to_run
FROM metrics.get_recommended_tests_v2(
input_build_id => ?,
input_test_impact_statuses => '{IMPACTED}'
""".trimIndent(), buildId, baselineBuildId
)
append(
"""
TestLaunches AS (
SELECT
tl.test_definition_id,
MIN(tl.test_result) AS test_result
FROM metrics.test_launches tl
JOIN metrics.test_sessions ts ON ts.test_session_id = tl.test_session_id AND ts.group_id = tl.group_id
JOIN metrics.test_session_builds tsb ON tsb.test_session_id = ts.test_session_id AND tsb.group_id = ts.group_id
WHERE tsb.build_id = ?
AND tl.test_result IN ('PASSED', 'FAILED')
GROUP BY tl.test_definition_id
),
""".trimIndent(), buildId
)
append(
"""
ImpactedTests AS (
SELECT
test_definition_id,
group_id
FROM metrics.get_impacted_tests_v2(
input_build_id => ?,
input_baseline_build_id => ?
)
)
SELECT
),
""".trimIndent(), buildId, baselineBuildId
)
append("""
ImpactedTestsWithResults AS (
SELECT
COUNT(*) AS impacted_tests,
SUM(CASE WHEN test_result = 'PASSED' THEN 1 ELSE 0 END) AS passed_impacted_tests,
SUM(CASE WHEN test_result = 'FAILED' THEN 1 ELSE 0 END) AS failed_impacted_tests
FROM ImpactedTests it
LEFT JOIN TestLaunches tl ON tl.test_definition_id = it.test_definition_id
)
""".trimIndent())
append(
"""
SELECT
(SELECT added FROM Changes) as changes_new_methods,
(SELECT modified FROM Changes) as changes_modified_methods,
(SELECT deleted FROM Changes) as changes_deleted_methods,
(SELECT added + modified FROM Changes) as total_changes,
(SELECT aggregated_tested_methods FROM Coverage) as tested_changes,
(SELECT aggregated_probes_coverage_ratio FROM Coverage) as coverage,
(SELECT tests_to_run FROM RecommendedTests) as recommended_tests
""".trimIndent(),
buildId,
baselineBuildId,
buildId,
baselineBuildId,
buildId
).first() as Map<String, String>
COALESCE((SELECT tested_methods FROM TestedChanges WHERE change_type = 'new'), 0) as tested_new_methods,
COALESCE((SELECT tested_methods FROM TestedChanges WHERE change_type = 'modified'), 0) as tested_modified_methods,
(SELECT isolated_probes_coverage_ratio FROM Coverage) as coverage,
(SELECT aggregated_probes_coverage_ratio FROM Coverage) as aggregated_coverage,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does aggregation also include information from other branches? AFAIR we wanted to exclude that

(SELECT impacted_tests FROM ImpactedTestsWithResults) AS impacted_tests,
(SELECT passed_impacted_tests FROM ImpactedTestsWithResults) AS passed_impacted_tests,
(SELECT failed_impacted_tests FROM ImpactedTestsWithResults) AS failed_impacted_tests
""".trimIndent()
)
}
result.firstOrNull() ?: emptyMap()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Metrics {
val baselineInstanceId: String? = null,
val baselineCommitSha: String? = null,
val baselineBuildVersion: String? = null,
val coverageThreshold: Double = 1.0, // TODO Float should be enough
val coverageThreshold: Double = 0.0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wanted to put that into raw_data.group_settings

)

@Resource("/recommended-tests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ class MetricsServiceImpl(

val metrics = metricsRepository.getBuildDiffReport(
buildId,
baselineBuildId
baselineBuildId,
coverageThreshold
)

val baseUrl = metricsServiceUiLinksConfig.baseUrl
val buildTestingReportPath = metricsServiceUiLinksConfig.buildTestingReportPath
val buildRisksReportPath = metricsServiceUiLinksConfig.buildChangesReportPath
val impactedTestsReportPath = metricsServiceUiLinksConfig.impactedTestsReportPath
mapOf(
"inputParameters" to mapOf(
"groupId" to groupId,
Expand All @@ -226,12 +229,30 @@ class MetricsServiceImpl(
"metrics" to metrics,
"links" to baseUrl?.run {
mapOf(
"changes" to null,
"recommended_tests" to null,
"changes" to buildRisksReportPath?.run {
getUriString(
baseUrl = baseUrl,
path = buildRisksReportPath,
queryParams = mapOf(
"build" to buildId,
"baseline_build" to baselineBuildId,
)
)
},
"impacted_tests" to impactedTestsReportPath?.run {
getUriString(
baseUrl = baseUrl,
path = this,
queryParams = mapOf(
"build" to buildId,
"baseline_build" to baselineBuildId,
)
)
},
"build" to buildTestingReportPath?.run {
getUriString(
baseUrl = baseUrl,
path = buildTestingReportPath,
path = this,
queryParams = mapOf(
"build" to buildId,
)
Expand All @@ -240,7 +261,7 @@ class MetricsServiceImpl(
"baseline_build" to buildTestingReportPath?.run {
getUriString(
baseUrl = baseUrl,
path = buildTestingReportPath,
path = this,
queryParams = mapOf(
"build" to baselineBuildId,
)
Expand All @@ -249,7 +270,7 @@ class MetricsServiceImpl(
"full_report" to buildTestingReportPath?.run {
getUriString(
baseUrl = baseUrl,
path = buildTestingReportPath,
path = this,
queryParams = mapOf(
"build" to buildId,
"baseline_build" to baselineBuildId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ $$ LANGUAGE plpgsql STABLE PARALLEL SAFE;
-- @param input_coverage_branches: Array of branches to filter coverage
-- @param input_coverage_test_tags: Array of test tags to filter coverage
-- @param input_coverage_test_task_ids: Array of test task IDs to filter coverage
-- @param input_coverage_test_results: Array of test results to filter coverage
-- @param input_coverage_period_from: Optional timestamp to filter coverage by creation date
-- @param is_smart_coverage_before_build: Boolean value indicating whether smart coverage should only be considered up to the build date
-- @returns TABLE: A table containing methods with coverage information
Expand All @@ -89,6 +90,7 @@ CREATE OR REPLACE FUNCTION metrics.get_methods_with_coverage(
input_coverage_branches VARCHAR[] DEFAULT NULL,
input_coverage_test_tags VARCHAR[] DEFAULT NULL,
input_coverage_test_task_ids VARCHAR[] DEFAULT NULL,
input_coverage_test_results VARCHAR[] DEFAULT NULL,
input_coverage_period_from TIMESTAMP DEFAULT NULL,

include_smart_coverage BOOLEAN DEFAULT TRUE,
Expand Down Expand Up @@ -145,6 +147,7 @@ BEGIN
AND (input_coverage_app_env_ids IS NULL OR ic.app_env_id = ANY(input_coverage_app_env_ids::VARCHAR[]))
AND (input_coverage_test_task_ids IS NULL OR ic.test_task_id = ANY(input_coverage_test_task_ids::VARCHAR[]))
AND (input_coverage_test_tags IS NULL OR ic.test_tag = ANY(input_coverage_test_tags::VARCHAR[]))
AND (input_coverage_test_results IS NULL OR ic.test_result = ANY(input_coverage_test_results::VARCHAR[]))
AND (input_coverage_period_from IS NULL OR ic.created_at_day >= input_coverage_period_from)
LEFT JOIN metrics.method_daily_coverage sc ON include_smart_coverage IS true AND sc.group_id = bm.group_id AND sc.app_id = bm.app_id AND sc.method_id = bm.method_id
-- Filters by smart coverage
Expand All @@ -153,6 +156,7 @@ BEGIN
AND (input_coverage_app_env_ids IS NULL OR sc.app_env_id = ANY(input_coverage_app_env_ids::VARCHAR[]))
AND (input_coverage_test_task_ids IS NULL OR sc.test_task_id = ANY(input_coverage_test_task_ids::VARCHAR[]))
AND (input_coverage_test_tags IS NULL OR sc.test_tag = ANY(input_coverage_test_tags::VARCHAR[]))
AND (input_coverage_test_results IS NULL OR sc.test_result = ANY(input_coverage_test_results::VARCHAR[]))
AND (input_coverage_period_from IS NULL OR sc.created_at_day >= input_coverage_period_from)
WHERE bm.group_id = _group_id
AND bm.app_id = _app_id
Expand Down Expand Up @@ -420,6 +424,7 @@ $$ LANGUAGE plpgsql STABLE PARALLEL SAFE;
-- @param input_coverage_branches: Array of branches to filter coverage
-- @param input_coverage_test_tags: Array of test tags to filter coverage
-- @param input_coverage_test_task_ids: Array of test task IDs to filter coverage
-- @param input_coverage_test_results: Array of test results to filter coverage
-- @param input_coverage_period_from: Optional timestamp to filter coverage by creation date
-- @param is_smart_coverage_before_build: Boolean value indicating whether smart coverage should only be considered up to the build date
-- @returns TABLE: A table containing changes in methods with coverage information between the two builds
Expand All @@ -437,6 +442,7 @@ CREATE OR REPLACE FUNCTION metrics.get_changes_with_coverage(
input_coverage_branches VARCHAR[] DEFAULT NULL,
input_coverage_test_tags VARCHAR[] DEFAULT NULL,
input_coverage_test_task_ids VARCHAR[] DEFAULT NULL,
input_coverage_test_results VARCHAR[] DEFAULT NULL,
input_coverage_period_from TIMESTAMP DEFAULT NULL,

include_smart_coverage BOOLEAN DEFAULT TRUE,
Expand Down Expand Up @@ -503,6 +509,7 @@ BEGIN
input_coverage_branches => input_coverage_branches,
input_coverage_test_tags => input_coverage_test_tags,
input_coverage_test_task_ids => input_coverage_test_task_ids,
input_coverage_test_results => input_coverage_test_results,
input_coverage_period_from => input_coverage_period_from,

include_smart_coverage => include_smart_coverage,
Expand Down
Loading
Loading