Repository navigation
lib: cmetrics: upgrade to v2.3.1 #12641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,9 @@ struct cmt_metric { | |
| int hash_indexed; | ||
| struct cmt_map *map; | ||
| struct cfl_list _hash_head; | ||
|
|
||
| /* Owned OTLP datapoint metadata; independent of string label identity. */ | ||
| struct cfl_kvlist *otlp_metadata; | ||
|
Comment on lines
+78
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Find code outside lib/cmetrics that allocates cmt_metric directly or reaches into cmt_map/cmt_metric fields.
rg -nP --type=c -C2 'sizeof\s*\(\s*struct\s+cmt_metric\s*\)|calloc\([^)]*struct\s+cmt_metric' -g '!lib/cmetrics/**'
rg -nP --type=c -C2 '->map->metric\b|->metric_static_set|->hist_buckets' -g '!lib/cmetrics/**' | head -n 80Repository: fluent/fluent-bit Length of output: 816 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- PR diff ---'
git diff --no-ext-diff --unified=30 329a371563c0e47406ce1373c1efebceae4af54e 3d9a7e33fb5b5a85bf71b6ffb42f8f62ec5d4907 -- lib/cmetrics/include/cmetrics/cmt_metric.h lib/cmetrics/src plugins/processor_labels/labels.c
printf '%s\n' '--- struct declarations and related APIs ---'
rg -n -F --glob '*.{h,c}' -e 'struct cmt_metric {' -e 'struct cmt_map {' -e 'cmt_metric_destroy' -e 'cmt_metric_free' -e 'otlp_metadata' -e 'cmt_map_destroy' -e 'cmt_map_free' lib/cmetrics plugins/processor_labels
printf '%s\n' '--- labels allocation and lifecycle ---'
sed -n '110,180p' plugins/processor_labels/labels.c
sed -n '820,920p' plugins/processor_labels/labels.c
rg -n -F --glob 'labels.c' -e 'free(metric)' -e 'cmt_metric' -e 'cmt_map' -e 'cfl_kvlist' plugins/processor_labelsRepository: fluent/fluent-bit Length of output: 43375 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- PR diff ---'
git diff --no-ext-diff --unified=30 329a371563c0e47406ce1373c1efebceae4af54e 3d9a7e33fb5b5a85bf71b6ffb42f8f62ec5d4907 -- lib/cmetrics/include/cmetrics/cmt_metric.h lib/cmetrics/src plugins/processor_labels/labels.c
printf '%s\n' '--- struct declarations and related APIs ---'
rg -n -F --glob '*.{h,c}' -e 'struct cmt_metric {' -e 'struct cmt_map {' -e 'cmt_metric_destroy' -e 'cmt_metric_free' -e 'otlp_metadata' -e 'cmt_map_destroy' -e 'cmt_map_free' lib/cmetrics plugins/processor_labels || test "$?" -eq 1
printf '%s\n' '--- labels allocation and lifecycle ---'
sed -n '110,180p' plugins/processor_labels/labels.c
sed -n '820,920p' plugins/processor_labels/labels.c
rg -n -F --glob 'labels.c' -e 'free(metric)' -e 'cmt_metric' -e 'cmt_map' -e 'cfl_kvlist' plugins/processor_labels || test "$?" -eq 1Repository: fluent/fluent-bit Length of output: 43291 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- cmt_map declaration ---'
nl -ba lib/cmetrics/include/cmetrics/cmt_map.h | sed -n '25,75p'
printf '%s\n' '--- processor metric lifecycle ---'
nl -ba plugins/processor_labels/labels.c | sed -n '135,215p'
nl -ba plugins/processor_labels/labels.c | sed -n '800,890p'
printf '%s\n' '--- cmetrics metric cleanup ---'
rg -n -F --glob '*.c' -e 'cmt_map_metric_destroy' -e 'cfl_kvlist_destroy(metric->otlp_metadata)' -e 'cfl_kvlist_destroy(map->metric.otlp_metadata)' -e 'free(metric)' lib/cmetrics/src plugins/processor_labelsRepository: fluent/fluent-bit Length of output: 11153 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- cmt_map declaration ---'
nl -ba lib/cmetrics/include/cmetrics/cmt_map.h | sed -n '25,75p'
printf '%s\n' '--- processor metric lifecycle ---'
nl -ba plugins/processor_labels/labels.c | sed -n '135,215p'
nl -ba plugins/processor_labels/labels.c | sed -n '800,890p'
printf '%s\n' '--- cmetrics metric cleanup ---'
rg -n -F --glob '*.c' -e 'cmt_map_metric_destroy' -e 'cfl_kvlist_destroy(metric->otlp_metadata)' -e 'cfl_kvlist_destroy(map->metric.otlp_metadata)' -e 'free(metric)' lib/cmetrics/src plugins/processor_labels || test "$?" -eq 1Repository: fluent/fluent-bit Length of output: 11153 Review downstream ABI users and preserve metadata ownership.
The processor also drops metadata during static-metric conversion. It zeroes Suggested cleanup--- a/plugins/processor_labels/labels.c
+++ b/plugins/processor_labels/labels.c
@@ -192,6 +192,7 @@ static void map_metric_destroy(struct cmt_metric *metric)
if (metric->sum_quantiles) {
free(metric->sum_quantiles);
}
+ cfl_kvlist_destroy(metric->otlp_metadata);
cfl_list_del(&metric->_head);
free(metric);
@@ -874,6 +875,7 @@ int metrics_map_convert_static_metric(struct cmt_map *map,
metric->sum_sum = map->metric.sum_sum;
metric->timestamp = map->metric.timestamp;
+ metric->otlp_metadata = map->metric.otlp_metadata;
map->metric_static_set = 0;🤖 Prompt for AI AgentsSource: Coding guidelines
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consumers will be updated |
||
| }; | ||
|
|
||
| struct cmt_exp_histogram_snapshot { | ||
|
|
@@ -136,6 +139,18 @@ void cmt_metric_hist_set(struct cmt_metric *metric, uint64_t timestamp, | |
|
|
||
| uint64_t cmt_metric_hist_get_value(struct cmt_metric *metric, int bucket_id); | ||
|
|
||
| /* Convert cumulative native buckets without unsigned underflow. */ | ||
| static inline uint64_t cmt_metric_hist_get_bucket_count(struct cmt_metric *metric, int bucket_id) | ||
| { | ||
| uint64_t current; | ||
| uint64_t previous; | ||
|
|
||
| current = cmt_metric_hist_get_value(metric, bucket_id); | ||
| previous = bucket_id == 0 ? 0 : cmt_metric_hist_get_value(metric, bucket_id - 1); | ||
| return current >= previous ? current - previous : 0; | ||
| } | ||
|
|
||
|
|
||
| double cmt_metric_hist_get_sum_value(struct cmt_metric *metric); | ||
|
|
||
| uint64_t cmt_metric_hist_get_count_value(struct cmt_metric *metric); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* CMetrics | ||
| * ======== | ||
| * Copyright 2021-2022 The CMetrics Authors | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| #ifndef CMT_OTLP_METADATA_H | ||
| #define CMT_OTLP_METADATA_H | ||
|
|
||
| #include <cmetrics/cmetrics.h> | ||
| #include <cmetrics/cmt_map.h> | ||
| #include <mpack/mpack.h> | ||
|
|
||
| struct cfl_kvlist *cmt_otlp_metadata_clone(struct cfl_kvlist *source); | ||
| int cmt_otlp_metadata_pack(mpack_writer_t *writer, struct cmt *context); | ||
| int cmt_otlp_metadata_pack_external(mpack_writer_t *writer, struct cmt *context); | ||
| int cmt_otlp_metadata_restore(struct cmt *context); | ||
| int cmt_otlp_histogram_restore(struct cmt *context); | ||
| int cmt_otlp_capture_labels(struct cmt_map *map, struct cmt_metric *sample); | ||
| int cmt_otlp_attributes_match_labels(struct cmt_map *map, struct cmt_metric *sample); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| @echo off | ||
| setlocal | ||
| git submodule update --init --recursive | ||
| cd build | ||
| cmake -G "NMake Makefiles" -DCMT_TESTS=On ..\ | ||
| cmake --build . | ||
| endlocal | ||
| if errorlevel 1 exit /b %errorlevel% | ||
| cmake -S . -B build -G "NMake Makefiles" -DCMT_TESTS=On -DCMAKE_BUILD_TYPE=Debug | ||
| if errorlevel 1 exit /b %errorlevel% | ||
| cmake --build build | ||
| endlocal & exit /b %errorlevel% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Pin the ARM64 action to the reviewed commit.
v3.2.1is a mutable tag. If its owner retargets the tag, later CI runs can execute different action code without a workflow change. Pin this reference to the release’s full commit SHA,fa1f3e7de95534497266c7265950b5188355fbfb, and retainv3.2.1in a comment. GitHub documents that tags can move. (docs.github.com)Based on learnings: “reference third-party actions by pinning to a full commit SHA” rather than a mutable tag.
🤖 Prompt for AI Agents
Source: Learnings