Skip to content

Commit

Permalink
Reduce the amount of logging by reporting each failed build feature o…
Browse files Browse the repository at this point in the history
…nly with Debug preset. The number of failures is still logged as an error
  • Loading branch information
Sagolbah committed Nov 28, 2023
1 parent c9dcf1a commit af165b8
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import jetbrains.buildServer.notification.slackNotifier.slack.SlackWebApiFactory
import jetbrains.buildServer.serverSide.*
import jetbrains.buildServer.serverSide.executors.ExecutorServices
import jetbrains.buildServer.serverSide.healthStatus.*
import jetbrains.buildServer.serverSide.impl.LogUtil
import jetbrains.buildServer.serverSide.impl.NotificationsBuildFeature
import jetbrains.buildServer.serverSide.oauth.OAuthConnectionsManager
import org.springframework.context.annotation.Conditional
Expand Down Expand Up @@ -68,17 +69,25 @@ class SlackBuildFeatureHealthReport(
}

override fun report(scope: HealthStatusScope, consumer: HealthStatusItemConsumer) {
var errors = 0

for (buildType in scope.buildTypes) {
report(buildType, consumer)
errors += report(buildType, consumer)
}

for (buildTemplate in scope.buildTypeTemplates) {
report(buildTemplate, consumer)
errors += report(buildTemplate, consumer)
}
if (errors != 0) {
logger.error("Could not generate health report for $errors build features" +
" due to error responses from Slack." +
" See notifications log for details. To see all failed features, enable the debug preset.")
}
}

private fun report(buildType: SBuildType, consumer: HealthStatusItemConsumer) {
private fun report(buildType: SBuildType, consumer: HealthStatusItemConsumer): Int {
val features = getFeatures(buildType)
var errorRequests = 0
for (feature in features) {
val statusItem = try {
getHealthStatus(feature, buildType, "buildType")
Expand All @@ -87,17 +96,21 @@ class SlackBuildFeatureHealthReport(
} catch (e: ExecutionException) {
null
} catch (e: SlackResponseError) {
logger.error("Error while generating health report: ${e.message}")
logger.debug("Error while generating health report for feature with id=${feature.id} " +
"in build type with id=${buildType.buildTypeId}: ${e.message}")
errorRequests++
null
}
if (statusItem != null) {
consumer.consumeForBuildType(buildType, statusItem)
}
}
return errorRequests
}

private fun report(buildTemplate: BuildTypeTemplate, consumer: HealthStatusItemConsumer) {
private fun report(buildTemplate: BuildTypeTemplate, consumer: HealthStatusItemConsumer): Int {
val features = getFeatures(buildTemplate)
var errorRequests = 0
for (feature in features) {
val statusItem = try {
getHealthStatus(feature, buildTemplate, "template")
Expand All @@ -106,13 +119,16 @@ class SlackBuildFeatureHealthReport(
} catch (e: ExecutionException) {
null
} catch (e: SlackResponseError) {
logger.error("Error while generating health report: ${e.message}")
logger.debug("Error while generating health report for feature" +
" with id=${feature.id} in template ${LogUtil.describe(buildTemplate)}: ${e.message}")
errorRequests++
null
}
if (statusItem != null) {
consumer.consumeForTemplate(buildTemplate, statusItem)
}
}
return errorRequests
}

private fun getFeatures(buildTypeSettings: BuildTypeSettings): List<SBuildFeatureDescriptor> {
Expand Down

0 comments on commit af165b8

Please sign in to comment.