Skip to content

Commit a17a1bf

Browse files
feat: add all bundled otel config to the observe-agent binary instead of relying on files on disk
1 parent 78f61a0 commit a17a1bf

File tree

59 files changed

+300
-789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+300
-789
lines changed

.goreleaser.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ builds:
2424
- linux
2525
ldflags: -s -w -X github.com/observeinc/observe-agent/build.Version={{.Version}}
2626

27+
- id: docker_build
28+
binary: observe-agent
29+
env:
30+
- CGO_ENABLED=0
31+
goos:
32+
- linux
33+
flags:
34+
- -tags=docker
35+
ldflags: -s -w -X github.com/observeinc/observe-agent/build.Version={{.Version}}
36+
2737
- id: mac_build
2838
binary: observe-agent
2939
env:
@@ -59,8 +69,6 @@ archives:
5969
# The default agent config file and the service file live in config.
6070
- src: "packaging/linux/config/*"
6171
dst: "."
62-
- src: "packaging/linux/connections/*"
63-
dst: "connections"
6472

6573
- id: windows
6674
formats: ["zip"]
@@ -75,8 +83,6 @@ archives:
7583
files:
7684
- src: "packaging/windows/observe-agent.yaml"
7785
dst: "observe-agent.yaml"
78-
- src: "packaging/windows/connections/*"
79-
dst: "connections"
8086

8187
- id: macos
8288
formats: ["zip"]
@@ -120,6 +126,8 @@ changelog:
120126
nfpms:
121127
- id: linux
122128

129+
ids: [linux_build]
130+
123131
package_name: observe-agent
124132

125133
# You can change the file name of the package.
@@ -162,10 +170,6 @@ nfpms:
162170
# Contents to add to the package.
163171
# GoReleaser will automatically add the binaries.
164172
contents:
165-
- src: packaging/linux/connections
166-
dst: /etc/observe-agent/connections
167-
type: tree
168-
169173
- src: packaging/linux/config/observe-agent.yaml
170174
dst: /etc/observe-agent/observe-agent.yaml
171175
type: config|noreplace
@@ -200,6 +204,7 @@ dockers:
200204
use: buildx
201205
goos: linux
202206
goarch: amd64
207+
ids: [docker_build]
203208
build_flag_templates:
204209
- "--platform=linux/amd64"
205210
extra_files:
@@ -211,6 +216,7 @@ dockers:
211216
use: buildx
212217
goos: linux
213218
goarch: arm64
219+
ids: [docker_build]
214220
build_flag_templates:
215221
- "--platform=linux/arm64/v8"
216222
extra_files:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ build:
3131
go build ./...
3232

3333
docker-image:
34-
env GOOS=linux GOARCH=arm64 go build -o observe-agent
34+
env GOOS=linux GOARCH=arm64 go build -tags docker -o observe-agent
3535
docker build -f packaging/docker/Dockerfile -t observe-agent:dev .
3636

3737
## test: Runs Go tests across all packages

internal/commands/config/config_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package config
66
import (
77
"bytes"
88
"context"
9+
"embed"
910
"os"
1011
"path"
1112
"path/filepath"
@@ -15,6 +16,7 @@ import (
1516

1617
"github.com/observeinc/observe-agent/internal/commands/util/logger"
1718
"github.com/observeinc/observe-agent/internal/connections"
19+
"github.com/observeinc/observe-agent/internal/connections/bundledconfig"
1820
"github.com/observeinc/observe-agent/internal/root"
1921
"github.com/observeinc/observe-agent/observecol"
2022
"github.com/spf13/pflag"
@@ -88,7 +90,8 @@ func runSnapshotTest(t *testing.T, test snapshotTest) {
8890

8991
// Set the template base dir for all connections
9092
for _, conn := range connections.AllConnectionTypes {
91-
conn.ApplyOptions(connections.WithConfigFolderPath(getPackagingPath(t, test.packageType, curPath)))
93+
// TODO
94+
conn.ApplyOptions(connections.WithConfigTemplateOverrides(getTemplateOverrides(t, test.packageType, curPath)))
9295
}
9396

9497
// Set config flags
@@ -111,16 +114,19 @@ func runSnapshotTest(t *testing.T, test snapshotTest) {
111114
assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(output.String()))
112115
}
113116

114-
func getPackagingPath(t *testing.T, packageType PackageType, curPath string) string {
115-
const packagingPath = "../../../packaging"
117+
func getTemplateOverrides(t *testing.T, packageType PackageType, curPath string) map[string]embed.FS {
116118
switch packageType {
117-
case MacOS, Linux, Windows:
118-
return filepath.Join(curPath, packagingPath, string(packageType), "connections")
119+
case MacOS:
120+
return bundledconfig.MacOSTemplateFS
121+
case Linux:
122+
return bundledconfig.LinuxTemplateFS
123+
case Windows:
124+
return bundledconfig.WindowsTemplateFS
119125
case Docker:
120-
return filepath.Join(curPath, packagingPath, "docker/observe-agent/connections")
126+
return bundledconfig.DockerTemplateFS
121127
default:
122128
t.Errorf("Unknown package type: %s", packageType)
123-
return ""
129+
return nil
124130
}
125131
}
126132

internal/commands/status/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func getStatusFromTemplate(v *viper.Viper) error {
4949
return err
5050
}
5151
t := template.Must(template.New(statusTemplate).
52-
Funcs(connections.GetTemplateFuncMap()).
52+
Funcs(connections.TemplateFuncMap).
5353
ParseFS(statusTemplateFS, statusTemplate))
5454
if err := t.ExecuteTemplate(os.Stdout, statusTemplate, data); err != nil {
5555
return err

internal/connections/allconnectiontypes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var CommonConnectionType = MakeConnectionType(
1515
func(_ *config.AgentConfig) bool {
1616
return true
1717
},
18-
[]CollectorConfigFragment{
18+
[]BundledConfigFragment{
1919
{
2020
enabledCheck: func(_ *config.AgentConfig) bool {
2121
// Always include the base connection.
@@ -55,7 +55,7 @@ var HostMonitoringConnectionType = MakeConnectionType(
5555
func(agentConfig *config.AgentConfig) bool {
5656
return agentConfig.HostMonitoring.Enabled
5757
},
58-
[]CollectorConfigFragment{
58+
[]BundledConfigFragment{
5959
{
6060
enabledCheck: func(agentConfig *config.AgentConfig) bool {
6161
// TODO remove this deprecated template
@@ -89,7 +89,7 @@ var SelfMonitoringConnectionType = MakeConnectionType(
8989
func(agentConfig *config.AgentConfig) bool {
9090
return agentConfig.SelfMonitoring.Enabled
9191
},
92-
[]CollectorConfigFragment{
92+
[]BundledConfigFragment{
9393
{
9494
enabledCheck: func(agentConfig *config.AgentConfig) bool {
9595
return agentConfig.SelfMonitoring.Enabled
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package bundledconfig
2+
3+
import (
4+
"embed"
5+
6+
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/docker"
7+
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/linux"
8+
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/shared"
9+
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/windows"
10+
)
11+
12+
// TODO break up some of the larger connections in order to share more configs.
13+
var SharedTemplateFS = map[string]embed.FS{
14+
"common/attributes.yaml.tmpl": shared.AttributesTemplateFS,
15+
"common/internal_telemetry.yaml.tmpl": shared.InternalTelemetryTemplateFS,
16+
"common/health_check.yaml.tmpl": shared.HealthCheckTemplateFS,
17+
"common/base.yaml.tmpl": shared.BaseTemplateFS,
18+
"common/forward.yaml.tmpl": shared.ForwardTemplateFS,
19+
"host_monitoring/logs.yaml.tmpl": shared.LogsTemplateFS,
20+
"host_monitoring/host_metrics.yaml.tmpl": shared.HostMetricsTemplateFS,
21+
"host_monitoring/host.yaml.tmpl": shared.HostTemplateFS,
22+
"host_monitoring/process_metrics.yaml.tmpl": shared.ProcessMetricsTemplateFS,
23+
"self_monitoring/logs_and_metrics.yaml.tmpl": shared.LogsAndMetricsTemplateFS,
24+
}
25+
26+
var DockerTemplateFS = map[string]embed.FS{
27+
"common/base.yaml.tmpl": docker.BaseTemplateFS,
28+
"host_monitoring/logs.yaml.tmpl": docker.LogsTemplateFS,
29+
"host_monitoring/host_metrics.yaml.tmpl": docker.HostMetricsTemplateFS,
30+
"host_monitoring/process_metrics.yaml.tmpl": docker.ProcessMetricsTemplateFS,
31+
"self_monitoring/logs_and_metrics.yaml.tmpl": docker.LogsAndMetricsTemplateFS,
32+
}
33+
34+
var LinuxTemplateFS = map[string]embed.FS{
35+
"host_monitoring/logs.yaml.tmpl": linux.LogsTemplateFS,
36+
"host_monitoring/host_metrics.yaml.tmpl": linux.HostMetricsTemplateFS,
37+
"self_monitoring/logs_and_metrics.yaml.tmpl": linux.LogsAndMetricsTemplateFS,
38+
}
39+
40+
var MacOSTemplateFS = map[string]embed.FS{}
41+
42+
var WindowsTemplateFS = map[string]embed.FS{
43+
"common/base.yaml.tmpl": windows.BaseTemplateFS,
44+
"host_monitoring/logs.yaml.tmpl": windows.LogsTemplateFS,
45+
"host_monitoring/host_metrics.yaml.tmpl": windows.HostMetricsTemplateFS,
46+
}

packaging/docker/observe-agent/connections/common/base.yaml.tmpl renamed to internal/connections/bundledconfig/docker/common/base.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- /* Forked from the default due to cgroup extensions */ -}}
12
extensions:
23
file_storage:
34
directory: ${env:FILESTORAGE_PATH}

packaging/docker/observe-agent/connections/host_monitoring/host_metrics.yaml.tmpl renamed to internal/connections/bundledconfig/docker/host_monitoring/host_metrics.yaml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- /* Forked from the default due to hostfs root path */ -}}
12
receivers:
23
hostmetrics/host-monitoring-host:
34
collection_interval: 60s
@@ -26,6 +27,7 @@ receivers:
2627
system.filesystem.utilization:
2728
enabled: true
2829
network:
30+
{{- /* TODO: add system.network.conntrack metrics, copy from the shared file */}}
2931
paging:
3032
metrics:
3133
system.paging.utilization:

packaging/docker/observe-agent/connections/host_monitoring/logs.yaml.tmpl renamed to internal/connections/bundledconfig/docker/host_monitoring/logs.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- /* Forked from the default due to hostfs root path and journald receiver */ -}}
12
receivers:
23
filelog/host_monitoring:
34
include:

packaging/docker/observe-agent/connections/host_monitoring/process_metrics.yaml.tmpl renamed to internal/connections/bundledconfig/docker/host_monitoring/process_metrics.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- /* Forked from the default due to hostfs root path */ -}}
12
receivers:
23
hostmetrics/host-monitoring-process:
34
collection_interval: 60s

0 commit comments

Comments
 (0)