Skip to main content

flow/adapter/
stat.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::BTreeMap;
16
17use common_meta::key::flow::flow_state::FlowStat;
18
19use crate::StreamingEngine;
20use crate::engine::FlowStatProvider;
21
22impl FlowStatProvider for StreamingEngine {
23    async fn flow_stat(&self) -> FlowStat {
24        let mut state_size_map = BTreeMap::new();
25        let mut last_exec_time_map = BTreeMap::new();
26        let mut start_time_map = BTreeMap::new();
27
28        for worker in self.worker_handles.iter() {
29            match worker.get_full_flow_stat().await {
30                Ok((sizes, exec_times, start_times)) => {
31                    state_size_map.extend(sizes.into_iter().map(|(k, v)| (k as u32, v)));
32                    last_exec_time_map.extend(exec_times.into_iter().map(|(k, v)| (k as u32, v)));
33                    start_time_map.extend(start_times.into_iter().map(|(k, v)| (k as u32, v)));
34                }
35                Err(err) => {
36                    common_telemetry::error!(err; "Get full flow stat error");
37                }
38            }
39        }
40
41        FlowStat {
42            state_size: state_size_map,
43            last_exec_time_map,
44            start_time_map,
45        }
46    }
47}