github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/pipeline/flusher.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  // Flusher ...
    23  // Sample flusher implementation: see plugin_manager/flusher_sls.gox.
    24  type Flusher interface {
    25  	// Init called for init some system resources, like socket, mutex...
    26  	Init(Context) error
    27  
    28  	// Description returns a one-sentence description on the Input.
    29  	Description() string
    30  
    31  	// IsReady checks if flusher is ready to accept more data.
    32  	// @projectName, @logstoreName, @logstoreKey: meta of the corresponding data.
    33  	// Note: If SetUrgent is called, please make some adjustment so that IsReady
    34  	//   can return true to accept more data in time and config instance can be
    35  	//   stopped gracefully.
    36  	IsReady(projectName string, logstoreName string, logstoreKey int64) bool
    37  
    38  	// SetUrgent indicates the flusher that it will be destroyed soon.
    39  	// @flag indicates if main program (Logtail mostly) will exit after calling this.
    40  	//
    41  	// Note: there might be more data to flush after SetUrgent is called, and if flag
    42  	//   is true, these data will be passed to flusher through IsReady/Export before
    43  	//   program exits.
    44  	//
    45  	// Recommendation: set some state flags in this method to guide the behavior
    46  	//   of other methods.
    47  	SetUrgent(flag bool)
    48  
    49  	// Stop stops flusher and release resources.
    50  	// It is time for flusher to do cleaning jobs, includes:
    51  	// 1. Export cached but not flushed data. For flushers that contain some kinds of
    52  	//   aggregation or buffering, it is important to flush cached out now, otherwise
    53  	//   data will lost.
    54  	// 2. Release opened resources: goroutines, file handles, connections, etc.
    55  	// 3. Maybe more, it depends.
    56  	// In a word, flusher should only have things that can be recycled by GC after this.
    57  	Stop() error
    58  }
    59  
    60  type FlusherV1 interface {
    61  	Flusher
    62  	// Flush flushes data to destination, such as SLS, console, file, etc.
    63  	// It is expected to return no error at most time because IsReady will be called
    64  	// before it to make sure there is space for next data.
    65  	Flush(projectName string, logstoreName string, configName string, logGroupList []*protocol.LogGroup) error
    66  }
    67  
    68  type FlusherV2 interface {
    69  	Flusher
    70  	// Export data to destination, such as gRPC, console, file, etc.
    71  	// It is expected to return no error at most time because IsReady will be called
    72  	// before it to make sure there is space for next data.
    73  	Export([]*models.PipelineGroupEvents, PipelineContext) error
    74  }