server

package
v0.47.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 53 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server wires store, engine, controller and HTTP API.

Index

Constants

View Source
const AsyncApiDocId = "github_com_SENERGY-Platform_automation-engine"

AsyncApiDocId names the document at api-docs-provider, by the convention of the platform services

Variables

This section is empty.

Functions

func PublishAsyncApi added in v0.15.0

func PublishAsyncApi(ctx context.Context, client *http.Client, baseUrl string, doc []byte) error

PublishAsyncApi uploads an AsyncAPI document to api-docs-provider, which shows it in API Docs of the web-ui. A later upload replaces it.

func Version

func Version() string

Version is the version of the engine from the build: the module version of a release, else the revision of the source.

Types

type Dependencies

type Dependencies struct {
	// a permissions-v2 client, e.g. permissions-v2's in-process test client
	Permissions permclient.Client
	AdminToken  auth.TokenSource
	// tokens of other users; the Keycloak token exchange if not given
	UserToken auth.UserTokenSource
	// device command dependencies; set together, they enable device commands without URLs
	DeviceRepository devicerepositoryclient.Interface
	Marshaller       devicecommand.Marshaller
	Timescale        devicecommand.Timescale
	Producer         devicecommand.Producer
	// event debugging: stored device messages and their unmarshalling (EVT-10, DBG-18)
	EventSeries       events.Series
	EventUnmarshaller events.Unmarshaller
	// fog: the broker of the gateway, e.g. mqtt.NewMemory() in tests
	Broker mqtt.Broker
	// cloud: the broker the gateways reach (SYNC-04), e.g. mqtt.NewMemory() in tests
	SyncBroker mqtt.Broker
	// cloud: the hubs, which name the owners of networks (FOG-11); device-repository if not given
	Hubs devicerepositoryclient.Interface
	// fog: the owner of the network of the gateway (FOG-11); the cert-manager of the cloud proxy if not given
	NetworkOwner fogsync.NetworkOwner
}

Dependencies replace connections to other services, e.g. in tests.

type EventDependencies

type EventDependencies struct {
	Unmarshaller events.Unmarshaller
	Consumer     events.Consumer
}

EventDependencies replace the unmarshalling and the Kafka consumer of the event role in tests.

type EventServer

type EventServer struct {
	Store   *store.Store
	Engine  *engine.Engine
	Worker  *events.Worker
	Metrics *Metrics
	// contains filtered or unexported fields
}

EventServer is the event role: it evaluates device and import data and correlates events in the process, against the same database as the engine role (section 10).

func NewEventServer

func NewEventServer(ctx context.Context, config configuration.Config, logger *slog.Logger, deps EventDependencies) (*EventServer, error)

func (*EventServer) Close

func (this *EventServer) Close() error

func (*EventServer) Run

func (this *EventServer) Run(ctx context.Context) error

Run reads events until ctx is done and serves metrics and health on the internal port.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics exposes Prometheus metrics of the engine (OPS-05, LONG-13, LONG-14).

func NewMetrics

func NewMetrics(stalledAfter time.Duration) *Metrics

NewMetrics registers the metrics; stalledAfter is the time without element change after which a running instance counts as stalled.

func (*Metrics) Collect

func (this *Metrics) Collect(ctx context.Context, s *store.Store) error

Collect updates the gauges from the database.

func (*Metrics) CommandSent

func (this *Metrics) CommandSent(userId string, deploymentId string)

CommandSent counts a device command per owner and deployment (TASK-12).

func (*Metrics) Correlation

func (this *Metrics) Correlation(result string)

func (*Metrics) DeprecatedRequest

func (this *Metrics) DeprecatedRequest(route string)

DeprecatedRequest counts a request to a route of the deprecated/ layer (API-03).

func (*Metrics) Handler

func (this *Metrics) Handler() http.Handler

func (*Metrics) Incident

func (this *Metrics) Incident(namespace, deploymentId, owner string)

func (*Metrics) InstanceEnded

func (this *Metrics) InstanceEnded(namespace, deploymentId, owner string, state model.InstanceState)

func (*Metrics) InstanceStarted

func (this *Metrics) InstanceStarted(namespace, deploymentId, owner string)

func (*Metrics) MarshallingLatency

func (this *Metrics) MarshallingLatency(endpoint string, userId string, serviceId string, functionIds string, duration time.Duration)

func (*Metrics) Restart

func (this *Metrics) Restart(namespace, deploymentId string, performed bool)

func (*Metrics) Run

func (this *Metrics) Run(ctx context.Context, s *store.Store, interval time.Duration, logger *slog.Logger)

Run collects the gauges periodically until ctx is done.

func (*Metrics) Task

func (this *Metrics) Task(taskType string, result string, namespace string, owner string, duration time.Duration)

Task counts a task execution and its time per owner, so that the cost of task execution can be shared by user (SNRGY-3077). The histogram has no owner label: per owner it would hold a series per bucket.

func (*Metrics) TimerDelay

func (this *Metrics) TimerDelay(delay time.Duration)

type Server

type Server struct {
	Store       *store.Store
	Engine      *engine.Engine
	Controller  *controller.Controller
	Handler     http.Handler
	Namespaces  *namespaces.Registry
	Permissions *permissions.Service
	Metrics     *Metrics
	Live        *debug.Hub
	// removes the resources of deleted modules (SMS-06)
	ModuleRemover *modules.Remover
	// module task types and health checks (TASK-20 to TASK-29)
	Modules *modules.Runtime
	// nil if device commands are not configured
	DeviceCommands *devicecommand.Type
	// fog: the broker of the gateway and the event worker in the process (FOG-01, FOG-06)
	Broker mqtt.Broker
	Events *events.Worker
	// fog: reports the connection state of devices to Events
	Connections *events.DeviceManagerSource
	// fog: the synchronisation with the cloud (SYNC-09)
	Sync *fogsync.Gateway
	// cloud: the synchronisation with gateways (SYNC-09)
	Networks *fogsync.Cloud
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, config configuration.Config, logger *slog.Logger, deps Dependencies) (*Server, error)

New opens the store, applies migrations, loads the namespaces and builds engine, controller and handler of the engine role. Nothing runs yet; see Run.

func (*Server) Close

func (this *Server) Close() error

func (*Server) HandleDeviceGroupMessage added in v0.39.0

func (this *Server) HandleDeviceGroupMessage(ctx context.Context, delivery []byte) error

HandleDeviceGroupMessage reacts to a device group that device-repository wrote or deleted: the event descriptions of deployments that select it change (DEP-08), and the watches of the group are checked (SNRGY-5132). An error repeats the message.

func (*Server) HandleDeviceMessage added in v0.39.0

func (this *Server) HandleDeviceMessage(ctx context.Context, delivery []byte) error

HandleDeviceMessage reacts to a device that device-repository deleted: the watches of the device groups it was in are checked, since the groups keep it without an announcement of their own (SNRGY-5132). An error repeats the message.

func (*Server) Run

func (this *Server) Run(ctx context.Context) error

Run starts the background loops and serves the API and the metrics until ctx is done.

func (*Server) Start

func (this *Server) Start(ctx context.Context)

Start runs the background loops of engine, namespaces, permissions and metrics until ctx is done.

Jump to

Keyboard shortcuts

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