-
Notifications
You must be signed in to change notification settings - Fork 122
/
k8s_integrations.go
67 lines (57 loc) · 1.81 KB
/
k8s_integrations.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
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build linux || darwin
// +build linux darwin
package plugins
import (
"time"
"github.com/newrelic/infrastructure-agent/internal/agent"
"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/entity"
"github.com/newrelic/infrastructure-agent/pkg/plugins/ids"
)
type pluginRetrieve func() []agent.Plugin
// Plugin that links integrations to the pod they are monitoring
type K8sIntegrationsPlugin struct {
agent.PluginCommon
pluginsRetrieve pluginRetrieve
frequency time.Duration
}
func NewK8sIntegrationsPlugin(ctx agent.AgentContext, pluginRetrieveFn pluginRetrieve) agent.Plugin {
cfg := ctx.Config()
p := &K8sIntegrationsPlugin{
PluginCommon: agent.PluginCommon{
ID: ids.PluginID{
Category: "metadata",
Term: "k8s_integrations",
},
Context: ctx,
},
pluginsRetrieve: pluginRetrieveFn,
frequency: config.ValidateConfigFrequencySetting(
cfg.K8sIntegrationSamplesIntervalSec,
config.FREQ_MINIMUM_FAST_INVENTORY_SAMPLE_RATE,
config.FREQ_PLUGIN_K8S_INTEGRATION_SAMPLES_UPDATES,
cfg.DisableAllPlugins,
) * time.Second,
}
return p
}
func (kip *K8sIntegrationsPlugin) Run() {
kip.Context.AddReconnecting(kip)
entityKey := kip.Context.EntityKey()
refreshTimer := time.NewTicker(kip.frequency)
for range refreshTimer.C {
for _, plugin := range kip.pluginsRetrieve() {
if plugin.IsExternal() {
kip.EmitEvent(kip.k8sIntegrationSample(plugin.GetExternalPluginName()), entity.Key(entityKey))
}
}
}
}
func (kip *K8sIntegrationsPlugin) k8sIntegrationSample(integrationName string) map[string]interface{} {
return map[string]interface{}{
"integrationName": integrationName,
"eventType": "K8sIntegrationSample",
}
}