remove metrics collection
This commit is contained in:
43
README.md
43
README.md
@@ -4,31 +4,24 @@ Classes and endpoints, to shape and to steer, Devices and sensors, their purpose
|
|||||||
|
|
||||||
## Properties for deployment
|
## Properties for deployment
|
||||||
|
|
||||||
| name | required | info |
|
| name | required | info |
|
||||||
|----------------------------------------------|:--------:|----------------------------------------------|
|
|-------------------------------|:--------:|------------------------------|
|
||||||
| spring.profiles.active | ✓ | Spring Boot environment |
|
| spring.profiles.active | ✓ | Spring Boot environment |
|
||||||
| server.port | ✓ | HTTP port |
|
| server.port | ✓ | HTTP port |
|
||||||
| server.ssl.enabled | ✓ | HTTP Enable SSL |
|
| server.ssl.enabled | ✓ | HTTP Enable SSL |
|
||||||
| server.ssl.key-store | ✓ | HTTP Keystore |
|
| server.ssl.key-store | ✓ | HTTP Keystore |
|
||||||
| server.ssl.key-store-type | ✓ | HTTP Cert Type |
|
| server.ssl.key-store-type | ✓ | HTTP Cert Type |
|
||||||
| server.ssl.key-store-password | ✗ | HTTP Cert Pass |
|
| server.ssl.key-store-password | ✗ | HTTP Cert Pass |
|
||||||
| spring.cache.type | | Cache type (redis) |
|
| spring.cache.type | | Cache type (redis) |
|
||||||
| spring.data.redis.host | ✓ | Redis host |
|
| spring.data.redis.host | ✓ | Redis host |
|
||||||
| spring.data.redis.port | | Redis port |
|
| spring.data.redis.port | | Redis port |
|
||||||
| spring.data.redis.database | ✓ | Redis database |
|
| spring.data.redis.database | ✓ | Redis database |
|
||||||
| spring.data.redis.password | ✗ | Redis password |
|
| spring.data.redis.password | ✗ | Redis password |
|
||||||
| cache.time-to-live | | Cache time to live (minutes) |
|
| cache.time-to-live | | Cache time to live (minutes) |
|
||||||
| jwt.public-key | ✓ | JWT public key |
|
| jwt.public-key | ✓ | JWT public key |
|
||||||
| device-registry.url | ✓ | Device Register URL |
|
| device-registry.url | ✓ | Device Register URL |
|
||||||
| device-data.url | ✓ | Device Data URL |
|
| device-data.url | ✓ | Device Data URL |
|
||||||
| device-configuration.url | ✓ | Device Configuration URL |
|
| device-configuration.url | ✓ | Device Configuration URL |
|
||||||
| management.influx.metrics.export.api-version | | InfluxDB API version |
|
|
||||||
| management.influx.metrics.export.enabled | | Enable/Disable exporting metrics to InfluxDB |
|
|
||||||
| management.influx.metrics.export.bucket | ✓ | InfluxDB bucket name |
|
|
||||||
| management.influx.metrics.export.org | ✓ | InfluxDB organization |
|
|
||||||
| management.influx.metrics.export.token | ✗ | InfluxDB token |
|
|
||||||
| management.influx.metrics.export.uri | ✓ | InfluxDB URL |
|
|
||||||
| management.metrics.tags.application | ✓ | Application instance tag for metrics |
|
|
||||||
|
|
||||||
*Required: ✓ can be stored as text, and ✗ need to be stored as secret.*
|
*Required: ✓ can be stored as text, and ✗ need to be stored as secret.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(hlaeja.plugins.kotlin.jvm)
|
alias(hlaeja.plugins.kotlin.jvm)
|
||||||
alias(hlaeja.plugins.kotlin.spring)
|
alias(hlaeja.plugins.kotlin.spring)
|
||||||
@@ -15,7 +13,6 @@ dependencies {
|
|||||||
implementation(hlaeja.kotlin.logging)
|
implementation(hlaeja.kotlin.logging)
|
||||||
implementation(hlaeja.kotlin.reflect)
|
implementation(hlaeja.kotlin.reflect)
|
||||||
implementation(hlaeja.kotlinx.coroutines)
|
implementation(hlaeja.kotlinx.coroutines)
|
||||||
implementation(hlaeja.micrometer.registry.influx)
|
|
||||||
implementation(hlaeja.library.common.messages)
|
implementation(hlaeja.library.common.messages)
|
||||||
implementation(hlaeja.library.jwt)
|
implementation(hlaeja.library.jwt)
|
||||||
implementation(hlaeja.springboot.starter.actuator)
|
implementation(hlaeja.springboot.starter.actuator)
|
||||||
@@ -34,17 +31,6 @@ dependencies {
|
|||||||
|
|
||||||
group = "ltd.hlaeja"
|
group = "ltd.hlaeja"
|
||||||
|
|
||||||
fun influxDbToken(): String = config.findOrDefault("influxdb.token", "INFLUXDB_TOKEN", "")
|
tasks.named("processResources") {
|
||||||
|
dependsOn("copyCertificates")
|
||||||
tasks {
|
|
||||||
named("containerCreate", DockerCreateContainer::class) {
|
|
||||||
withEnvVar("MANAGEMENT_INFLUX_METRICS_EXPORT_TOKEN", influxDbToken())
|
|
||||||
}
|
|
||||||
withType<ProcessResources> {
|
|
||||||
filesMatching("**/application.yml") { filter { it.replace("%INFLUXDB_TOKEN%", influxDbToken()) } }
|
|
||||||
onlyIf { file("src/main/resources/application.yml").exists() }
|
|
||||||
}
|
|
||||||
named("processResources") {
|
|
||||||
dependsOn("copyCertificates")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ltd.hlaeja.service
|
package ltd.hlaeja.service
|
||||||
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.micrometer.core.instrument.Counter
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.library.deviceConfiguration.Node
|
import ltd.hlaeja.library.deviceConfiguration.Node
|
||||||
import ltd.hlaeja.property.DeviceConfigurationProperty
|
import ltd.hlaeja.property.DeviceConfigurationProperty
|
||||||
@@ -18,29 +16,17 @@ private val log = KotlinLogging.logger {}
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
class DeviceConfigurationService(
|
class DeviceConfigurationService(
|
||||||
meterRegistry: MeterRegistry,
|
|
||||||
private val webClient: WebClient,
|
private val webClient: WebClient,
|
||||||
private val deviceConfigurationProperty: DeviceConfigurationProperty,
|
private val deviceConfigurationProperty: DeviceConfigurationProperty,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val deviceConfigurationSuccess = Counter.builder("device.configuration.success")
|
|
||||||
.description("Number of successful device configuration calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
private val deviceConfigurationFailure = Counter.builder("device.configuration.failure")
|
|
||||||
.description("Number of failed device configuration calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
suspend fun getConfiguration(
|
suspend fun getConfiguration(
|
||||||
node: UUID,
|
node: UUID,
|
||||||
): Node.Response = try {
|
): Node.Response = try {
|
||||||
webClient.deviceConfigurationGetConfiguration(node, deviceConfigurationProperty)
|
webClient.deviceConfigurationGetConfiguration(node, deviceConfigurationProperty)
|
||||||
.also { deviceConfigurationSuccess.increment() }
|
|
||||||
} catch (e: ErrorResponseException) {
|
} catch (e: ErrorResponseException) {
|
||||||
deviceConfigurationFailure.increment()
|
|
||||||
throw e
|
throw e
|
||||||
} catch (e: WebClientRequestException) {
|
} catch (e: WebClientRequestException) {
|
||||||
deviceConfigurationFailure.increment()
|
|
||||||
log.error(e) { "Error device registry" }
|
log.error(e) { "Error device registry" }
|
||||||
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ltd.hlaeja.service
|
package ltd.hlaeja.service
|
||||||
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.micrometer.core.instrument.Counter
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.library.deviceData.MeasurementData
|
import ltd.hlaeja.library.deviceData.MeasurementData
|
||||||
import ltd.hlaeja.property.DeviceDataProperty
|
import ltd.hlaeja.property.DeviceDataProperty
|
||||||
@@ -20,30 +18,18 @@ private val log = KotlinLogging.logger {}
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
class DeviceDataService(
|
class DeviceDataService(
|
||||||
meterRegistry: MeterRegistry,
|
|
||||||
private val webClient: WebClient,
|
private val webClient: WebClient,
|
||||||
private val deviceDataProperty: DeviceDataProperty,
|
private val deviceDataProperty: DeviceDataProperty,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val deviceDataSuccess = Counter.builder("device.data.success")
|
|
||||||
.description("Number of successful device data calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
private val deviceDataFailure = Counter.builder("device.data.failure")
|
|
||||||
.description("Number of failed device data calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
suspend fun getMeasurement(
|
suspend fun getMeasurement(
|
||||||
client: UUID,
|
client: UUID,
|
||||||
node: UUID,
|
node: UUID,
|
||||||
): MeasurementData.Response = try {
|
): MeasurementData.Response = try {
|
||||||
webClient.deviceDataGetMeasurement(client, node, deviceDataProperty)
|
webClient.deviceDataGetMeasurement(client, node, deviceDataProperty)
|
||||||
.also { deviceDataSuccess.increment() }
|
|
||||||
} catch (e: ErrorResponseException) {
|
} catch (e: ErrorResponseException) {
|
||||||
deviceDataFailure.increment()
|
|
||||||
throw e
|
throw e
|
||||||
} catch (e: WebClientRequestException) {
|
} catch (e: WebClientRequestException) {
|
||||||
deviceDataFailure.increment()
|
|
||||||
log.error(e) { "Error device registry" }
|
log.error(e) { "Error device registry" }
|
||||||
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
@@ -53,12 +39,9 @@ class DeviceDataService(
|
|||||||
request: MeasurementData.Request,
|
request: MeasurementData.Request,
|
||||||
): ResponseEntity<Void> = try {
|
): ResponseEntity<Void> = try {
|
||||||
webClient.deviceDataAddMeasurement(client, request, deviceDataProperty)
|
webClient.deviceDataAddMeasurement(client, request, deviceDataProperty)
|
||||||
.also { deviceDataSuccess.increment() }
|
|
||||||
} catch (e: ErrorResponseException) {
|
} catch (e: ErrorResponseException) {
|
||||||
deviceDataFailure.increment()
|
|
||||||
throw e
|
throw e
|
||||||
} catch (e: WebClientRequestException) {
|
} catch (e: WebClientRequestException) {
|
||||||
deviceDataFailure.increment()
|
|
||||||
log.error(e) { "Error device registry" }
|
log.error(e) { "Error device registry" }
|
||||||
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ltd.hlaeja.service
|
package ltd.hlaeja.service
|
||||||
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.micrometer.core.instrument.Counter
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.library.deviceRegistry.Identity
|
import ltd.hlaeja.library.deviceRegistry.Identity
|
||||||
import ltd.hlaeja.property.DeviceRegistryProperty
|
import ltd.hlaeja.property.DeviceRegistryProperty
|
||||||
@@ -19,30 +17,18 @@ private val log = KotlinLogging.logger {}
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
class DeviceRegistryService(
|
class DeviceRegistryService(
|
||||||
meterRegistry: MeterRegistry,
|
|
||||||
private val webClient: WebClient,
|
private val webClient: WebClient,
|
||||||
private val deviceRegistryProperty: DeviceRegistryProperty,
|
private val deviceRegistryProperty: DeviceRegistryProperty,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val identityDeviceSuccess = Counter.builder("device.identity.success")
|
|
||||||
.description("Number of successful device identity calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
private val identityDeviceFailure = Counter.builder("device.identity.failure")
|
|
||||||
.description("Number of failed device identity calls")
|
|
||||||
.register(meterRegistry)
|
|
||||||
|
|
||||||
@Cacheable(value = ["identity"], key = "#device")
|
@Cacheable(value = ["identity"], key = "#device")
|
||||||
suspend fun getIdentityFromDevice(
|
suspend fun getIdentityFromDevice(
|
||||||
device: UUID,
|
device: UUID,
|
||||||
): Identity.Response = try {
|
): Identity.Response = try {
|
||||||
webClient.deviceRegistryIdentityDevice(device, deviceRegistryProperty)
|
webClient.deviceRegistryIdentityDevice(device, deviceRegistryProperty)
|
||||||
.also { identityDeviceSuccess.increment() }
|
|
||||||
} catch (e: ErrorResponseException) {
|
} catch (e: ErrorResponseException) {
|
||||||
identityDeviceFailure.increment()
|
|
||||||
throw e
|
throw e
|
||||||
} catch (e: WebClientRequestException) {
|
} catch (e: WebClientRequestException) {
|
||||||
identityDeviceFailure.increment()
|
|
||||||
log.error(e) { "Error device identity" }
|
log.error(e) { "Error device identity" }
|
||||||
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
throw ResponseStatusException(SERVICE_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ management:
|
|||||||
access: read_only
|
access: read_only
|
||||||
info:
|
info:
|
||||||
access: read_only
|
access: read_only
|
||||||
influx:
|
|
||||||
metrics:
|
|
||||||
export:
|
|
||||||
api-version: v2
|
|
||||||
bucket: hlaeja
|
|
||||||
org: hlaeja_ltd
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
time-to-live: 10
|
time-to-live: 10
|
||||||
@@ -54,16 +48,6 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
host: localhost
|
host: localhost
|
||||||
|
|
||||||
management:
|
|
||||||
metrics:
|
|
||||||
tags:
|
|
||||||
application: device-api
|
|
||||||
influx:
|
|
||||||
metrics:
|
|
||||||
export:
|
|
||||||
enabled: false
|
|
||||||
token: %INFLUXDB_TOKEN%
|
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 8443
|
port: 8443
|
||||||
ssl:
|
ssl:
|
||||||
@@ -93,15 +77,6 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
host: Redis
|
host: Redis
|
||||||
|
|
||||||
management:
|
|
||||||
metrics:
|
|
||||||
tags:
|
|
||||||
application: device-api
|
|
||||||
influx:
|
|
||||||
metrics:
|
|
||||||
export:
|
|
||||||
uri: http://InfluxDB:8086
|
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 8443
|
port: 8443
|
||||||
ssl:
|
ssl:
|
||||||
|
|||||||
Reference in New Issue
Block a user