-
Notifications
You must be signed in to change notification settings - Fork 106
feat: metrics reporting for scan and commit #589
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
Open
evindj
wants to merge
3
commits into
apache:main
Choose a base branch
from
evindj:metrics_core_components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # 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. | ||
|
|
||
| iceberg_install_all_headers(iceberg/metrics) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * 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 "iceberg/metrics/commit_report.h" | ||
|
|
||
| #include "iceberg/snapshot.h" | ||
| #include "iceberg/util/string_util.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| CommitMetrics CommitMetrics::Of(MetricsContext& context) { | ||
| CommitMetrics m; | ||
| m.total_duration = context.GetTimer("total-duration"); | ||
| m.attempts = context.GetCounter("attempts"); | ||
| return m; | ||
| } | ||
|
|
||
| CommitMetrics CommitMetrics::Noop() { return CommitMetrics::Of(MetricsContext::Null()); } | ||
|
|
||
| void CommitMetrics::PopulateResult(CommitMetricsResult& result) const { | ||
| result.total_duration = | ||
| total_duration ? TimerResult{.unit = std::string(total_duration->Unit()), | ||
| .count = total_duration->Count(), | ||
| .total_duration = total_duration->TotalDuration()} | ||
| : TimerResult{}; | ||
| result.attempts = | ||
| attempts ? CounterResult{.unit = attempts->Unit(), .value = attempts->Value()} | ||
| : CounterResult{}; | ||
| } | ||
|
|
||
| CommitMetricsResult CommitMetricsResult::From( | ||
| const CommitMetrics& live_metrics, | ||
| const std::unordered_map<std::string, std::string>& snapshot_summary) { | ||
| CommitMetricsResult result; | ||
| live_metrics.PopulateResult(result); | ||
|
|
||
| // Helpers: parse a summary key and wrap as a typed CounterResult. | ||
| auto count_field = [&snapshot_summary](const std::string& key) -> CounterResult { | ||
| auto it = snapshot_summary.find(key); | ||
| if (it == snapshot_summary.end()) return {}; | ||
| auto parsed = StringUtils::ParseNumber<int64_t>(it->second); | ||
| return {.unit = CounterUnit::kCount, | ||
| .value = parsed.has_value() ? parsed.value() : 0}; | ||
| }; | ||
| auto bytes_field = [&snapshot_summary](const std::string& key) -> CounterResult { | ||
| auto it = snapshot_summary.find(key); | ||
| if (it == snapshot_summary.end()) return {.unit = CounterUnit::kBytes}; | ||
| auto parsed = StringUtils::ParseNumber<int64_t>(it->second); | ||
| return {.unit = CounterUnit::kBytes, | ||
| .value = parsed.has_value() ? parsed.value() : 0}; | ||
| }; | ||
|
|
||
| result.added_data_files = count_field(SnapshotSummaryFields::kAddedDataFiles); | ||
| result.removed_data_files = count_field(SnapshotSummaryFields::kDeletedDataFiles); | ||
| result.total_data_files = count_field(SnapshotSummaryFields::kTotalDataFiles); | ||
| result.added_delete_files = count_field(SnapshotSummaryFields::kAddedDeleteFiles); | ||
| result.added_equality_delete_files = | ||
| count_field(SnapshotSummaryFields::kAddedEqDeleteFiles); | ||
| result.added_positional_delete_files = | ||
| count_field(SnapshotSummaryFields::kAddedPosDeleteFiles); | ||
| result.added_dvs = count_field(SnapshotSummaryFields::kAddedDVs); | ||
| result.removed_positional_delete_files = | ||
| count_field(SnapshotSummaryFields::kRemovedPosDeleteFiles); | ||
| result.removed_dvs = count_field(SnapshotSummaryFields::kRemovedDVs); | ||
| result.removed_equality_delete_files = | ||
| count_field(SnapshotSummaryFields::kRemovedEqDeleteFiles); | ||
| result.removed_delete_files = count_field(SnapshotSummaryFields::kRemovedDeleteFiles); | ||
| result.total_delete_files = count_field(SnapshotSummaryFields::kTotalDeleteFiles); | ||
| result.added_records = count_field(SnapshotSummaryFields::kAddedRecords); | ||
| result.removed_records = count_field(SnapshotSummaryFields::kDeletedRecords); | ||
| result.total_records = count_field(SnapshotSummaryFields::kTotalRecords); | ||
| result.added_files_size_bytes = bytes_field(SnapshotSummaryFields::kAddedFileSize); | ||
| result.removed_files_size_bytes = bytes_field(SnapshotSummaryFields::kRemovedFileSize); | ||
| result.total_files_size_bytes = bytes_field(SnapshotSummaryFields::kTotalFileSize); | ||
| result.added_positional_deletes = count_field(SnapshotSummaryFields::kAddedPosDeletes); | ||
| result.removed_positional_deletes = | ||
| count_field(SnapshotSummaryFields::kRemovedPosDeletes); | ||
| result.total_positional_deletes = count_field(SnapshotSummaryFields::kTotalPosDeletes); | ||
| result.added_equality_deletes = count_field(SnapshotSummaryFields::kAddedEqDeletes); | ||
| result.removed_equality_deletes = count_field(SnapshotSummaryFields::kRemovedEqDeletes); | ||
| result.total_equality_deletes = count_field(SnapshotSummaryFields::kTotalEqDeletes); | ||
| result.kept_manifest_count = count_field(SnapshotSummaryFields::kManifestsKept); | ||
| result.created_manifest_count = count_field(SnapshotSummaryFields::kManifestsCreated); | ||
| result.replaced_manifest_count = count_field(SnapshotSummaryFields::kManifestsReplaced); | ||
| result.processed_manifest_entries_count = | ||
| count_field(SnapshotSummaryFields::kEntriesProcessed); | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace iceberg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * 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 <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "iceberg/constants.h" | ||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/metrics/metrics_context.h" | ||
| #include "iceberg/metrics/metrics_types.h" | ||
| #include "iceberg/metrics/timer.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| // Forward declaration: CommitMetricsResult is defined later in this header. | ||
| struct CommitMetricsResult; | ||
|
|
||
| /// \brief Live commit metrics collected during a table commit operation. | ||
| /// | ||
| /// Tracks the overall commit duration and retry count. File/record counts come | ||
| /// from the snapshot summary after the commit succeeds and are stored separately | ||
| /// in CommitMetricsResult. | ||
| class ICEBERG_EXPORT CommitMetrics { | ||
| public: | ||
| /// \brief Create a CommitMetrics instance backed by the given MetricsContext. | ||
| static CommitMetrics Of(MetricsContext& context); | ||
|
|
||
| /// \brief Create a CommitMetrics instance with all-noop timer and counter. | ||
| static CommitMetrics Noop(); | ||
|
|
||
| /// \brief Snapshot timer and counter values into the corresponding fields of result. | ||
| /// | ||
| /// Only total_duration and attempts are written; the caller is responsible for | ||
| /// populating the remaining snapshot-summary fields. | ||
| void PopulateResult(CommitMetricsResult& result) const; | ||
|
|
||
| /// \brief Timer measuring total wall-clock time of the commit call. | ||
| std::shared_ptr<Timer> total_duration; | ||
|
|
||
| /// \brief Counter for the number of commit attempts (including retries). | ||
| std::shared_ptr<Counter> attempts; | ||
| }; | ||
|
|
||
| /// \brief Immutable snapshot of commit metrics for use in CommitReport. | ||
| struct ICEBERG_EXPORT CommitMetricsResult { | ||
| /// \brief Total wall-clock duration of the commit attempt. | ||
| TimerResult total_duration; | ||
| /// \brief Number of commit attempts (1 on success without retries). | ||
| CounterResult attempts; | ||
| /// \brief Number of data files added in this commit. | ||
| CounterResult added_data_files; | ||
| /// \brief Number of data files removed in this commit. | ||
| CounterResult removed_data_files; | ||
| /// \brief Total live data files after this commit. | ||
| CounterResult total_data_files; | ||
| /// \brief Number of delete files added in this commit. | ||
| CounterResult added_delete_files; | ||
| /// \brief Equality delete files added. | ||
| CounterResult added_equality_delete_files; | ||
| /// \brief Positional delete files added. | ||
| CounterResult added_positional_delete_files; | ||
| /// \brief Deletion vectors added. | ||
| CounterResult added_dvs; | ||
| /// \brief Positional delete files removed. | ||
| CounterResult removed_positional_delete_files; | ||
| /// \brief Deletion vectors removed. | ||
| CounterResult removed_dvs; | ||
| /// \brief Equality delete files removed. | ||
| CounterResult removed_equality_delete_files; | ||
| /// \brief Number of delete files removed in this commit. | ||
| CounterResult removed_delete_files; | ||
| /// \brief Total live delete files after this commit. | ||
| CounterResult total_delete_files; | ||
| /// \brief Number of records added in this commit. | ||
| CounterResult added_records; | ||
| /// \brief Number of records removed in this commit. | ||
| CounterResult removed_records; | ||
| /// \brief Total live records after this commit. | ||
| CounterResult total_records; | ||
| /// \brief Total byte size of files added. | ||
| CounterResult added_files_size_bytes; | ||
| /// \brief Total byte size of files removed. | ||
| CounterResult removed_files_size_bytes; | ||
| /// \brief Total byte size of all live files after this commit. | ||
| CounterResult total_files_size_bytes; | ||
| /// \brief Positional delete records added. | ||
| CounterResult added_positional_deletes; | ||
| /// \brief Positional delete records removed. | ||
| CounterResult removed_positional_deletes; | ||
| /// \brief Total positional delete records after this commit. | ||
| CounterResult total_positional_deletes; | ||
| /// \brief Equality delete records added. | ||
| CounterResult added_equality_deletes; | ||
| /// \brief Equality delete records removed. | ||
| CounterResult removed_equality_deletes; | ||
| /// \brief Total equality delete records after this commit. | ||
| CounterResult total_equality_deletes; | ||
| /// \brief Manifest files kept unchanged in this commit. | ||
| CounterResult kept_manifest_count; | ||
| /// \brief Manifest files created in this commit. | ||
| CounterResult created_manifest_count; | ||
| /// \brief Manifest files replaced in this commit. | ||
| CounterResult replaced_manifest_count; | ||
| /// \brief Manifest entries processed in this commit. | ||
| CounterResult processed_manifest_entries_count; | ||
|
|
||
| bool operator==(const CommitMetricsResult&) const = default; | ||
|
|
||
| /// \brief Build a CommitMetricsResult from live metrics and a snapshot summary map. | ||
| /// | ||
| /// Combines timer/retry measurements from \p live_metrics with records parsed | ||
| /// from \p snapshot_summary. Missing or unparseable summary keys default to 0. | ||
| static CommitMetricsResult From( | ||
| const CommitMetrics& live_metrics, | ||
| const std::unordered_map<std::string, std::string>& snapshot_summary); | ||
| }; | ||
|
|
||
| /// \brief Report generated after a commit operation. | ||
| /// | ||
| /// Contains metrics about the changes made in a commit. | ||
| struct ICEBERG_EXPORT CommitReport { | ||
| /// \brief The fully qualified name of the table that was modified. | ||
| std::string table_name; | ||
| /// \brief The snapshot ID created by this commit. | ||
| int64_t snapshot_id = kInvalidSnapshotId; | ||
| /// \brief The sequence number assigned to this commit. | ||
| int64_t sequence_number = kInvalidSequenceNumber; | ||
| /// \brief The operation that was performed (write, delete, etc.). | ||
| std::string operation; | ||
| /// \brief Metrics collected during the commit operation. | ||
| CommitMetricsResult commit_metrics; | ||
| /// \brief Additional key-value metadata. | ||
| std::unordered_map<std::string, std::string> metadata; | ||
| }; | ||
|
|
||
| } // namespace iceberg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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 "iceberg/metrics/counter.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| namespace { | ||
|
|
||
| class NoopCounter final : public Counter { | ||
| public: | ||
| void Increment() override {} | ||
| void Increment(int64_t) override {} | ||
| int64_t Value() const override { return 0; } | ||
| bool IsNoop() const override { return true; } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| Counter& Counter::Noop() { | ||
| static NoopCounter instance; | ||
| return instance; | ||
| } | ||
|
|
||
| DefaultCounter::DefaultCounter(CounterUnit unit) : unit_(unit) {} | ||
|
|
||
| void DefaultCounter::Increment() { count_.fetch_add(1, std::memory_order_relaxed); } | ||
|
|
||
| void DefaultCounter::Increment(int64_t amount) { | ||
| count_.fetch_add(amount, std::memory_order_relaxed); | ||
| } | ||
|
|
||
| int64_t DefaultCounter::Value() const { return count_.load(std::memory_order_relaxed); } | ||
|
|
||
| } // namespace iceberg |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing meson.build equivalent for this subdirectory