action_kit_sdk

package module
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 27 Imported by: 43

README

ActionKit Go SDK

This module contains helper and interfaces which will help you to implement actions using the action kit go api.

The module encapsulates the following technical aspects:

  • JSON marshalling and unmarshalling of action inputs and outputs
  • The sdk will wrap around your describe call and will provide some meaningful defaults for your endpoint definitions.
  • An additional layer of rollback stability. The SDK will keep a copy of your action state in memory to be able to roll back to the previous state in case of connections issues.
  • Automatic handling of file parameters. The SDK will automatically download the file, store it in a temporary directory and delete the file after the action has stopped. The Config-map in action_kit_api.PrepareActionRequestBody will contain the path to the downloaded file.

Installation

Add the following to your go.mod file:

go get github.com/steadybit/action-kit/go/action_kit_sdk

Usage

  1. Implement at least the action_kit_sdk.Action interface:

  2. Implement other interfaces if you need them:

    • action_kit_sdk.ActionWithStatus
    • action_kit_sdk.ActionWithStop
    • action_kit_sdk.ActionWithMetricQuery
  3. Register your action:

    action_kit_sdk.RegisterAction(NewRolloutRestartAction())
    
  4. Add your registered actions to the index endpoint of your extension:

    exthttp.RegisterHttpHandler("/actions", exthttp.GetterAsHandler(action_kit_sdk.GetActionList))
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearRegisteredActions added in v1.1.7

func ClearRegisteredActions()

ClearRegisteredActions clears all registered actions - used for testing. Warning: This will not remove the registered routes from the http server.

func GetActionList

func GetActionList() action_kit_api.ActionList

GetActionList returns a list of all root endpoints of registered actions.

func InstallSignalHandler added in v1.0.2

func InstallSignalHandler()

InstallSignalHandler registers a signal handler that stops all active actions on SIGINT, SIGTERM and SIGUSR1.

func RegisterAction

func RegisterAction[T any](a Action[T])

func RegisterCoverageEndpoints added in v1.1.3

func RegisterCoverageEndpoints()

RegisterCoverageEndpoints registers two endpoints which get called by action_kit_test to retrieve coverage data.

func StopAction added in v1.0.2

func StopAction(ctx context.Context, executionId uuid.UUID, reason string)

func StopAllActiveActions

func StopAllActiveActions(reason string)

Types

type Action

type Action[T any] interface {
	// NewEmptyState creates a new empty state. A pointer to this state is passed to the other methods.
	NewEmptyState() T
	// Describe returns the action description.
	Describe() action_kit_api.ActionDescription
	// Prepare is called before the action is actually started. It is used to validate the action configuration and to prepare the action state.
	// [Details](https://github.com/steadybit/action-kit/blob/main/docs/action-api.md#preparation)
	Prepare(ctx context.Context, state *T, request action_kit_api.PrepareActionRequestBody) (*action_kit_api.PrepareResult, error)
	// Start is called when the action should actually happen.
	// [Details](https://github.com/steadybit/action-kit/blob/main/docs/action-api.md#start)
	Start(ctx context.Context, state *T) (*action_kit_api.StartResult, error)
}

type ActionWithMetricQuery

type ActionWithMetricQuery[T any] interface {
	Action[T]
	// QueryMetrics is used to fetch metrics from the action. This method is required if the action supports a metric endpoint defined by [action_kit_api.MetricsConfiguration] in the [action_kit_api.ActionDe scription].
	QueryMetrics(ctx context.Context, request action_kit_api.QueryMetricsRequestBody) (*action_kit_api.QueryMetricsResult, error)
}

type ActionWithStatus

type ActionWithStatus[T any] interface {
	Action[T]
	// Status is used to observe the current status of the action. This is called periodically by the action-kit if time control [action_kit_api.TimeControlInternal] or [action_kit_api.TimeControlExternal] is used.
	// [Details](https://github.com/steadybit/action-kit/blob/main/docs/action-api.md#status)
	Status(ctx context.Context, state *T) (*action_kit_api.StatusResult, error)
}

type ActionWithStop

type ActionWithStop[T any] interface {
	Action[T]
	// Stop is used to revert system modification or clean up any leftovers. This method is optional.
	// [Details](https://github.com/steadybit/action-kit/blob/main/docs/action-api.md#stop)
	Stop(ctx context.Context, state *T) (*action_kit_api.StopResult, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL