github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/pipeline/aggregator.go (about) 1 // Copyright 2021 iLogtail Authors 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 15 package pipeline 16 17 import ( 18 "github.com/alibaba/ilogtail/pkg/models" 19 "github.com/alibaba/ilogtail/pkg/protocol" 20 ) 21 22 // Aggregator is an interface for implementing an Aggregator plugin. 23 // the RunningAggregator wraps this interface and guarantees that 24 type Aggregator interface { 25 // Init called for init some system resources, like socket, mutex... 26 // return flush interval(ms) and error flag, if interval is 0, use default interval 27 Init(Context, LogGroupQueue) (int, error) 28 29 // Description returns a one-sentence description on the Input. 30 Description() string 31 32 // Reset resets the aggregators caches and aggregates. 33 Reset() 34 } 35 36 // AggregatorV1 37 // Add, Flush, and Reset can not be called concurrently, so locking is not 38 // required when implementing an Aggregator plugin. 39 type AggregatorV1 interface { 40 Aggregator 41 // Add the metric to the aggregator. 42 Add(log *protocol.Log, ctx map[string]interface{}) error 43 44 // Flush pushes the current aggregates to the accumulator. 45 Flush() []*protocol.LogGroup 46 } 47 48 // AggregatorV2 49 // Apply, Push, and Reset can not be called concurrently, so locking is not 50 // required when implementing an Aggregator plugin. 51 type AggregatorV2 interface { 52 Aggregator 53 // Add the metric to the aggregator. 54 Record(*models.PipelineGroupEvents, PipelineContext) error 55 // GetResult the current aggregates to the accumulator. 56 GetResult(PipelineContext) error 57 }