apache / skywalking

APM, Application Performance Monitoring System
https://skywalking.apache.org/
Apache License 2.0
23.81k stars 6.52k forks source link

[Feature] SkyWalking should check if the database exists first, instead of creating it directly. #7686

Closed buddy-yao closed 2 years ago

buddy-yao commented 3 years ago

Search before asking

Description

I am using InfluxDB as the storage, the InFluxDB is provided by cloud provider, it does't has admin privilege. If SkyWalking try to create database, it will fail. I think, SkyWalking should check if the database exists first, instead of creating it directly.

2021-09-09 19:40:48,227 - org.apache.skywalking.oap.server.starter.OAPServerBootstrap -4223 [main] ERROR [] - error authorizing query: skywalking not authorized to execute statement 'CREATE DATABASE skywa
lking', requires admin privilege
org.influxdb.InfluxDBException: error authorizing query: skywalking not authorized to execute statement 'CREATE DATABASE skywalking', requires admin privilege
        at org.influxdb.InfluxDBException.buildExceptionFromErrorMessage(InfluxDBException.java:161) ~[influxdb-java-2.15.jar:?]
        at org.influxdb.InfluxDBException.buildExceptionForErrorState(InfluxDBException.java:188) ~[influxdb-java-2.15.jar:?]
        at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:806) ~[influxdb-java-2.15.jar:?]
        at org.influxdb.impl.InfluxDBImpl.executeQuery(InfluxDBImpl.java:795) ~[influxdb-java-2.15.jar:?]
        at org.influxdb.impl.InfluxDBImpl.query(InfluxDBImpl.java:552) ~[influxdb-java-2.15.jar:?]
        at org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient.connect(InfluxClient.java:77) ~[storage-influxdb-plugin-8.7.0.jar:8.7.0]
        at org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxStorageProvider.start(InfluxStorageProvider.java:140) ~[storage-influxdb-plugin-8.7.0.jar:8.7.0]
        at org.apache.skywalking.oap.server.library.module.BootstrapFlow.start(BootstrapFlow.java:49) ~[library-module-8.7.0.jar:8.7.0]
        at org.apache.skywalking.oap.server.library.module.ModuleManager.init(ModuleManager.java:60) ~[library-module-8.7.0.jar:8.7.0]
        at org.apache.skywalking.oap.server.starter.OAPServerBootstrap.start(OAPServerBootstrap.java:43) [server-bootstrap-8.7.0.jar:8.7.0]
        at org.apache.skywalking.oap.server.starter.OAPServerStartUp.main(OAPServerStartUp.java:27) [server-starter-es7-8.7.0.jar:8.7.0]

Use case

When SkyWalking using InfluxDB as the storage, SkyWalking should check if the database exists, if not, then try create database.

Related issues

No response

Are you willing to submit a PR?

Code of Conduct

wu-sheng commented 3 years ago

Do you want to contribute this? This is not a critical issue. We don't check this in all database implementations, such as PostgreSQL, MySQL, TiDB. Of course, it is fine to add if you want.

gaggudeep commented 3 years ago

Hi @wu-sheng, can I contribute here? This would be my first contribution. I think I got what is required; additional check in all DBClients (like this: https://github.com/apache/skywalking/blob/f61dff9a9f1d1f8ddd11c31f039e540521479d36/oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java) to check if the the DB property (in this case: InfluxDB influx) is already initialized or not.(if it is then log some info and return?)

wu-sheng commented 3 years ago

Basically you can, just should notice, whether database creation could require more parameters, and only create if it missed.

wu-sheng commented 2 years ago

No update in months.