forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.go
88 lines (73 loc) · 3.14 KB
/
common.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
85
86
87
88
// 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 common provides a set of common symbols needed by different packages,
// to avoid circular dependencies.
package common
import (
"context"
"encoding/json"
"fmt"
"net/http"
"path/filepath"
"github.com/StackVista/stackstate-agent/pkg/api/util"
"github.com/StackVista/stackstate-agent/pkg/autodiscovery"
"github.com/StackVista/stackstate-agent/pkg/collector"
"github.com/StackVista/stackstate-agent/pkg/config"
"github.com/StackVista/stackstate-agent/pkg/config/settings"
settingshttp "github.com/StackVista/stackstate-agent/pkg/config/settings/http"
"github.com/StackVista/stackstate-agent/pkg/dogstatsd"
"github.com/StackVista/stackstate-agent/pkg/forwarder"
"github.com/StackVista/stackstate-agent/pkg/metadata"
"github.com/StackVista/stackstate-agent/pkg/otlp"
"github.com/StackVista/stackstate-agent/pkg/util/executable"
"github.com/StackVista/stackstate-agent/pkg/version"
)
var (
// AC is the global object orchestrating checks' loading and running
AC *autodiscovery.AutoConfig
// Coll is the global collector instance
Coll *collector.Collector
// DSD is the global dogstatsd instance
DSD *dogstatsd.Server
// OTLP is the global OTLP pipeline instance
OTLP *otlp.Pipeline
// MetadataScheduler is responsible to orchestrate metadata collection
MetadataScheduler *metadata.Scheduler
// Forwarder is the global forwarder instance
Forwarder forwarder.Forwarder
// MainCtx is the main agent context passed to components
MainCtx context.Context
// MainCtxCancel cancels the main agent context
MainCtxCancel context.CancelFunc
// utility variables
_here, _ = executable.Folder()
)
// GetPythonPaths returns the paths (in order of precedence) from where the agent
// should load python modules and checks
func GetPythonPaths() []string {
// wheels install in default site - already in sys.path; takes precedence over any additional location
return []string{
GetDistPath(), // common modules are shipped in the dist path directly or under the "checks/" sub-dir
PyChecksPath, // integrations-core legacy checks
filepath.Join(GetDistPath(), "checks.d"), // custom checks in the "checks.d/" sub-dir of the dist path
config.Datadog.GetString("additional_checksd"), // custom checks, least precedent check location
}
}
// GetVersion returns the version of the agent in a http response json
func GetVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
av, _ := version.Agent()
j, _ := json.Marshal(av)
w.Write(j)
}
// NewSettingsClient returns a configured runtime settings client.
func NewSettingsClient() (settings.Client, error) {
ipcAddress, err := config.GetIPCAddress()
if err != nil {
return nil, err
}
hc := util.GetClient(false)
return settingshttp.NewClient(hc, fmt.Sprintf("https://%v:%v/agent/config", ipcAddress, config.Datadog.GetInt("cmd_port")), "agent"), nil
}