forked from alibaba/loongcollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_wrapper.go
140 lines (114 loc) · 5.3 KB
/
plugin_wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2024 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pluginmanager
import (
"time"
"github.com/alibaba/ilogtail/pkg/helper"
"github.com/alibaba/ilogtail/pkg/pipeline"
)
/*---------------------
Plugin Input
The input plugin is used for reading data.
---------------------*/
type InputWrapper struct {
pipeline.PluginContext
Config *LogstoreConfig
Tags map[string]string
Interval time.Duration
outEventsTotal pipeline.CounterMetric
outEventGroupsTotal pipeline.CounterMetric
outSizeBytes pipeline.CounterMetric
}
func (wrapper *InputWrapper) InitMetricRecord(pluginMeta *pipeline.PluginMeta) {
labels := helper.GetPluginCommonLabels(wrapper.Config.Context, pluginMeta)
wrapper.MetricRecord = wrapper.Config.Context.RegisterMetricRecord(labels)
wrapper.outEventsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutEventsTotal)
wrapper.outEventGroupsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutEventGroupsTotal)
wrapper.outSizeBytes = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutSizeBytes)
}
// The service plugin is an input plugin used for passively receiving data.
type ServiceWrapper struct {
InputWrapper
}
// metric plugin is an input plugin used for actively pulling data.
type MetricWrapper struct {
InputWrapper
LatencyMetric pipeline.LatencyMetric
}
/*---------------------
Plugin Processor
The processor plugin is used for reading data.
---------------------*/
type ProcessorWrapper struct {
pipeline.PluginContext
Config *LogstoreConfig
inEventsTotal pipeline.CounterMetric
inSizeBytes pipeline.CounterMetric
outEventsTotal pipeline.CounterMetric
outSizeBytes pipeline.CounterMetric
totalProcessTimeMs pipeline.CounterMetric
}
func (wrapper *ProcessorWrapper) InitMetricRecord(pluginMeta *pipeline.PluginMeta) {
labels := helper.GetPluginCommonLabels(wrapper.Config.Context, pluginMeta)
wrapper.MetricRecord = wrapper.Config.Context.RegisterMetricRecord(labels)
wrapper.inEventsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginInEventsTotal)
wrapper.inSizeBytes = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginInSizeBytes)
wrapper.outEventsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutEventsTotal)
wrapper.outSizeBytes = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutSizeBytes)
wrapper.totalProcessTimeMs = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginTotalProcessTimeMs)
}
/*---------------------
Plugin Aggregator
The aggregator plugin is used for aggregating data.
---------------------*/
type AggregatorWrapper struct {
pipeline.PluginContext
Config *LogstoreConfig
Interval time.Duration
outEventsTotal pipeline.CounterMetric
outEventGroupsTotal pipeline.CounterMetric
outSizeBytes pipeline.CounterMetric
}
func (wrapper *AggregatorWrapper) InitMetricRecord(pluginMeta *pipeline.PluginMeta) {
labels := helper.GetPluginCommonLabels(wrapper.Config.Context, pluginMeta)
wrapper.MetricRecord = wrapper.Config.Context.RegisterMetricRecord(labels)
wrapper.outEventsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutEventsTotal)
wrapper.outEventGroupsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutEventGroupsTotal)
wrapper.outSizeBytes = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginOutSizeBytes)
}
/*---------------------
Plugin Flusher
The flusher plugin is used for sending data.
---------------------*/
type FlusherWrapperInterface interface {
Init(pluginMeta *pipeline.PluginMeta) error
IsReady(projectName string, logstoreName string, logstoreKey int64) bool
}
type FlusherWrapper struct {
pipeline.PluginContext
Config *LogstoreConfig
Interval time.Duration
inEventsTotal pipeline.CounterMetric
inEventGroupsTotal pipeline.CounterMetric
inSizeBytes pipeline.CounterMetric
totalDelayTimeMs pipeline.CounterMetric
}
func (wrapper *FlusherWrapper) InitMetricRecord(pluginMeta *pipeline.PluginMeta) {
labels := helper.GetPluginCommonLabels(wrapper.Config.Context, pluginMeta)
wrapper.MetricRecord = wrapper.Config.Context.RegisterMetricRecord(labels)
wrapper.inEventsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginInEventsTotal)
wrapper.inEventGroupsTotal = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginInEventGroupsTotal)
wrapper.inSizeBytes = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginInSizeBytes)
wrapper.totalDelayTimeMs = helper.NewCounterMetricAndRegister(wrapper.MetricRecord, helper.MetricPluginTotalDelayMs)
}