net.nemerosa.ontrack.extension.influxdb.validation.data.InfluxDBValidationRunMetricsExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-extension-influxdb Show documentation
Show all versions of ontrack-extension-influxdb Show documentation
Ontrack module: ontrack-extension-influxdb
package net.nemerosa.ontrack.extension.influxdb.validation.data
import net.nemerosa.ontrack.common.Time
import net.nemerosa.ontrack.extension.api.ValidationRunMetricsExtension
import net.nemerosa.ontrack.extension.influxdb.InfluxDBConnection
import net.nemerosa.ontrack.extension.influxdb.InfluxDBExtensionFeature
import net.nemerosa.ontrack.extension.support.AbstractExtension
import net.nemerosa.ontrack.model.structure.ValidationDataType
import net.nemerosa.ontrack.model.structure.ValidationDataTypeService
import net.nemerosa.ontrack.model.structure.ValidationRun
import net.nemerosa.ontrack.model.structure.ValidationRunData
import org.influxdb.dto.Point
import java.util.concurrent.TimeUnit
class InfluxDBValidationRunMetricsExtension(
influxDBExtensionFeature: InfluxDBExtensionFeature,
private val validationDataTypeService: ValidationDataTypeService,
private val influxDBConnection: InfluxDBConnection
) : AbstractExtension(influxDBExtensionFeature), ValidationRunMetricsExtension {
override fun onValidationRun(validationRun: ValidationRun) {
val validationRunData: ValidationRunData<*>? = validationRun.data
if (validationRunData != null) {
onValidationRunData(validationRun, validationRunData)
}
}
private fun onValidationRunData(
validationRun: ValidationRun,
validationRunData: ValidationRunData
) {
val dataType: ValidationDataType? = validationDataTypeService.getValidationDataType(validationRunData.descriptor.id)
if (dataType != null) {
val metrics: Map? = dataType.getMetrics(validationRunData.data)
if (metrics != null && metrics.isNotEmpty()) {
influxDBConnection.safe {
write(
Point.measurement("ontrack_value_validation_data")
// Tags
.tag("project", validationRun.project.name)
.tag("branch", validationRun.validationStamp.branch.name)
.tag("build", validationRun.build.name)
.tag("validation", validationRun.validationStamp.name)
.tag("status", validationRun.lastStatus.statusID.id)
// Type
.tag("type", validationRunData.descriptor.id)
// Fields
.fields(metrics)
// OK
.time(Time.toEpochMillis(validationRun.signature.time), TimeUnit.MILLISECONDS)
.build()
)
flush()
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy