github-actions[bot] commented on code in PR #41752: URL: https://github.com/apache/doris/pull/41752#discussion_r1801066308
########## be/src/util/jni_metrics.h: ########## @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <memory> + +#include "jni.h" +#include "util/metrics.h" + +namespace doris { + +struct JdbcConnectionMetrics; + +class JniMetrics { +public: + JniMetrics(MetricRegistry* registry); + ~JniMetrics(); + void update_jdbc_connection_metrics(); + +private: + void _init(); + +private: Review Comment: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] ```suggestion ``` <details> <summary>Additional context</summary> **be/src/util/jni_metrics.h:34:** previously declared here ```cpp private: ^ ``` </details> ########## be/src/util/jni_metrics.cpp: ########## @@ -0,0 +1,135 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "jni_metrics.h" + +#include <utility> + +#include "util/jni-util.h" +#include "util/metrics.h" + +namespace doris { + +struct JdbcConnectionMetrics { + JdbcConnectionMetrics(std::string catalog_id, std::shared_ptr<MetricEntity> entity) { + server_entity = entity; + metric_jdbc_scan_connection_percent = new MetricPrototype(MetricType::GAUGE, MetricUnit::PERCENT, + "jdbc_scan_connection_percent", "", "", {{"catalog", catalog_id}}); + jdbc_scan_connection_percent = static_cast<IntGauge *>(entity->register_metric<IntGauge>(metric_jdbc_scan_connection_percent)); + } + void update(const int value) const { jdbc_scan_connection_percent->set_value(value); } + void deregister_metric() const { + if (metric_jdbc_scan_connection_percent != nullptr) { + server_entity->deregister_metric(metric_jdbc_scan_connection_percent); + } + } + std::shared_ptr<MetricEntity> server_entity; + MetricPrototype* metric_jdbc_scan_connection_percent; + IntGauge* jdbc_scan_connection_percent; +}; + +const char* JniMetrics::_s_hook_name = "jni_metrics"; + +JniMetrics::JniMetrics(MetricRegistry* registry) { + DCHECK(registry != nullptr); + _registry = registry; + _server_entity = _registry->register_entity("server"); + DCHECK(_server_entity != nullptr); + _server_entity->register_hook(_s_hook_name, + std::bind(&JniMetrics::update_jdbc_connection_metrics, this)); + _init(); +} + +void JniMetrics::_init() { + JNIEnv* env = nullptr; + Status st = JniUtil::GetJNIEnv(&env); + if (!st.ok()) { + LOG(WARNING) << "get jni env failed. " << st.to_string(); + return; + } + st = JniUtil::get_jni_scanner_class(env, "org/apache/doris/jdbc/JdbcDataSource", + &_jdbc_data_source_clz); + if (!st.ok()) { + LOG(WARNING) << "class org/apachhe/doris/jdbc/JdbcDataSource not find in jvm." + << st.to_string(); + return; + } + _get_connection_percent_id = env->GetStaticMethodID( + _jdbc_data_source_clz, "getConnectionPercent", "()Ljava/util/Map;"); + st = JniUtil::GetJniExceptionMsg(env); + if (!st.ok()) { + LOG(WARNING) << "get getConnectionPercent method id failed. " << st.to_string(); + return; + } + _is_init = true; + LOG(INFO) << "jni metrics inited successfully"; +} + +void JniMetrics::update_jdbc_connection_metrics() { Review Comment: warning: method 'update_jdbc_connection_metrics' can be made const [readability-make-member-function-const] ```suggestion void JniMetrics::update_jdbc_connection_metrics() const { ``` be/src/util/jni_metrics.h:32: ```diff - void update_jdbc_connection_metrics(); + void update_jdbc_connection_metrics() const; ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org