generated from steadybit/extension-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (82 loc) · 4.18 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
93
94
95
96
97
98
99
/*
* Copyright 2023 steadybit GmbH. All rights reserved.
*/
package main
import (
"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/extension-jvm/config"
"github.com/steadybit/extension-jvm/extjvm"
"github.com/steadybit/extension-jvm/extjvm/common"
"github.com/steadybit/extension-kit/extbuild"
"github.com/steadybit/extension-kit/exthealth"
"github.com/steadybit/extension-kit/exthttp"
"github.com/steadybit/extension-kit/extlogging"
)
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()
//This will start /health/liveness and /health/readiness endpoints on port 8083 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))
// Most extensions require some form of configuration. These calls exist to parse and validate the
// configuration obtained from environment variables.
config.ParseConfiguration()
config.ValidateConfiguration()
action_kit_sdk.RegisterCoverageEndpoints()
// 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.
extjvm.RegisterDiscoveryHandlers()
action_kit_sdk.RegisterAction(extjvm.NewControllerDelay())
action_kit_sdk.RegisterAction(extjvm.NewControllerException())
action_kit_sdk.RegisterAction(extjvm.NewJdbcTemplateException())
action_kit_sdk.RegisterAction(extjvm.NewJdbcTemplateDelay())
action_kit_sdk.RegisterAction(extjvm.NewHttpClientStatus())
action_kit_sdk.RegisterAction(extjvm.NewHttpClientDelay())
action_kit_sdk.RegisterAction(extjvm.NewJavaMethodDelay())
action_kit_sdk.RegisterAction(extjvm.NewJavaMethodException())
//This will install a signal handlder, that will stop active actions when receiving a SIGURS1, SIGTERM or SIGINT
action_kit_sdk.InstallSignalHandler()
extjvm.InitDiscovery()
//This will switch the readiness state of the application to true.
exthealth.SetReady(true)
common.PrintCaps()
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 8080 as the default.
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: extjvm.GetDiscoveryList(),
}
}