-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
types.go
84 lines (73 loc) · 3.35 KB
/
types.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package listeners
import (
"context"
"errors"
"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/util/containers"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
// ContainerPort represents a network port in a Service.
type ContainerPort struct {
Port int
Name string
}
// Service represents an application we can run a check against.
// It should be matched with a check template by the ConfigResolver using the
// ADIdentifiers field.
type Service interface {
GetServiceID() string // unique service name
GetTaggerEntity() string // tagger entity name
GetADIdentifiers(context.Context) ([]string, error) // identifiers on which templates will be matched
GetHosts(context.Context) (map[string]string, error) // network --> IP address
GetPorts(context.Context) ([]ContainerPort, error) // network ports
GetTags() ([]string, error) // tags
GetPid(context.Context) (int, error) // process identifier
GetHostname(context.Context) (string, error) // hostname.domainname for the entity
IsReady(context.Context) bool // is the service ready
GetCheckNames(context.Context) []string // slice of check names defined in kubernetes annotations or container labels
HasFilter(containers.FilterType) bool // whether the service is excluded by metrics or logs exclusion config
GetExtraConfig(string) (string, error) // Extra configuration values
// FilterTemplates filters the templates which will be resolved against
// this service, in a map keyed by template digest.
//
// This method is called every time the configs for the service change,
// with the full set of templates matching this service. It must not rely
// on any non-static information except the given configs, and it must not
// modify the configs in the map.
FilterTemplates(map[string]integration.Config)
}
// ServiceListener monitors running services and triggers check (un)scheduling
//
// It holds a cache of running services, listens to new/killed services and
// updates its cache, and the autoconfig with these events.
type ServiceListener interface {
Listen(newSvc, delSvc chan<- Service)
Stop()
}
// Config represents autodiscovery listener config
type Config interface {
IsProviderEnabled(string) bool
}
// ServiceListenerFactory builds a service listener
type ServiceListenerFactory func(Config) (ServiceListener, error)
// Register registers a service listener factory
func Register(name string,
factory ServiceListenerFactory,
serviceListenerFactories map[string]ServiceListenerFactory) {
if factory == nil {
log.Infof("Service listener factory %s does not exist.", name)
return
}
_, registered := serviceListenerFactories[name]
if registered {
log.Errorf("Service listener factory %s already registered. Ignoring.", name)
return
}
serviceListenerFactories[name] = factory
}
// ErrNotSupported is thrown if listener doesn't support the asked variable
var ErrNotSupported = errors.New("AD: variable not supported by listener")