<commit_before>package net.nemerosa.ontrack.extension.elastic.metrics

import net.nemerosa.ontrack.it.AbstractDSLTestSupport
import net.nemerosa.ontrack.json.asJson
import net.nemerosa.ontrack.json.parse
import net.nemerosa.ontrack.model.structure.RunInfoInput
import net.nemerosa.ontrack.model.structure.RunInfoService
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.TestPropertySource
import kotlin.test.assertEquals

@TestPropertySource(properties = [
    "ontrack.extension.elastic.metrics.enabled=true",
    "ontrack.extension.elastic.metrics.index.immediate=true",
])
class ElasticMetricsRunInfoListenerIT : AbstractDSLTestSupport() {

    @Autowired
    private lateinit var elasticMetricsClient: ElasticMetricsClient

    @Test
    fun `Export of run info for a build`() {
        project {
            branch {
                build {
                    runInfoService.setRunInfo(this, RunInfoInput(
                        runTime = 50,
                    ))
                    // Checks the metric has been exported into ES
                    val results = elasticMetricsClient.rawSearch(
                        token = this.name,
                    )
                    // Expecting only one result
                    assertEquals(1, results.items.size, "One metric registered")
                    val result = results.items.first()
                    val source = result.source.asJson()
                    val ecs = source.parse<ECSEntry>()
                    assertEquals(50_000_000_000L, ecs.event.duration)
                    assertEquals(this.name, ecs.labels?.get("name"))
                    assertEquals(this.project.name, ecs.labels?.get("project"))<commit_msg>#997 Cleanup of run info metrics - correction of tests<commit_after>package net.nemerosa.ontrack.extension.elastic.metrics

import net.nemerosa.ontrack.it.AbstractDSLTestSupport
import net.nemerosa.ontrack.json.asJson
import net.nemerosa.ontrack.json.parse
import net.nemerosa.ontrack.model.structure.RunInfoInput
import net.nemerosa.ontrack.model.structure.RunInfoService
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.TestPropertySource
import kotlin.test.assertEquals

@TestPropertySource(properties = [
    "ontrack.extension.elastic.metrics.enabled=true",
    "ontrack.extension.elastic.metrics.index.immediate=true",
    "management.metrics.export.elastic.enabled=false",
])
class ElasticMetricsRunInfoListenerIT : AbstractDSLTestSupport() {

    @Autowired
    private lateinit var elasticMetricsClient: ElasticMetricsClient

    @Test
    fun `Export of run info for a build`() {
        project {
            branch {
                build {
                    runInfoService.setRunInfo(this, RunInfoInput(
                        runTime = 50,
                    ))
                    // Checks the metric has been exported into ES
                    val results = elasticMetricsClient.rawSearch(
                        token = <PASSWORD>,
                    )
                    // Expecting only one result
                    assertEquals(1, results.items.size, "One metric registered")
                    val result = results.items.first()
                    val source = result.source.asJson()
                    val ecs = source.parse<ECSEntry>()
                    assertEquals(50_000_000_000L, ecs.event.duration)
                    assertEquals(this.name, ecs.labels?.get("name"))
                    assertEquals(this.project.name, ecs.labels?.get("project"))
{'fraction_non_alphanumeric': 0.08708708708708708, 'fraction_numerical': 0.008463008463008462, 'mean_word_length': 2.2802148612354523, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7666547', 'n_tokens_mistral': 988, 'n_tokens_neox': 926, 'n_words': 178}