Skip to content
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

V2 Runtime Component Manager #645

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ internal/pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86/configura
internal/pkg/agent/operation/tests/scripts/servicable-1.0-darwin-x86/configurable
internal/pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86_64/configurable
internal/pkg/agent/operation/tests/scripts/serviceable-1.0-darwin-x86_64/serviceable
internal/pkg/agent/operation/tests/scripts/configurable
internal/pkg/agent/operation/tests/scripts/serviceable
internal/pkg/agent/application/fleet.yml
internal/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/exec
pkg/component/fake/fake

# VSCode
/.vscode
Expand Down
8 changes: 2 additions & 6 deletions internal/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/artifact/install/tar"
"github.com/elastic/elastic-agent/internal/pkg/cli"
"github.com/elastic/elastic-agent/internal/pkg/config"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/release"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/version"
)

Expand Down Expand Up @@ -727,10 +727,6 @@ func runLegacyAPMServer(streams *cli.IOStreams, path string) (*process.Info, err
apmDir := filepath.Join(path, files[0].Name())
// Start apm-server process respecting path ENVs
apmBinary := filepath.Join(apmDir, spec.Cmd)
log, err := logger.New("apm-server", false)
if err != nil {
return nil, err
}
// add APM Server specific configuration
var args []string
addEnv := func(arg, env string) {
Expand All @@ -751,7 +747,7 @@ func runLegacyAPMServer(streams *cli.IOStreams, path string) (*process.Info, err
addEnv("--httpprof", "HTTPPROF")
addSettingEnv("gc_percent", "APMSERVER_GOGC")
logInfo(streams, "Starting legacy apm-server daemon as a subprocess.")
return process.Start(log, apmBinary, nil, os.Geteuid(), os.Getegid(), args)
return process.Start(apmBinary, os.Geteuid(), os.Getegid(), args, nil)
}

func logToStderr(cfg *configuration.Configuration) {
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/core/authority"
"github.com/elastic/elastic-agent/internal/pkg/core/backoff"
monitoringConfig "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/fleetapi"
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
"github.com/elastic/elastic-agent/internal/pkg/release"
"github.com/elastic/elastic-agent/internal/pkg/remote"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/core/process"
)

const (
Expand Down Expand Up @@ -600,9 +600,10 @@ func (c *enrollCmd) startAgent(ctx context.Context) (<-chan *os.ProcessState, er
args = append(args, "--path.home.unversioned")
}
proc, err := process.StartContext(
ctx, c.log, cmd, nil, os.Geteuid(), os.Getegid(), args, func(c *exec.Cmd) {
ctx, cmd, os.Geteuid(), os.Getegid(), args, nil, func(c *exec.Cmd) error {
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return nil
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/configuration/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/elastic/elastic-agent/internal/pkg/artifact"
monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/retry"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/operation/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/artifact/uninstall"
"github.com/elastic/elastic-agent/internal/pkg/core/app"
"github.com/elastic/elastic-agent/internal/pkg/core/monitoring/noop"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/retry"
"github.com/elastic/elastic-agent/internal/pkg/core/status"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/operation/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/core/app"
"github.com/elastic/elastic-agent/internal/pkg/core/monitoring"
monitoringConfig "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/retry"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/internal/pkg/core/status"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/core/monitoring/server/processes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"

"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/internal/pkg/sorted"
"github.com/elastic/elastic-agent/pkg/core/process"
)

func TestProcesses(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/core/plugin/process/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/program"
"github.com/elastic/elastic-agent/internal/pkg/core/app"
"github.com/elastic/elastic-agent/internal/pkg/core/monitoring"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/internal/pkg/core/status"
"github.com/elastic/elastic-agent/internal/pkg/tokenbucket"
"github.com/elastic/elastic-agent/pkg/core/logger"
process2 "github.com/elastic/elastic-agent/pkg/core/process"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to call it with alias? we dont use this alias in other places so it may be a bit misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goland did that automatically because the module itself is also named process. I will change it back.

"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ type Application struct {
monitor monitoring.Monitor
statusReporter status.Reporter

processConfig *process.Config
processConfig *process2.Config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the import above you shouldn't need process2?

logger *logger.Logger

Expand Down Expand Up @@ -190,7 +190,7 @@ func (a *Application) SetState(s state.Status, msg string, payload map[string]in
a.setState(s, msg, payload)
}

func (a *Application) watch(ctx context.Context, p app.Taggable, proc *process.Info, cfg map[string]interface{}) {
func (a *Application) watch(ctx context.Context, p app.Taggable, proc *process2.Info, cfg map[string]interface{}) {
go func() {
var procState *os.ProcessState

Expand Down Expand Up @@ -235,7 +235,7 @@ func (a *Application) watch(ctx context.Context, p app.Taggable, proc *process.I
}()
}

func (a *Application) stopWatcher(procInfo *process.Info) {
func (a *Application) stopWatcher(procInfo *process2.Info) {
if procInfo != nil {
if closer, ok := a.watchClosers[procInfo.PID]; ok {
closer()
Expand Down Expand Up @@ -280,7 +280,7 @@ func (a *Application) cleanUp() {
a.monitor.Cleanup(a.desc.Spec(), a.pipelineID)
}

func (a *Application) gracefulKill(proc *process.Info) {
func (a *Application) gracefulKill(proc *process2.Info) {
if proc == nil || proc.Process == nil {
return
}
Expand Down
7 changes: 3 additions & 4 deletions internal/pkg/core/plugin/process/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package process
import (
"context"
"fmt"
"github.com/elastic/elastic-agent/pkg/core/process"
"io"
"os/exec"
"path/filepath"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/core/app"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/pkg/core/server"
)
Expand Down Expand Up @@ -128,14 +128,13 @@ func (a *Application) start(ctx context.Context, t app.Taggable, cfg map[string]
spec.Args = injectDataPath(spec.Args, a.pipelineID, a.id)

a.state.ProcessInfo, err = process.Start(
a.logger,
spec.BinaryPath,
a.processConfig,
a.uid,
a.gid,
spec.Args, func(c *exec.Cmd) {
spec.Args, nil, func(c *exec.Cmd) error {
c.Stdout = newLoggerWriter(a.Name(), logStdOut, a.logger)
c.Stderr = newLoggerWriter(a.Name(), logStdErr, a.logger)
return nil
})
if err != nil {
return fmt.Errorf("%q failed to start %q: %w",
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/core/plugin/process/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"fmt"
"time"

"gopkg.in/yaml.v2"

"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"gopkg.in/yaml.v2"

"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/core/plugin/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/core/app"
"github.com/elastic/elastic-agent/internal/pkg/core/monitoring"
"github.com/elastic/elastic-agent/internal/pkg/core/plugin"
"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/internal/pkg/core/state"
"github.com/elastic/elastic-agent/internal/pkg/core/status"
"github.com/elastic/elastic-agent/internal/pkg/tokenbucket"
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/server"
)

Expand Down
91 changes: 0 additions & 91 deletions internal/pkg/core/process/process.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/pkg/core/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/elastic/elastic-agent-client/v7/pkg/proto"

"github.com/elastic/elastic-agent/internal/pkg/core/process"
"github.com/elastic/elastic-agent/pkg/core/process"
)

// Status describes the current status of the application process.
Expand Down
4 changes: 4 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,22 @@ func (Build) Clean() {
func (Build) TestBinaries() error {
p := filepath.Join("internal", "pkg", "agent", "operation", "tests", "scripts")
p2 := filepath.Join("internal", "pkg", "agent", "transpiler", "tests")
p3 := filepath.Join("pkg", "component")
configurableName := "configurable"
serviceableName := "serviceable"
execName := "exec"
fakeName := "fake"
if runtime.GOOS == "windows" {
configurableName += ".exe"
serviceableName += ".exe"
execName += ".exe"
fakeName += ".exe"
}
return combineErr(
RunGo("build", "-o", filepath.Join(p, configurableName), filepath.Join(p, "configurable-1.0-darwin-x86_64", "main.go")),
RunGo("build", "-o", filepath.Join(p, serviceableName), filepath.Join(p, "serviceable-1.0-darwin-x86_64", "main.go")),
RunGo("build", "-o", filepath.Join(p2, "exec-1.0-darwin-x86_64", execName), filepath.Join(p2, "exec-1.0-darwin-x86_64", "main.go")),
RunGo("build", "-o", filepath.Join(p3, "fake", fakeName), filepath.Join(p3, "fake", "main.go")),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we delete the configurable-* and serviceable-* still required in v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will be removed once v2 is being used.

}

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/elastic/elastic-agent/internal/pkg/agent/cmd"
"github.com/elastic/elastic-agent/internal/pkg/agent/cmd/proc"
"github.com/elastic/elastic-agent/pkg/core/process"
)

// Setups and Runs agent.
Expand All @@ -21,7 +21,7 @@ func main() {
os.Exit(1)
}

pj, err := proc.CreateJobObject()
pj, err := process.CreateJobObject()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize process job object: %v\n", err)
os.Exit(1)
Expand Down
3 changes: 3 additions & 0 deletions pkg/component/fake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fake Component

Controllable through GRPC control protocol with actions. Allows unit tests to simulate control and communication with a running sub-process.
Loading