Skip to content

feat: add all bundled otel config to the observe-agent binary instead of relying on files on disk #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install qemu
uses: docker/setup-qemu-action@v3
- name: Run GoReleaser
timeout-minutes: 18
timeout-minutes: 25
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Run GoReleaser
timeout-minutes: 18
timeout-minutes: 25
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Run GoReleaser
timeout-minutes: 18
timeout-minutes: 25
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install qemu
uses: docker/setup-qemu-action@v3
- name: Run GoReleaser
timeout-minutes: 18
timeout-minutes: 25
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
Expand Down
22 changes: 14 additions & 8 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ builds:
- linux
ldflags: -s -w -X github.com/observeinc/observe-agent/build.Version={{.Version}}

- id: docker_build
binary: observe-agent
env:
- CGO_ENABLED=0
goos:
- linux
flags:
- -tags=docker
ldflags: -s -w -X github.com/observeinc/observe-agent/build.Version={{.Version}}

- id: mac_build
binary: observe-agent
env:
Expand Down Expand Up @@ -59,8 +69,6 @@ archives:
# The default agent config file and the service file live in config.
- src: "packaging/linux/config/*"
dst: "."
- src: "packaging/linux/connections/*"
dst: "connections"

- id: windows
formats: ["zip"]
Expand All @@ -75,8 +83,6 @@ archives:
files:
- src: "packaging/windows/observe-agent.yaml"
dst: "observe-agent.yaml"
- src: "packaging/windows/connections/*"
dst: "connections"

- id: macos
formats: ["zip"]
Expand Down Expand Up @@ -120,6 +126,8 @@ changelog:
nfpms:
- id: linux

ids: [linux_build]

package_name: observe-agent

# You can change the file name of the package.
Expand Down Expand Up @@ -162,10 +170,6 @@ nfpms:
# Contents to add to the package.
# GoReleaser will automatically add the binaries.
contents:
- src: packaging/linux/connections
dst: /etc/observe-agent/connections
type: tree

- src: packaging/linux/config/observe-agent.yaml
dst: /etc/observe-agent/observe-agent.yaml
type: config|noreplace
Expand Down Expand Up @@ -200,6 +204,7 @@ dockers:
use: buildx
goos: linux
goarch: amd64
ids: [docker_build]
build_flag_templates:
- "--platform=linux/amd64"
extra_files:
Expand All @@ -211,6 +216,7 @@ dockers:
use: buildx
goos: linux
goarch: arm64
ids: [docker_build]
build_flag_templates:
- "--platform=linux/arm64/v8"
extra_files:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build:
go build ./...

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

## test: Runs Go tests across all packages
Expand Down
1 change: 0 additions & 1 deletion integration/scripts/install_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ Expand-Archive -Force -LiteralPath $local_installer -DestinationPath "$temp_dir
Write-Output "Copying files from $temp_dir\observe-agent_extract to $observeagent_install_dir"
Copy-Item -Force -Path $temp_dir\observe-agent_extract\observe-agent.exe -Destination $observeagent_install_dir
Copy-Item -Force -Path $temp_dir\observe-agent_extract\observe-agent.yaml -Destination $observeagent_install_dir
Copy-Item -Force -Path $temp_dir\observe-agent_extract\connections\* -Destination $observeagent_install_dir\connections -Recurse
Get-ChildItem -Path $observeagent_install_dir -Recurse
19 changes: 12 additions & 7 deletions internal/commands/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package config
import (
"bytes"
"context"
"embed"
"os"
"path"
"path/filepath"
Expand All @@ -15,6 +16,7 @@ import (

"github.com/observeinc/observe-agent/internal/commands/util/logger"
"github.com/observeinc/observe-agent/internal/connections"
"github.com/observeinc/observe-agent/internal/connections/bundledconfig"
"github.com/observeinc/observe-agent/internal/root"
"github.com/observeinc/observe-agent/observecol"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -109,7 +111,7 @@ func runSnapshotTest(t *testing.T, test snapshotTest) {

// Set the template base dir for all connections
for _, conn := range connections.AllConnectionTypes {
conn.ApplyOptions(connections.WithConfigFolderPath(getPackagingPath(t, test.packageType, curPath)))
conn.ApplyOptions(connections.WithConfigTemplateOverrides(getTemplateOverrides(t, test.packageType, curPath)))
}

// Set config flags
Expand All @@ -132,16 +134,19 @@ func runSnapshotTest(t *testing.T, test snapshotTest) {
assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(output.String()))
}

func getPackagingPath(t *testing.T, packageType PackageType, curPath string) string {
const packagingPath = "../../../packaging"
func getTemplateOverrides(t *testing.T, packageType PackageType, curPath string) map[string]embed.FS {
switch packageType {
case MacOS, Linux, Windows:
return filepath.Join(curPath, packagingPath, string(packageType), "connections")
case MacOS:
return bundledconfig.MacOSTemplateFS
case Linux:
return bundledconfig.LinuxTemplateFS
case Windows:
return bundledconfig.WindowsTemplateFS
case Docker:
return filepath.Join(curPath, packagingPath, "docker/observe-agent/connections")
return bundledconfig.DockerTemplateFS
default:
t.Errorf("Unknown package type: %s", packageType)
return ""
return nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/commands/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getStatusFromTemplate(v *viper.Viper) error {
return err
}
t := template.Must(template.New(statusTemplate).
Funcs(connections.GetTemplateFuncMap()).
Funcs(connections.TemplateFuncMap).
ParseFS(statusTemplateFS, statusTemplate))
if err := t.ExecuteTemplate(os.Stdout, statusTemplate, data); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions internal/connections/allconnectiontypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var CommonConnectionType = MakeConnectionType(
func(_ *config.AgentConfig) bool {
return true
},
[]CollectorConfigFragment{
[]BundledConfigFragment{
{
enabledCheck: func(_ *config.AgentConfig) bool {
// Always include the base connection.
Expand Down Expand Up @@ -55,7 +55,7 @@ var HostMonitoringConnectionType = MakeConnectionType(
func(agentConfig *config.AgentConfig) bool {
return agentConfig.HostMonitoring.Enabled
},
[]CollectorConfigFragment{
[]BundledConfigFragment{
{
enabledCheck: func(agentConfig *config.AgentConfig) bool {
// TODO remove this deprecated template
Expand Down Expand Up @@ -89,7 +89,7 @@ var SelfMonitoringConnectionType = MakeConnectionType(
func(agentConfig *config.AgentConfig) bool {
return agentConfig.SelfMonitoring.Enabled
},
[]CollectorConfigFragment{
[]BundledConfigFragment{
{
enabledCheck: func(agentConfig *config.AgentConfig) bool {
return agentConfig.SelfMonitoring.Enabled
Expand Down
46 changes: 46 additions & 0 deletions internal/connections/bundledconfig/bundledconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bundledconfig

import (
"embed"

"github.com/observeinc/observe-agent/internal/connections/bundledconfig/docker"
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/linux"
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/shared"
"github.com/observeinc/observe-agent/internal/connections/bundledconfig/windows"
)

// TODO break up some of the larger connections in order to share more configs.
var SharedTemplateFS = map[string]embed.FS{
"common/attributes.yaml.tmpl": shared.AttributesTemplateFS,
"common/internal_telemetry.yaml.tmpl": shared.InternalTelemetryTemplateFS,
"common/health_check.yaml.tmpl": shared.HealthCheckTemplateFS,
"common/base.yaml.tmpl": shared.BaseTemplateFS,
"common/forward.yaml.tmpl": shared.ForwardTemplateFS,
"host_monitoring/logs.yaml.tmpl": shared.LogsTemplateFS,
"host_monitoring/host_metrics.yaml.tmpl": shared.HostMetricsTemplateFS,
"host_monitoring/host.yaml.tmpl": shared.HostTemplateFS,
"host_monitoring/process_metrics.yaml.tmpl": shared.ProcessMetricsTemplateFS,
"self_monitoring/logs_and_metrics.yaml.tmpl": shared.LogsAndMetricsTemplateFS,
}

var DockerTemplateFS = map[string]embed.FS{
"common/base.yaml.tmpl": docker.BaseTemplateFS,
"host_monitoring/logs.yaml.tmpl": docker.LogsTemplateFS,
"host_monitoring/host_metrics.yaml.tmpl": docker.HostMetricsTemplateFS,
"host_monitoring/process_metrics.yaml.tmpl": docker.ProcessMetricsTemplateFS,
"self_monitoring/logs_and_metrics.yaml.tmpl": docker.LogsAndMetricsTemplateFS,
}

var LinuxTemplateFS = map[string]embed.FS{
"host_monitoring/logs.yaml.tmpl": linux.LogsTemplateFS,
"host_monitoring/host_metrics.yaml.tmpl": linux.HostMetricsTemplateFS,
"self_monitoring/logs_and_metrics.yaml.tmpl": linux.LogsAndMetricsTemplateFS,
}

var MacOSTemplateFS = map[string]embed.FS{}

var WindowsTemplateFS = map[string]embed.FS{
"common/base.yaml.tmpl": windows.BaseTemplateFS,
"host_monitoring/logs.yaml.tmpl": windows.LogsTemplateFS,
"host_monitoring/host_metrics.yaml.tmpl": windows.HostMetricsTemplateFS,
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to cgroup extensions */ -}}
extensions:
file_storage:
directory: ${env:FILESTORAGE_PATH}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to hostfs root path */ -}}
receivers:
hostmetrics/host-monitoring-host:
collection_interval: 60s
Expand Down Expand Up @@ -26,6 +27,7 @@ receivers:
system.filesystem.utilization:
enabled: true
network:
{{- /* TODO: add system.network.conntrack metrics, copy from the shared file */}}
paging:
metrics:
system.paging.utilization:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to hostfs root path and journald receiver */ -}}
receivers:
filelog/host_monitoring:
include:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to hostfs root path */ -}}
receivers:
hostmetrics/host-monitoring-process:
collection_interval: 60s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- /* Forked from the default due to journald receiver */ -}}
receivers:
# TODO: Add observe-agent.yaml once we can obfuscate sensitive config fields

{{- /* TODO update this to pull from the internal telemetry config */}}
prometheus/agent:
config:
scrape_configs:
Expand Down Expand Up @@ -37,6 +39,11 @@ service:
- batch
exporters: [prometheusremotewrite/observe]

# Deprecated
logs/agent-config:
receivers: [nop]
exporters: [nop]

logs/agent-journald:
receivers: [journald/agent]
processors:
Expand All @@ -52,8 +59,3 @@ service:
{{- end }}
- batch
exporters: [otlphttp/observe, count]

# Deprecated
logs/agent-config:
receivers: [nop]
exporters: [nop]
16 changes: 16 additions & 0 deletions internal/connections/bundledconfig/docker/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package docker

import "embed"

var (
//go:embed common/base.yaml.tmpl
BaseTemplateFS embed.FS
//go:embed host_monitoring/logs.yaml.tmpl
LogsTemplateFS embed.FS
//go:embed host_monitoring/host_metrics.yaml.tmpl
HostMetricsTemplateFS embed.FS
//go:embed host_monitoring/process_metrics.yaml.tmpl
ProcessMetricsTemplateFS embed.FS
//go:embed self_monitoring/logs_and_metrics.yaml.tmpl
LogsAndMetricsTemplateFS embed.FS
)
9 changes: 9 additions & 0 deletions internal/connections/bundledconfig/docker_defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build linux && docker

package bundledconfig

import (
"embed"
)

var OverrideTemplates map[string]embed.FS = DockerTemplateFS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to system.linux.memory.available metric */ -}}
receivers:
hostmetrics/host-monitoring-host:
collection_interval: 60s
Expand Down Expand Up @@ -25,6 +26,7 @@ receivers:
system.filesystem.utilization:
enabled: true
network:
{{- /* TODO: add system.network.conntrack metrics, copy from the shared file */}}
paging:
metrics:
system.paging.utilization:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* Forked from the default due to journald receiver */ -}}
receivers:
filelog/host_monitoring:
include:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- /* Forked from the default due to journald receiver */ -}}
receivers:
# TODO: Add observe-agent.yaml once we can obfuscate sensitive config fields

{{- /* TODO update this to pull from the internal telemetry config */}}
prometheus/agent:
config:
scrape_configs:
Expand Down Expand Up @@ -37,6 +39,11 @@ service:
- batch
exporters: [prometheusremotewrite/observe]

# Deprecated
logs/agent-config:
receivers: [nop]
exporters: [nop]

logs/agent-journald:
receivers: [journald/agent]
processors:
Expand All @@ -52,8 +59,3 @@ service:
{{- end }}
- batch
exporters: [otlphttp/observe, count]

# Deprecated
logs/agent-config:
receivers: [nop]
exporters: [nop]
Loading
Loading