Skip to content

feat: add mac support #129

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 4 commits into from
Nov 18, 2024
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
646 changes: 21 additions & 625 deletions .goreleaser.yaml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion integration/scripts/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ def _get_installation_package(env_vars: dict) -> tuple:
# Search criteria
package_type = env_vars["machine_config"]["package_type"]
architecture = env_vars["machine_config"]["architecture"]
distribution = env_vars["machine_config"]["distribution"]

print(f"Looking for installation package '{package_type}' and architecture '{architecture}'")

# Iterate through files and find matches
for filename in files:
if package_type in filename and architecture in filename:
if package_type in filename and architecture in filename:
# We can make this more general if need be.
if "windows" in distribution and "windows" not in filename.lower():
continue
full_path = os.path.join(dist_directory, filename)
print(f"Found matching file {filename} at: {full_path}")
return filename, full_path
u.die(f"❌ No matching file found for {distribution},{architecture},{package_type} in {dist_directory}: {', '.join(files)}")


@u.print_test_decorator
def run_test_windows(remote_host: u.Host, env_vars: dict) -> None:
Expand Down
14 changes: 7 additions & 7 deletions internal/connections/confighandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func GetOverrideConfigFile(sub *viper.Viper) (string, error) {
func GetDefaultConfigFolder() string {
switch currOS := runtime.GOOS; currOS {
case "darwin":
return GetDefaultAgentPath()
return filepath.Join(GetDefaultAgentPath(), "config")
case "windows":
return filepath.Join(GetDefaultAgentPath(), "config")
case "linux":
Expand All @@ -100,14 +100,14 @@ func GetDefaultConfigFolder() string {
}
}

func GetConfigFragmentFolderPath() string {
return filepath.Join(GetDefaultAgentPath(), "connections")
}

func GetDefaultAgentPath() string {
switch currOS := runtime.GOOS; currOS {
case "darwin":
homedir, err := os.UserHomeDir()
if err != nil {
return ""
}
return homedir
return "/usr/local/observe-agent"
case "windows":
return os.ExpandEnv("$ProgramFiles\\Observe\\observe-agent")
case "linux":
Expand All @@ -120,7 +120,7 @@ func GetDefaultAgentPath() string {
func GetDefaultFilestoragePath() string {
switch currOS := runtime.GOOS; currOS {
case "darwin":
return filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "Observe", "observe-agent", "filestorage")
return "/var/lib/observe-agent/filestorage"
case "windows":
return os.ExpandEnv("$ProgramData\\Observe\\observe-agent\\filestorage")
case "linux":
Expand Down
20 changes: 1 addition & 19 deletions internal/connections/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"text/template"

logger "github.com/observeinc/observe-agent/internal/commands/util"
Expand Down Expand Up @@ -34,23 +33,6 @@ type ConnectionType struct {
getConfig func() *viper.Viper
}

func GetConfigFolderPath() string {
switch currOS := runtime.GOOS; currOS {
case "darwin":
homedir, err := os.UserHomeDir()
if err != nil {
return ""
}
return filepath.Join(homedir, ".observe-agent/connections")
case "windows":
return os.ExpandEnv("$ProgramFiles\\Observe\\observe-agent\\connections")
case "linux":
return "/etc/observe-agent/connections"
default:
return "/etc/observe-agent/connections"
}
}

func (c *ConnectionType) GetTemplateFilepath(tplFilename string) string {
return filepath.Join(c.configFolderPath, c.Name, tplFilename)
}
Expand Down Expand Up @@ -138,7 +120,7 @@ func MakeConnectionType(Name string, ConfigFields []CollectorConfigFragment, Typ
c.getConfig = func() *viper.Viper {
return viper.Sub(c.Name)
}
c.configFolderPath = GetConfigFolderPath()
c.configFolderPath = GetConfigFragmentFolderPath()

// Apply provided options
for _, opt := range opts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ receivers:
process.cpu.utilization:
enabled: true
process.disk.operations:
enabled: true
enabled: true
process.memory.utilization:
enabled: true
enabled: true
process.open_file_descriptors:
enabled: true
enabled: true
process.paging.faults:
enabled: true
enabled: true
process.signals_pending:
enabled: true
enabled: true
process.threads:
enabled: true
mute_process_name_error: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ service:
receivers: [filelog/agent-config]
processors: [memory_limiter, transform/truncate, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]

12 changes: 6 additions & 6 deletions packaging/linux/etc/observe-agent/otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ processors:
transform/truncate:
log_statements:
- context: log
statements:
statements:
- truncate_all(attributes, 4095)
- truncate_all(resource.attributes, 4095)
trace_statements:
Expand All @@ -35,9 +35,9 @@ processors:
check_interval: 1s
limit_percentage: 20
spike_limit_percentage: 5

batch:

resourcedetection:
detectors: [env, system]
system:
Expand Down Expand Up @@ -65,7 +65,7 @@ processors:
enabled: true
os.description:
enabled: true

resourcedetection/cloud:
detectors:
{{- if .CloudResourceDetectors }}
Expand Down Expand Up @@ -101,8 +101,8 @@ service:
receivers: [otlp]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe]
logs/forward:

logs/forward:
receivers: [otlp]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe, count]
Expand Down
126 changes: 126 additions & 0 deletions packaging/macos/config/otel-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
extensions:
health_check:
endpoint: 'localhost:13133'
path: '/status'
file_storage:
directory: ${env:FILESTORAGE_PATH}

connectors:
count:

receivers:
otlp:
protocols:
grpc:
endpoint: localhost:4317
http:
endpoint: localhost:4318

processors:
# Snowflake limit for identifiers: Regardless of whether an identifier is unquoted or double-quoted, the maximum number of characters allowed is 255 (including blank spaces).
# https://docs.snowflake.com/en/sql-reference/identifiers-syntax#identifier-requirements
transform/truncate:
log_statements:
- context: log
statements:
- truncate_all(attributes, 4095)
- truncate_all(resource.attributes, 4095)
trace_statements:
- context: span
statements:
- truncate_all(attributes, 4095)
- truncate_all(resource.attributes, 4095)

memory_limiter:
check_interval: 1s
limit_percentage: 20
spike_limit_percentage: 5

batch:

resourcedetection:
detectors: [env, system]
system:
hostname_sources: ["dns", "os"]
resource_attributes:
host.id:
enabled: false
os.type:
enabled: true
host.arch:
enabled: true
host.name:
enabled: true
host.cpu.vendor.id:
enabled: true
host.cpu.family:
enabled: true
host.cpu.model.id:
enabled: true
host.cpu.model.name:
enabled: true
host.cpu.stepping:
enabled: true
host.cpu.cache.l2.size:
enabled: true
os.description:
enabled: true

resourcedetection/cloud:
detectors:
{{- if .CloudResourceDetectors }}
{{- inlineArrayStr .CloudResourceDetectors }}
{{- else }} ["gcp", "ecs", "ec2", "azure"]
{{- end }}
timeout: 2s
override: false

filter/count:
error_mode: ignore
metrics:
metric:
- 'IsMatch(name, ".*")'

exporters:
otlphttp/observe:
endpoint: ${env:OBSERVE_ENDPOINT}
headers:
authorization: ${env:OBSERVE_TOKEN}
sending_queue:
num_consumers: 4
queue_size: 100
retry_on_failure:
enabled: true
compression: zstd

debug:

service:
pipelines:
metrics/forward:
receivers: [otlp]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe]

logs/forward:
receivers: [otlp]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe, count]

traces/forward:
receivers: [otlp]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe]

metrics/count-nooop:
receivers: [count]
processors: [filter/count]
exporters: [debug]

extensions: [health_check, file_storage]
telemetry:
metrics:
level: detailed
address: ":8888"
logs:
level: ${env:OTEL_LOG_LEVEL}
12 changes: 12 additions & 0 deletions packaging/macos/connections/host_monitoring/host.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
receivers:
filestats/agent:
include: '/usr/local/observe-agent/config/otel-collector.yaml'
collection_interval: 5m
initial_delay: 60s

service:
pipelines:
metrics/agent-filestats:
receivers: [filestats/agent]
processors: [resourcedetection, resourcedetection/cloud]
exporters: [otlphttp/observe]
42 changes: 42 additions & 0 deletions packaging/macos/connections/host_monitoring/host_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
receivers:
hostmetrics/host-monitoring-host:
collection_interval: 20s
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
system.cpu.frequency:
enabled: true
system.cpu.logical.count:
enabled: true
system.cpu.physical.count:
enabled: true
load:
memory:
metrics:
system.memory.utilization:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
network:
metrics:
system.network.conntrack.count:
enabled: true
system.network.conntrack.max:
enabled: true
paging:
metrics:
system.paging.utilization:
enabled: true
processes:

service:
pipelines:
metrics/host_monitoring_host:
receivers: [hostmetrics/host-monitoring-host]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
18 changes: 18 additions & 0 deletions packaging/macos/connections/host_monitoring/logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
receivers:
filelog/host_monitoring:
include: [/var/log/**/*.log]
include_file_path: true
storage: file_storage
retry_on_failure:
enabled: true
max_log_size: 4MiB
operators:
- type: filter
expr: 'body matches "otel-contrib"'

service:
pipelines:
logs/host_monitoring-file:
receivers: [filelog/host_monitoring]
processors: [memory_limiter, transform/truncate, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe, count]
Loading
Loading