wang1027-wqh commented on code in PR #1658:
URL: https://github.com/apache/hertzbeat/pull/1658#discussion_r1538516624
##########
grafana/src/main/java/org/dromara/hertzbeat/grafana/config/GrafanaInit.java:
##########
@@ -0,0 +1,48 @@
+package org.dromara.hertzbeat.grafana.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.hertzbeat.grafana.service.DatasourceService;
+import org.dromara.hertzbeat.grafana.service.ServiceAccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+/**
+ * grafana init
+ */
+@Component
+@Slf4j
+public class GrafanaInit implements CommandLineRunner {
+ @Autowired
+ private GrafanaConfiguration grafanaConfiguration;
+ @Autowired
+ private ServiceAccountService serviceAccountService;
+ @Autowired
+ private DatasourceService datasourceService;
+
+ //1.判断配置是否填写完整
Review Comment:
Please translate an English note as well
##########
grafana/src/main/java/org/dromara/hertzbeat/grafana/config/GrafanaInit.java:
##########
@@ -0,0 +1,48 @@
+package org.dromara.hertzbeat.grafana.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.hertzbeat.grafana.service.DatasourceService;
+import org.dromara.hertzbeat.grafana.service.ServiceAccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+/**
+ * grafana init
+ */
+@Component
+@Slf4j
+public class GrafanaInit implements CommandLineRunner {
+ @Autowired
+ private GrafanaConfiguration grafanaConfiguration;
+ @Autowired
+ private ServiceAccountService serviceAccountService;
+ @Autowired
+ private DatasourceService datasourceService;
+
+ //1.判断配置是否填写完整
+ //2.判断是否有账号,没有则创建且保证账号唯一
+ //2.判断是否有token,没有则创建且保证账号唯一
+ @Override
+ public void run(String... args) throws Exception {
+ if (grafanaConfiguration.isEnabled() && grafanaConfiguration.getUrl()
!= null && grafanaConfiguration.getUsername() != null &&
grafanaConfiguration.getPassword() != null) {
+ serviceAccountService.reload();
+ try {
+ serviceAccountService.getAccount();
+ } catch (RuntimeException e) {
+ log.info("service account is not exist, create service
account");
Review Comment:
Specifies the log level, use the warn level if it is not important. Printing
logs requires critical information, such as the exception stack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]