I have a application where it connects to two mutiple databases. One is IBM DB2 and one is Postgres.
In the logs I seen multiple WARN messages that says following:
[otel.javaagent 2024-07-02 14:06:33:077 +0200] [PeriodicMetricReader-1] WARN io.opentelemetry.sdk.metrics.internal.state.AsynchronousMetricStorage - Instrument db.client.connections.idle.min has recorded multiple values for the same attributes: {pool.name="HikariPool-(my-app-name)-DB2"}
My database config for these two databases is:
object DatabaseConfig {
private fun db2HikariConfig(): HikariConfig {
val db2Properties: PropertiesConfig.Db2Properties = PropertiesConfig.Db2Properties()
return HikariConfig().apply {
maximumPoolSize = 10
minimumIdle = 1
poolName = "HikariPool-${PropertiesConfig.Configuration().naisAppName}-DB2"
connectionTestQuery = "select 1 from sysibm.sysdummy1"
dataSource =
DB2SimpleDataSource().apply {
driverType = 4
enableNamedParameterMarkers = DB2BaseDataSource.YES
databaseName = db2Properties.name
serverName = db2Properties.host
portNumber = db2Properties.port.toInt()
currentSchema = db2Properties.schema
connectionTimeout = 1000
commandTimeout = 10000
user = db2Properties.username
setPassword(db2Properties.password)
}
}
}
private fun postgresHikariConfig(): HikariConfig {
val postgresProperties: PropertiesConfig.PostgresProperties = PropertiesConfig.PostgresProperties()
return HikariConfig().apply {
poolName = "HikariPool-${PropertiesConfig.Configuration().naisAppName}-POSTGRES"
maximumPoolSize = 5
minimumIdle = 1
dataSource =
PGSimpleDataSource().apply {
if (PropertiesConfig.isLocal()) {
user = postgresProperties.adminUsername
password = postgresProperties.adminPassword
}
serverNames = arrayOf(postgresProperties.host)
databaseName = postgresProperties.databaseName
portNumbers = intArrayOf(postgresProperties.port.toInt())
connectionTimeout = Duration.ofSeconds(10).toMillis()
maxLifetime = Duration.ofMinutes(30).toMillis()
initializationFailTimeout = Duration.ofMinutes(30).toMillis()
}
}
}
fun db2DataSource(): HikariDataSource = HikariDataSource(db2HikariConfig())
fun postgresDataSource(
hikariConfig: HikariConfig = postgresHikariConfig(),
role: String = PropertiesConfig.PostgresProperties().user,
): HikariDataSource {
return when {
PropertiesConfig.isLocal() -> HikariDataSource(hikariConfig)
else ->
HikariCPVaultUtil.createHikariDataSourceWithVaultIntegration(
hikariConfig,
PropertiesConfig.PostgresProperties().vaultMountPath,
role,
)
}
}
fun postgresMigrate(dataSource: HikariDataSource = postgresDataSource(role = PropertiesConfig.PostgresProperties().adminUser)) {
Flyway.configure()
.dataSource(dataSource)
.initSql("""SET ROLE "${PropertiesConfig.PostgresProperties().adminUser}"""")
.lockRetryCount(-1)
.load()
.migrate()
.migrationsExecuted
logger.info { "Migration finished" }
}
}
How can I fix the WARN message? Its logs like every second. I am using OpenTelemetry agent version 2.5.0.
I have looked at a solution, but it will turn off database monitoring. So maybe not so smart as I want to monitor the connection etc.
https://github.com/open-telemetry/opentelemetry-java-instrumentation/discussions/10440
I removed the poolName
attribute, and it solved the issue.