Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 275e718

Browse files
Host Observer: Add OmitPIDDimension config option (#1517)
1 parent a0d174e commit 275e718

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

docs/observers/host.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Observer Type: `host`
1818

1919
| Config option | Required | Type | Description |
2020
| --- | --- | --- | --- |
21+
| `omitPIDDimension` | no | `bool` | If `true`, the `pid` dimension will be omitted from the generated endpoints, which means it will not appear on datapoints emitted by monitors instantiated from discovery rules matching this endpoint. (**default:** `false`) |
2122
| `pollIntervalSeconds` | no | `integer` | (**default:** `10`) |
2223

2324

pkg/observers/host/host.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ type Observer struct {
4747
// Config specific to the host observer
4848
type Config struct {
4949
config.ObserverConfig
50-
PollIntervalSeconds int `default:"10" yaml:"pollIntervalSeconds"`
50+
// If `true`, the `pid` dimension will be omitted from the generated
51+
// endpoints, which means it will not appear on datapoints emitted by
52+
// monitors instantiated from discovery rules matching this endpoint.
53+
OmitPIDDimension bool `default:"false" yaml:"omitPIDDimension"`
54+
PollIntervalSeconds int `default:"10" yaml:"pollIntervalSeconds"`
5155
}
5256

5357
func init() {
@@ -138,8 +142,9 @@ func (o *Observer) discover() []services.Endpoint {
138142
continue
139143
}
140144

141-
dims := map[string]string{
142-
"pid": strconv.Itoa(int(pid)),
145+
dims := map[string]string{}
146+
if !o.config.OmitPIDDimension {
147+
dims["pid"] = strconv.Itoa(int(pid))
143148
}
144149

145150
for _, c := range conns {

pkg/observers/host/host_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ func Test_HostObserver(t *testing.T) {
105105
}
106106
}
107107

108+
t.Run("Omit PID", func(t *testing.T) {
109+
config.OmitPIDDimension = true
110+
defer func() { config.OmitPIDDimension = false }()
111+
tcpConns := openTestTCPPorts(t)
112+
startObserver()
113+
lock.Lock()
114+
require.True(t, len(endpoints) >= len(tcpConns))
115+
116+
for _, e := range endpoints {
117+
_, ok := e.Dimensions()["pid"]
118+
require.False(t, ok)
119+
}
120+
121+
lock.Unlock()
122+
o.Shutdown()
123+
})
124+
108125
t.Run("Basic connections", func(t *testing.T) {
109126
tcpConns := openTestTCPPorts(t)
110127
udpConns := openTestUDPPorts(t)
@@ -130,6 +147,9 @@ func Test_HostObserver(t *testing.T) {
130147
} else {
131148
require.Equal(t, e.DerivedFields()["is_ipv6"], false)
132149
}
150+
151+
_, ok := e.Dimensions()["pid"]
152+
require.True(t, ok)
133153
}
134154
})
135155

@@ -151,6 +171,9 @@ func Test_HostObserver(t *testing.T) {
151171
} else {
152172
require.Equal(t, e.DerivedFields()["is_ipv6"], false)
153173
}
174+
175+
_, ok := e.Dimensions()["pid"]
176+
require.True(t, ok)
154177
}
155178
})
156179

selfdescribe.json

+8
Original file line numberDiff line numberDiff line change
@@ -56127,6 +56127,14 @@
5612756127
"doc": " Looks at the current host for listening network endpoints.\nIt uses the `/proc` filesystem and requires the `SYS_PTRACE` and\n`DAC_READ_SEARCH` capabilities so that it can determine what processes own\nthe listening sockets.\n\nIt will look for all listening sockets on TCP and UDP over IPv4 and IPv6.\n",
5612856128
"package": "pkg/observers/host",
5612956129
"fields": [
56130+
{
56131+
"yamlName": "omitPIDDimension",
56132+
"doc": "If `true`, the `pid` dimension will be omitted from the generated endpoints, which means it will not appear on datapoints emitted by monitors instantiated from discovery rules matching this endpoint.",
56133+
"default": false,
56134+
"required": false,
56135+
"type": "bool",
56136+
"elementKind": ""
56137+
},
5613056138
{
5613156139
"yamlName": "pollIntervalSeconds",
5613256140
"doc": "",

0 commit comments

Comments
 (0)