github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/pipeline/plugin.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 "github.com/alibaba/ilogtail/pkg/selfmonitor"
    18  
    19  // logtail plugin type define
    20  const (
    21  	MetricInputType  = iota
    22  	ServiceInputType = iota
    23  	FilterType       = iota
    24  	ProcessorType    = iota
    25  	AggregatorType   = iota
    26  )
    27  
    28  type PluginContext struct {
    29  	ID           string
    30  	Priority     int
    31  	MetricRecord *selfmonitor.MetricsRecord
    32  }
    33  
    34  type PluginMeta struct {
    35  	PluginID         string
    36  	PluginType       string
    37  	PluginTypeWithID string
    38  }
    39  
    40  type MetricCreator func() MetricInput
    41  
    42  var MetricInputs = map[string]MetricCreator{}
    43  
    44  func AddMetricCreator(name string, creator MetricCreator) {
    45  	MetricInputs[name] = creator
    46  }
    47  
    48  type ServiceCreator func() ServiceInput
    49  
    50  var ServiceInputs = map[string]ServiceCreator{}
    51  
    52  func AddServiceCreator(name string, creator ServiceCreator) {
    53  	ServiceInputs[name] = creator
    54  }
    55  
    56  type ProcessorCreator func() Processor
    57  
    58  var Processors = map[string]ProcessorCreator{}
    59  
    60  func AddProcessorCreator(name string, creator ProcessorCreator) {
    61  	Processors[name] = creator
    62  }
    63  
    64  type AggregatorCreator func() Aggregator
    65  
    66  var Aggregators = map[string]AggregatorCreator{}
    67  
    68  func AddAggregatorCreator(name string, creator AggregatorCreator) {
    69  	Aggregators[name] = creator
    70  }
    71  
    72  type FlusherCreator func() Flusher
    73  
    74  var Flushers = map[string]FlusherCreator{}
    75  
    76  func AddFlusherCreator(name string, creator FlusherCreator) {
    77  	Flushers[name] = creator
    78  }
    79  
    80  type ExtensionCreator func() Extension
    81  
    82  var Extensions = map[string]ExtensionCreator{}
    83  
    84  func AddExtensionCreator(name string, creator ExtensionCreator) {
    85  	Extensions[name] = creator
    86  }
    87  
    88  func GetPluginCommonLabels(context Context, pluginMeta *PluginMeta) []selfmonitor.LabelPair {
    89  	labels := make([]selfmonitor.LabelPair, 0)
    90  	labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyMetricCategory, Value: selfmonitor.MetricLabelValueMetricCategoryPlugin})
    91  	labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyProject, Value: context.GetProject()})
    92  	labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyLogstore, Value: context.GetLogstore()})
    93  	labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyPipelineName, Value: context.GetConfigName()})
    94  
    95  	if len(pluginMeta.PluginID) > 0 {
    96  		labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyPluginID, Value: pluginMeta.PluginID})
    97  	}
    98  	if len(pluginMeta.PluginType) > 0 {
    99  		labels = append(labels, selfmonitor.LabelPair{Key: selfmonitor.MetricLabelKeyPluginType, Value: pluginMeta.PluginType})
   100  	}
   101  	return labels
   102  }