generated from steadybit/extension-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (78 loc) · 3.98 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright 2023 steadybit GmbH. All rights reserved.
*/
package main
import (
_ "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_sdk"
"github.com/steadybit/discovery-kit/go/discovery_kit_api"
"github.com/steadybit/event-kit/go/event_kit_api"
"github.com/steadybit/extension-debug/config"
"github.com/steadybit/extension-debug/extdebug"
"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"
_ "go.uber.org/automaxprocs" // Importing automaxprocs automatically adjusts GOMAXPROCS.
_ "net/http/pprof" //allow pprof
)
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()
// 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.DebugLevel)
// Most extensions require some form of configuration. These calls exist to parse and validate the
// configuration obtained from environment variables.
config.ParseConfiguration()
config.ValidateConfiguration()
//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(8081)
// 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.
exthttp.RegisterHttpHandler("/", exthttp.GetterAsHandler(getExtensionList))
// 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.
action_kit_sdk.RegisterAction(extdebug.NewDebugAction())
//This will install a signal handlder, that will stop active actions when receiving a SIGURS1, SIGTERM or SIGINT
extsignals.ActivateSignalHandlers()
//This will register the coverage endpoints for the extension (used by action_kit_test)
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.
// We suggest that you keep port 8089 as the default.
Port: 8089,
})
}
// 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"`
event_kit_api.EventListenerList `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(),
}
}