Skip to content
Closed
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
6 changes: 3 additions & 3 deletions src/main/kotlin/cash/atto/node/NodeMetricProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class NodeMetricProvider(
) {
@PostConstruct
fun start() {
val version = applicationVersion.substringBefore('-').toDoubleOrNull() ?: 0.0
val version = applicationVersion.substringBefore('-')
Gauge
.builder("node.version", this) { version }
.builder("node.version", this) { 1.0 }
.description("Information about the Atto node")
.tags(
listOf(
Expand All @@ -29,7 +29,7 @@ class NodeMetricProvider(
Tag.of("algorithm", thisNode.algorithm.toString()),
Tag.of("address", AttoAddress(thisNode.algorithm, thisNode.publicKey).toString()),
Tag.of("features", thisNode.features.joinToString(", ")),
Tag.of("version", version.toString()),
Tag.of("version", version),
),
).register(meterRegistry)
}
Expand Down
54 changes: 54 additions & 0 deletions src/test/kotlin/cash/atto/node/NodeMetricProviderTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cash.atto.node

import cash.atto.commons.AttoAlgorithm
import cash.atto.commons.AttoNetwork
import cash.atto.commons.AttoPublicKey
import cash.atto.protocol.AttoNode
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import java.net.URI

class NodeMetricProviderTest {
@Test
fun `preserves semantic version in metric tag`() {
// Given
val registry = SimpleMeterRegistry()
val provider = NodeMetricProvider(node(), "7.0.2-SNAPSHOT", registry)

// When
provider.start()

// Then
val gauge = registry.find("node.version").tag("version", "7.0.2").gauge()
assertNotNull(gauge)
assertEquals(1.0, gauge?.value())
}

@Test
fun `preserves local version in metric tag`() {
// Given
val registry = SimpleMeterRegistry()
val provider = NodeMetricProvider(node(), "local", registry)

// When
provider.start()

// Then
val gauge = registry.find("node.version").tag("version", "local").gauge()
assertNotNull(gauge)
assertEquals(1.0, gauge?.value())
}

private fun node(): AttoNode =
mockk {
every { publicUri } returns URI("ws://localhost:8080")
every { network } returns AttoNetwork.LOCAL
every { publicKey } returns AttoPublicKey(ByteArray(32))
every { algorithm } returns AttoAlgorithm.V1
every { features } returns emptySet()
}
}