-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
122 lines (102 loc) · 5.7 KB
/
Copy pathmain.go
File metadata and controls
122 lines (102 loc) · 5.7 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2025 Steadybit GmbH
package main
import (
"time"
_ "github.com/KimMachineGun/automemlimit" // By default, it sets `GOMEMLIMIT` to 90% of cgroup's memory limit.
"github.com/rs/zerolog"
"github.com/steadybit/action-kit/go/action_kit_api/v2"
"github.com/steadybit/action-kit/go/action_kit_commons/network/netfault"
"github.com/steadybit/action-kit/go/action_kit_commons/ociruntime"
"github.com/steadybit/action-kit/go/action_kit_sdk"
"github.com/steadybit/discovery-kit/go/discovery_kit_api"
"github.com/steadybit/discovery-kit/go/discovery_kit_sdk"
"github.com/steadybit/extension-host/config"
"github.com/steadybit/extension-host/exthost"
"github.com/steadybit/extension-kit/extbuild"
"github.com/steadybit/extension-kit/exthealth"
"github.com/steadybit/extension-kit/exthttp"
"github.com/steadybit/extension-kit/extlogging"
"github.com/steadybit/extension-kit/extruntime"
"github.com/steadybit/extension-kit/extsignals"
)
var startedAt = time.Now().Format(time.RFC3339)
func main() {
// Most Steadybit extensions leverage zerolog. To encourage persistent logging setups across extensions,
// you may leverage the extlogging package to initialize zerolog. Among others, this package supports
// configuration of active log levels and the log format (JSON or plain text).
//
// Example
// - to activate JSON logging, set the environment variable STEADYBIT_LOG_FORMAT="json"
// - to set the log level to debug, set the environment variable STEADYBIT_LOG_LEVEL="debug"
extlogging.InitZeroLog()
extruntime.AdjustOOMScoreAdj()
// Build information is set at compile-time. This line writes the build information to the log.
// The information is mostly handy for debugging purposes.
extbuild.PrintBuildInformation()
extruntime.LogRuntimeInformation(zerolog.InfoLevel)
// Most extensions require some form of configuration. These calls exist to parse and validate the
// configuration obtained from environment variables.
config.ParseConfiguration()
config.ValidateConfiguration()
// Single knob for the operator: strict mode refuses attacks on
// non-noqueue roots; lifting it activates the snapshot/restore path so
// cloud-tuned roots survive the attack.
netfault.SetStrictRootQdisc(config.Config.NetworkStrictRootQdisc)
//This will start /health/liveness and /health/readiness endpoints on port 8081 for use with kubernetes
//The port can be configured using the STEADYBIT_EXTENSION_HEALTH_PORT environment variable
exthealth.SetReady(false)
exthealth.StartProbes(int(config.Config.HealthPort))
// This call registers a handler for the extension's root path. This is the path initially accessed
// by the Steadybit agent to obtain the extension's capabilities.
r := ociruntime.NewOciRuntimeWithCrunForSidecars(ociruntime.ConfigFromEnvironment())
// This is a section you will most likely want to change: The registration of HTTP handlers
// for your extension. You might want to change these because the names do not fit, or because
// you do not have a need for all of them.
discovery_kit_sdk.Register(exthost.NewHostDiscovery())
action_kit_sdk.RegisterAction(exthost.NewStressCpuAction(r))
action_kit_sdk.RegisterAction(exthost.NewCpuSpeedAction())
action_kit_sdk.RegisterAction(exthost.NewStressMemoryAction(r))
action_kit_sdk.RegisterAction(exthost.NewStressIoAction(r))
action_kit_sdk.RegisterAction(exthost.NewTimetravelAction(r))
action_kit_sdk.RegisterAction(exthost.NewStopProcessAction())
action_kit_sdk.RegisterAction(exthost.NewShutdownAction())
action_kit_sdk.RegisterAction(exthost.NewNetworkBlackholeContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkTcpResetAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkLimitBandwidthContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkCorruptPackagesContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkDelayContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkDNSErrorInjectionAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkBlockDnsContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewNetworkPackageLossContainerAction(r))
action_kit_sdk.RegisterAction(exthost.NewFillDiskHostAction(r))
action_kit_sdk.RegisterAction(exthost.NewFillMemoryHostAction(r))
exthttp.RegisterHttpHandler("/", exthttp.IfNoneMatchHandler(func() string { return startedAt }, exthttp.GetterAsHandler(getExtensionList)))
//This will install a signal handler, that will stop active actions when receiving a SIGURS1, SIGTERM or SIGINT
extsignals.ActivateSignalHandlers()
action_kit_sdk.RegisterCoverageEndpoints()
//This will switch the readiness state of the application to true.
exthealth.SetReady(true)
exthttp.Listen(exthttp.ListenOpts{
// This is the default port under which your extension is accessible.
// The port can be configured externally through the
// STEADYBIT_EXTENSION_PORT environment variable.
Port: int(config.Config.Port),
})
}
// ExtensionListResponse exists to merge the possible root path responses supported by the
// various extension kits. In this case, the response for ActionKit, DiscoveryKit and EventKit.
type ExtensionListResponse struct {
action_kit_api.ActionList `json:",inline"`
discovery_kit_api.DiscoveryList `json:",inline"`
}
func getExtensionList() ExtensionListResponse {
return ExtensionListResponse{
// See this document to learn more about the action list:
// https://github.com/steadybit/action-kit/blob/main/docs/action-api.md#action-list
ActionList: action_kit_sdk.GetActionList(),
// See this document to learn more about the discovery list:
// https://github.com/steadybit/discovery-kit/blob/main/docs/discovery-api.md#index-response
DiscoveryList: discovery_kit_sdk.GetDiscoveryList(),
}
}