-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathapp.go
More file actions
68 lines (55 loc) · 1.48 KB
/
app.go
File metadata and controls
68 lines (55 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.
package internal
import (
"context"
"log/slog"
"github.com/nginx/agent/v3/internal/bus"
"github.com/nginx/agent/v3/internal/config"
"github.com/nginx/agent/v3/internal/plugin"
"github.com/spf13/cobra"
)
const (
defaultMessagePipeChannelSize = 100
defaultQueueSize = 100
)
type App struct {
commit string
version string
}
func NewApp(commit, version string) *App {
return &App{commit, version}
}
func (a *App) Run(ctx context.Context) error {
config.Init(a.version, a.commit)
config.RegisterRunner(func(_ *cobra.Command, _ []string) {
err := config.RegisterConfigFile()
if err != nil {
slog.ErrorContext(ctx, "Failed to load configuration file", "error", err)
return
}
agentConfig, err := config.ResolveConfig()
if err != nil {
slog.ErrorContext(ctx, "Invalid config", "error", err)
return
}
slog.InfoContext(ctx, "Starting NGINX Agent",
slog.String("version", a.version),
slog.String("commit", a.commit),
)
messagePipe := bus.NewMessagePipe(defaultMessagePipeChannelSize)
err = messagePipe.Register(defaultQueueSize, plugin.LoadPlugins(ctx, agentConfig))
if err != nil {
slog.ErrorContext(ctx, "Failed to register plugins", "error", err)
return
}
messagePipe.Run(ctx)
})
err := config.Execute(ctx)
if err != nil {
return err
}
return nil
}