-
Notifications
You must be signed in to change notification settings - Fork 37
/
vector_logs_aggregator_container.go
73 lines (63 loc) · 2.9 KB
/
vector_logs_aggregator_container.go
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
69
70
71
72
73
package vector
import (
"context"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
)
type vectorLogsAggregatorContainer struct{}
func NewVectorLogsAggregatorContainer() *vectorLogsAggregatorContainer {
return &vectorLogsAggregatorContainer{}
}
func (vectorContainer *vectorLogsAggregatorContainer) CreateAndStart(
ctx context.Context,
logsListeningPortNumber uint16,
targetNetworkId string,
objAttrsProvider object_attributes_provider.DockerObjectAttributesProvider,
dockerManager *docker_manager.DockerManager,
) (string, map[string]string, func(), error) {
vectorContainerConfigProviderObj := createVectorContainerConfigProvider(logsListeningPortNumber)
logsAggregatorAttrs, err := objAttrsProvider.ForLogsAggregator()
if err != nil {
return "", nil, nil, stacktrace.Propagate(err, "An error occurred getting the logs aggregator container attributes.")
}
containerName := logsAggregatorAttrs.GetName().GetString()
containerLabelStrs := map[string]string{}
for labelKey, labelValue := range logsAggregatorAttrs.GetLabels() {
containerLabelStrs[labelKey.GetString()] = labelValue.GetString()
}
// Engine handles creating the volume, but we need to mount the aggregator can send logs to logs storage
logsStorageAttrs, err := objAttrsProvider.ForLogsStorageVolume()
if err != nil {
return "", nil, nil, stacktrace.Propagate(err, "An error occurred getting the logs storage volume attributes.")
}
logsStorageVolNameStr := logsStorageAttrs.GetName().GetString()
createAndStartArgs, err := vectorContainerConfigProviderObj.GetContainerArgs(containerName, containerLabelStrs, targetNetworkId, logsStorageVolNameStr)
if err != nil {
return "", nil, nil, err
}
containerId, _, err := dockerManager.CreateAndStartContainer(ctx, createAndStartArgs)
if err != nil {
return "", nil, nil, stacktrace.Propagate(err, "An error occurred starting the logs aggregator container with these args '%+v'", createAndStartArgs)
}
removeContainerFunc := func() {
removeCtx := context.Background()
if err := dockerManager.RemoveContainer(removeCtx, containerId); err != nil {
logrus.Errorf(
"Launching the logs aggregator server with container ID '%v' didn't complete successfully so we "+
"tried to remove the container we started, but doing so exited with an error:\n%v",
containerId,
err)
logrus.Errorf("ACTION REQUIRED: You'll need to manually remove the logs aggregator server with Docker container ID '%v'!!!!!!", containerId)
}
}
shouldRemoveLogsAggregatorContainer := true
defer func() {
if shouldRemoveLogsAggregatorContainer {
removeContainerFunc()
}
}()
shouldRemoveLogsAggregatorContainer = false
return containerId, containerLabelStrs, removeContainerFunc, nil
}