mirror of
https://github.com/apache/doris.git
synced 2026-11-04 16:03:23 +00:00
Related PR: #68655 Problem Summary: The existing version gauges concatenate variable-width decimal components with `0`. Their numeric ordering can disagree with version ordering; for example, `4.99.0` is encoded as `409900`, which is greater than `5.0.0` encoded as `50000`. Appending hotfix only when it is positive also changes the value's magnitude. This change treats `major`, `minor`, `patch`, and `hotfix` as four base-100 digits. Every component therefore occupies exactly two decimal positions: `5.1.2.3` is logically encoded as `05|01|02|03` and exported as the numeric value `5010203`. Source generation rejects components outside `0..99`, so the encoding remains unambiguous and order-preserving. BE and Cloud share one C++ encoder, FE applies the equivalent calculation, and the existing metric names and build labels remain unchanged. Unit tests cover representative values, ordering, and bounds; the cross-process regression reconstructs the expected value from labels for FE, BE, and Cloud. ### Prometheus exposition examples The following examples assume build version `doris-5.1.2.3` and short Git hash `abc1234`. Each version component occupies two decimal positions, so `5.1.2.3` is logically encoded as `05|01|02|03` and exported as the numeric value `5010203`. FE (`/metrics`): ```text # HELP doris_fe_version # TYPE doris_fe_version gauge doris_fe_version{version="doris-5.1.2.3", major="5", minor="1", patch="2", hotfix="3", short_hash="abc1234"} 5010203 ``` BE (`/brpc_metrics`): ```text # HELP doris_be_version # TYPE doris_be_version gauge doris_be_version{version="doris-5.1.2.3",major="5",minor="1",patch="2",hotfix="3",short_hash="abc1234"} 5010203 ``` Cloud meta-service/recycler (`/brpc_metrics`): ```text # HELP doris_cloud_version # TYPE doris_cloud_version gauge doris_cloud_version{version="doris-5.1.2.3",major="5",minor="1",patch="2",hotfix="3",short_hash="abc1234"} 5010203 ``` ### Release note Encode FE, BE, and Cloud version metric values with fixed-width base-100 components.
42 lines
1.8 KiB
C++
42 lines
1.8 KiB
C++
// 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 <cstdint>
|
|
|
|
namespace doris {
|
|
|
|
inline constexpr uint64_t VERSION_METRIC_COMPONENT_BASE = 100;
|
|
|
|
inline constexpr bool is_valid_version_metric_component(int64_t component) {
|
|
return component >= 0 && component < static_cast<int64_t>(VERSION_METRIC_COMPONENT_BASE);
|
|
}
|
|
|
|
// Treat each component as one base-100 digit so numeric ordering matches version ordering.
|
|
// For example, 26.0.1.0 is encoded as 26000100 and 26.0.1.1 as 26000101.
|
|
// Callers must validate every component with is_valid_version_metric_component first.
|
|
inline constexpr uint64_t encode_version_metric_value(int64_t major, int64_t minor, int64_t patch,
|
|
int64_t hotfix) {
|
|
uint64_t encoded = static_cast<uint64_t>(major);
|
|
encoded = encoded * VERSION_METRIC_COMPONENT_BASE + static_cast<uint64_t>(minor);
|
|
encoded = encoded * VERSION_METRIC_COMPONENT_BASE + static_cast<uint64_t>(patch);
|
|
return encoded * VERSION_METRIC_COMPONENT_BASE + static_cast<uint64_t>(hotfix);
|
|
}
|
|
|
|
} // namespace doris
|