Skip to content

Commit 4e66ae8

Browse files
committed
include event processor logs and send them to customer manager
1 parent 3672c3f commit 4e66ae8

3 files changed

Lines changed: 61 additions & 16 deletions

File tree

installer/config/const.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ const (
2828
)
2929

3030
var (
31-
BackendConfigEndpoint = "https://127.0.0.1/api/utm-configuration-parameters?page=0&size=10000&sectionId.equals=%d&sort=id,asc"
32-
ConfigPath = filepath.Join("/root", "utmstack.yml")
33-
InstanceConfigPath = filepath.Join(GetConfig().UpdatesFolder, "instance-config.yml")
34-
ServiceLogPath = filepath.Join(GetConfig().UpdatesFolder, "logs", "utmstack-updater.log")
35-
VersionFilePath = filepath.Join(GetConfig().UpdatesFolder, "version.json")
36-
LicenseFilePath = filepath.Join(GetConfig().UpdatesFolder, "LICENSE")
37-
CheckUpdatesEvery = 5 * time.Minute
38-
SyncSystemLogsEvery = 5 * time.Minute
39-
ConnectedToInternet = false
40-
Updating = false
31+
BackendConfigEndpoint = "https://127.0.0.1/api/utm-configuration-parameters?page=0&size=10000&sectionId.equals=%d&sort=id,asc"
32+
ConfigPath = filepath.Join("/root", "utmstack.yml")
33+
InstanceConfigPath = filepath.Join(GetConfig().UpdatesFolder, "instance-config.yml")
34+
ServiceLogPath = filepath.Join(GetConfig().UpdatesFolder, "logs", "utmstack-updater.log")
35+
VersionFilePath = filepath.Join(GetConfig().UpdatesFolder, "version.json")
36+
LicenseFilePath = filepath.Join(GetConfig().UpdatesFolder, "LICENSE")
37+
EventProcessorLogsPath = filepath.Join(GetConfig().DataDir, "events-engine-workdir", "logs")
38+
CheckUpdatesEvery = 5 * time.Minute
39+
SyncSystemLogsEvery = 5 * time.Minute
40+
ConnectedToInternet = false
41+
Updating = false
4142
)
4243

4344
func GetCMServer() string {

installer/updater/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (c *UpdaterClient) UpdateProcess() {
7070
defer ticker.Stop()
7171

7272
for range ticker.C {
73-
if IsInMaintenanceWindow() {
73+
if !config.Updating && IsInMaintenanceWindow() {
7474
err := c.CheckUpdate()
7575
if err != nil {
7676
config.Logger().ErrorF("error checking update: %v", err)

installer/updater/logprocessor.go

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"os/signal"
10+
"path/filepath"
911
"strings"
12+
"syscall"
1013
"time"
1114

1215
"github.com/docker/docker/api/types"
@@ -21,17 +24,23 @@ const (
2124
)
2225

2326
func SyncSystemLogs() {
24-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
25-
defer cancel()
27+
rootCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
28+
defer stop()
2629

2730
for {
31+
select {
32+
case <-rootCtx.Done():
33+
return
34+
default:
35+
}
36+
2837
active, err := isLogSenderEnabled()
2938
if err != nil {
3039
config.Logger().ErrorF("Error getting log sender config: %v", err)
3140
}
3241

33-
if active {
34-
err := CollectAndShipSwarmLogs(ctx)
42+
if !config.Updating && active {
43+
err := CollectAndShipSwarmLogs()
3544
if err != nil {
3645
config.Logger().ErrorF("Error collecting and shipping logs: %v", err)
3746
} else {
@@ -52,7 +61,10 @@ func isLogSenderEnabled() (bool, error) {
5261
return backConf[0].ConfParamValue == "true", nil
5362
}
5463

55-
func CollectAndShipSwarmLogs(ctx context.Context) error {
64+
func CollectAndShipSwarmLogs() error {
65+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
66+
defer cancel()
67+
5668
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
5769
if err != nil {
5870
return fmt.Errorf("unable to create Docker client: %v", err)
@@ -122,7 +134,39 @@ func createZip(
122134
}
123135
rc.Close()
124136
}
137+
if info, err := os.Stat(config.EventProcessorLogsPath); err == nil && info.IsDir() {
138+
if err := addDirToZip(zipWriter, config.EventProcessorLogsPath, "events-engine"); err != nil {
139+
return fmt.Errorf("error adding events-engine logs to zip: %v", err)
140+
}
141+
}
142+
125143
return nil
126144
}
127145

146+
func addDirToZip(zipWriter *zip.Writer, dirPath, baseInZip string) error {
147+
return filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
148+
if err != nil {
149+
return err
150+
}
151+
if info.IsDir() {
152+
return nil
153+
}
154+
relPath, err := filepath.Rel(dirPath, path)
155+
if err != nil {
156+
return err
157+
}
158+
zipEntry, err := zipWriter.Create(filepath.Join(baseInZip, relPath))
159+
if err != nil {
160+
return err
161+
}
162+
file, err := os.Open(path)
163+
if err != nil {
164+
return err
165+
}
166+
defer file.Close()
167+
_, err = io.Copy(zipEntry, file)
168+
return err
169+
})
170+
}
171+
128172
func sanitize(name string) string { return strings.TrimPrefix(name, "/") }

0 commit comments

Comments
 (0)