forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexing.go
84 lines (69 loc) · 2.04 KB
/
indexing.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
package add_kubernetes_metadata
import (
"sync"
"github.com/elastic/beats/libbeat/common"
)
// Indexing is the singleton Register instance where all Indexers and Matchers
// are stored
var Indexing = NewRegister()
// Register contains Indexer and Matchers to use on pod indexing and event matching
type Register struct {
sync.RWMutex
indexers map[string]IndexerConstructor
matchers map[string]MatcherConstructor
defaultIndexerConfigs map[string]common.Config
defaultMatcherConfigs map[string]common.Config
}
// NewRegister creates and returns a new Register.
func NewRegister() *Register {
return &Register{
indexers: make(map[string]IndexerConstructor, 0),
matchers: make(map[string]MatcherConstructor, 0),
defaultIndexerConfigs: make(map[string]common.Config, 0),
defaultMatcherConfigs: make(map[string]common.Config, 0),
}
}
// AddIndexer to the register
func (r *Register) AddIndexer(name string, indexer IndexerConstructor) {
r.RWMutex.Lock()
defer r.RWMutex.Unlock()
r.indexers[name] = indexer
}
// AddMatcher to the register
func (r *Register) AddMatcher(name string, matcher MatcherConstructor) {
r.RWMutex.Lock()
defer r.RWMutex.Unlock()
r.matchers[name] = matcher
}
// AddIndexer to the register
func (r *Register) AddDefaultIndexerConfig(name string, config common.Config) {
r.defaultIndexerConfigs[name] = config
}
// AddMatcher to the register
func (r *Register) AddDefaultMatcherConfig(name string, config common.Config) {
r.defaultMatcherConfigs[name] = config
}
// AddIndexer to the register
func (r *Register) GetIndexer(name string) IndexerConstructor {
indexer, ok := r.indexers[name]
if ok {
return indexer
} else {
return nil
}
}
// AddMatcher to the register
func (r *Register) GetMatcher(name string) MatcherConstructor {
matcher, ok := r.matchers[name]
if ok {
return matcher
} else {
return nil
}
}
func (r *Register) GetDefaultIndexerConfigs() map[string]common.Config {
return r.defaultIndexerConfigs
}
func (r *Register) GetDefaultMatcherConfigs() map[string]common.Config {
return r.defaultMatcherConfigs
}