-
Notifications
You must be signed in to change notification settings - Fork 24
/
log_analytics.go
65 lines (54 loc) · 1.91 KB
/
log_analytics.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
package loganalytics
import (
"context"
jsoniter "github.com/json-iterator/go"
"github.com/observiq/stanza/v2/operator/builtin/input/azure"
"github.com/open-telemetry/opentelemetry-log-collection/operator"
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper"
)
const operatorName = "azure_log_analytics_input"
func init() {
operator.Register(operatorName, func() operator.Builder { return NewLogAnalyticsConfig("") })
}
// NewLogAnalyticsConfig creates a new Azure Log Analytics input config with default values
func NewLogAnalyticsConfig(operatorID string) *LogAnalyticsInputConfig {
return &LogAnalyticsInputConfig{
InputConfig: helper.NewInputConfig(operatorID, operatorName),
AzureConfig: azure.AzureConfig{
PrefetchCount: 1000,
StartAt: "end",
},
}
}
// LogAnalyticsInputConfig is the configuration of a Azure Log Analytics input operator.
type LogAnalyticsInputConfig struct {
helper.InputConfig `yaml:",inline"`
azure.AzureConfig `yaml:",inline"`
}
// Build will build a Azure Log Analytics input operator.
func (c *LogAnalyticsInputConfig) Build(buildContext operator.BuildContext) ([]operator.Operator, error) {
if err := c.AzureConfig.Build(buildContext, c.InputConfig); err != nil {
return nil, err
}
logAnalyticsInput := &LogAnalyticsInput{
EventHub: azure.EventHub{
AzureConfig: c.AzureConfig,
},
json: jsoniter.ConfigFastest,
}
return []operator.Operator{logAnalyticsInput}, nil
}
// LogAnalyticsInput is an operator that reads Azure Log Analytics input from Azure Event Hub.
type LogAnalyticsInput struct {
azure.EventHub
json jsoniter.API
}
// Start will start generating log entries.
func (l *LogAnalyticsInput) Start(persister operator.Persister) error {
l.Handler = l.handleBatchedEvents
return l.StartConsumers(context.Background(), persister)
}
// Stop will stop generating logs.
func (l *LogAnalyticsInput) Stop() error {
return l.StopConsumers()
}