-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added metrics * added logger in in-memory-metrics * removed decrement and added attributes * Apply spotless formatting * Update examples/src/main/kotlin/com/xebia/functional/xef/assistants/DSL.kt Co-authored-by: Francisco Diaz <[email protected]> --------- Co-authored-by: José Carlos Montañez <[email protected]> Co-authored-by: Montagon <[email protected]> Co-authored-by: Francisco Diaz <[email protected]>
- Loading branch information
1 parent
46a4d4f
commit 220981e
Showing
10 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/CounterMetric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.xebia.functional.xef.metrics | ||
|
||
interface CounterMetric { | ||
fun increment(n: Long) | ||
|
||
fun increment(n: Long, attributes: Map<String, String>) | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/commonMain/kotlin/com/xebia/functional/xef/metrics/InMemoryCounterMetric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.xebia.functional.xef.metrics | ||
|
||
import arrow.atomic.AtomicLong | ||
import io.github.oshai.kotlinlogging.KLogger | ||
|
||
class InMemoryCounterMetric(val name: String, val logger: KLogger) : CounterMetric { | ||
private val count = AtomicLong(0) | ||
|
||
override fun increment(n: Long) { | ||
count.incrementAndGet() | ||
logger.info { "Counter $name incremented to ${count.get()}" } | ||
} | ||
|
||
override fun increment(n: Long, attributes: Map<String, String>) { | ||
count.addAndGet(n) | ||
logger.info { | ||
"Counter $name incremented to ${count.get()} with those attributes: ${attributes.entries.joinToString( ",")}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
...ntelemetry/src/main/kotlin/com/xebia/functional/xef/opentelemetry/OpenTelemetryCounter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.xebia.functional.xef.opentelemetry | ||
|
||
import com.xebia.functional.xef.metrics.CounterMetric | ||
import io.opentelemetry.api.common.Attributes | ||
|
||
class OpenTelemetryCounter(private val longCounter: io.opentelemetry.api.metrics.LongCounter) : | ||
CounterMetric { | ||
override fun increment(n: Long) { | ||
longCounter.add(n) | ||
} | ||
|
||
override fun increment(n: Long, attributes: Map<String, String>) { | ||
val attributesBuilder = Attributes.builder() | ||
attributes.forEach { (k, v) -> attributesBuilder.put(k, v) } | ||
longCounter.add(n, attributesBuilder.build()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters