iceberg-cpp
Loading...
Searching...
No Matches
metrics_reporter.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <string>
23#include <string_view>
24#include <unordered_map>
25#include <utility>
26#include <variant>
27
28#include "iceberg/iceberg_export.h"
29#include "iceberg/metrics/commit_report.h"
30#include "iceberg/metrics/scan_report.h"
31#include "iceberg/result.h"
32
33namespace iceberg {
34
36enum class MetricsReportType {
37 kScanReport,
38 kCommitReport,
39};
40
42ICEBERG_EXPORT constexpr std::string_view ToString(MetricsReportType type) noexcept {
43 switch (type) {
44 case MetricsReportType::kScanReport:
45 return "scan";
46 case MetricsReportType::kCommitReport:
47 return "commit";
48 }
49 std::unreachable();
50}
51
56using MetricsReport = std::variant<ScanReport, CommitReport>;
57
62ICEBERG_EXPORT inline MetricsReportType GetReportType(const MetricsReport& report) {
63 return std::visit(
64 [](const auto& r) -> MetricsReportType {
65 using T = std::decay_t<decltype(r)>;
66 if constexpr (std::is_same_v<T, ScanReport>) {
67 return MetricsReportType::kScanReport;
68 } else {
69 return MetricsReportType::kCommitReport;
70 }
71 },
72 report);
73}
74
82class ICEBERG_EXPORT MetricsReporter {
83 public:
84 virtual ~MetricsReporter() = default;
85
91 virtual Status Initialize(
92 [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
93 return {};
94 }
95
102 virtual Status Report(const MetricsReport& report) = 0;
103};
104
105} // namespace iceberg
Interface for reporting metrics from Iceberg operations.
Definition metrics_reporter.h:82
virtual Status Initialize(const std::unordered_map< std::string, std::string > &properties)
Initialize the reporter with catalog properties after construction.
Definition metrics_reporter.h:91
virtual Status Report(const MetricsReport &report)=0
Report a metrics report.