Skip to content
Draft
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
22 changes: 20 additions & 2 deletions cmd/host-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"strconv"
"sync"

"github.com/k0kubun/pp"
"github.com/middleware-labs/mw-agent/pkg/agent"
"github.com/middleware-labs/synthetics-agent/pkg/worker"
"gopkg.in/natefinch/lumberjack.v2"

"github.com/kardianos/service"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand All @@ -45,7 +45,17 @@ func (p *program) Start(s service.Service) error {

p.programWG.Add(1)
go p.run()

if p.hostAgent.EnableInjector {
pp.Println("Oh baby we injecting .....")
p.programWG.Add(1)
go func() {
p.hostAgent.ReportServices(p.errCh, p.stopCh)
p.programWG.Done()
}()
p.logger.Info("Oh baby we injectin' real hard...")
} else {
p.logger.Info("injector status reporting disabled")
}
// Start any goroutines that can control collection
if p.hostAgent.FetchAccountOtelConfig {
// Listen to the config changes provided by Middleware API
Expand Down Expand Up @@ -135,6 +145,14 @@ func getFlags(execPath string, cfg *agent.HostConfig) []cli.Flag {
DefaultText: "true",
Value: true,
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "enable_injector",
EnvVars: []string{"MW_ENABLE_INJECTOR "},
Usage: "Enables the mw-injector",
Destination: &cfg.EnableInjector,
DefaultText: "true",
Value: true,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "docker-endpoint",
EnvVars: []string{"MW_DOCKER_ENDPOINT"},
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/middleware-labs/mw-agent

go 1.24.2

toolchain go1.24.5
go 1.25.3

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter => github.com/middleware-labs/opentelemetry-collector-contrib/internal/filter v0.0.0-20251119125747-84554b33c7be

Expand Down Expand Up @@ -42,6 +40,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/reso

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders => github.com/middleware-labs/opentelemetry-collector-contrib/internal/metadataproviders v0.0.0-20251119125747-84554b33c7be

replace github.com/middleware-labs/java-injector => ../mw-injector

replace go.opentelemetry.io/collector => go.opentelemetry.io/collector v0.139.0

require (
Expand Down Expand Up @@ -117,6 +117,8 @@ require (
)

require (
github.com/k0kubun/pp v3.0.1+incompatible
github.com/middleware-labs/java-injector v0.0.0-20251201104016-5041a9e06475
github.com/middleware-labs/synthetics-agent v1.0.56
github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.139.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver v0.139.0
Expand Down Expand Up @@ -304,7 +306,6 @@ require (
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/k0kubun/pp v3.0.1+incompatible // indirect
github.com/klauspost/compress v1.18.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/knadh/koanf v1.5.0 // indirect
Expand Down
33 changes: 33 additions & 0 deletions pkg/agent/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type BaseConfig struct {
ProfilngServerURL string
InternalMetricsPort uint
EnableDataDogReceiver bool
EnableInjector bool
}

// String() implements stringer interface for BaseConfig
Expand Down Expand Up @@ -427,3 +428,35 @@ func (p *Profiler) StartProfiling(appName string, target string, tags string) {

p.Logger.Info("PROFILER: Running on mw-agent")
}

// ServiceSetting represents the detailed status for a single service/process.
type ServiceSetting struct {
PID int `json:"pid"`
ServiceName string `json:"service_name"`
Owner string `json:"owner"`
Status string `json:"status"`
Enabled bool `json:"enabled"`
ServiceType string `json:"service_type"`
Language string `json:"language"`
RuntimeVersion string `json:"runtime_version"`
SystemdUnit string `json:"systemd_unit,omitempty"`
JarFile string `json:"jar_file,omitempty"`
MainClass string `json:"main_class,omitempty"`
HasAgent bool `json:"has_agent"`
IsMiddlewareAgent bool `json:"is_middleware_agent"`
AgentPath string `json:"agent_path,omitempty"`
ConfigPath string `json:"config_path,omitempty"`
Instrumented bool `json:"instrumented"`
Key string `json:"key"`
}

// OSConfig represents the configuration and status for a specific OS (e.g., "linux").
type OSConfig struct {
AgentRestartStatus bool `json:"agent_restart_status"`
AutoInstrumentationInit bool `json:"auto_instrumentation_init"`
AutoInstrumentationSettings map[string]ServiceSetting `json:"auto_instrumentation_settings"`
// Add other OS-specific fields (darwin, windows, k8s, etc.) if needed
}

// AgentReportValue is the root structure for the 'value' field's JSON content.
type AgentReportValue map[string]OSConfig
Loading
Loading