forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_common.go
More file actions
58 lines (49 loc) · 2.12 KB
/
Copy pathtest_common.go
File metadata and controls
58 lines (49 loc) · 2.12 KB
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
// 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.
//go:build test
package aggregator
import (
"errors"
log "github.com/DataDog/datadog-agent/comp/core/log/def"
secretnooptypes "github.com/DataDog/datadog-agent/comp/core/secrets/noop-impl/types"
defaultforwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/def"
defaultforwarderimpl "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/impl"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/metrics"
)
// PeekSender returns a Sender with passed ID or an error if the sender is not registered
func (s *senders) PeekSender(cid checkid.ID) (sender.Sender, error) {
return s.senderPool.getSender(cid)
}
// PeekSender returns a Sender with passed ID or an error if the sender is not registered
func (d *AgentDemultiplexer) PeekSender(cid checkid.ID) (sender.Sender, error) {
d.m.Lock()
defer d.m.Unlock()
if d.senders == nil {
return nil, errors.New("demultiplexer is stopped")
}
return d.senders.PeekSender(cid)
}
func NewForwarderTest(log log.Component) defaultforwarder.Forwarder {
options, _ := defaultforwarderimpl.NewOptions(pkgconfigsetup.Datadog(), log, nil)
options.Secrets = &secretnooptypes.SecretNoop{}
return defaultforwarderimpl.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, options)
}
// GetRecurrentSeries returns a copy of the recurrent series for testing
func GetRecurrentSeries() []*metrics.Serie {
recurrentSeriesLock.Lock()
defer recurrentSeriesLock.Unlock()
result := make([]*metrics.Serie, len(recurrentSeries))
copy(result, recurrentSeries)
return result
}
// ClearRecurrentSeries clears the recurrent series for testing
func ClearRecurrentSeries() {
recurrentSeriesLock.Lock()
defer recurrentSeriesLock.Unlock()
recurrentSeries = metrics.Series{}
}