server

package
v1.16.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

README

pkg/server

Purpose

This package assembles the live compute HTTP server.

It is where the service-specific application layer is combined with the shared platform request pipeline:

  • OpenTelemetry
  • logging
  • route resolution
  • CORS
  • remote authorization
  • OpenAPI validation
  • audit

The important point is that compute does not invent its own trust model here. It composes platform-defined middleware and then injects a compute-specific handler that depends on both identity and region clients.

Invariants And Guard Rails

  • Middleware ordering is treated as an application-level invariant.
  • Identity-backed authorization and OpenAPI validation are applied centrally, not route-by-route.
  • The server always constructs both identity and region API clients before the compute handler comes alive, which reflects compute's role as a façade over both services.
  • pprof is exposed on a separate listener, which is operationally relevant even though it is not part of the user-facing API contract.

Caveats

  • This package is mostly composition, so it is easy to undersell. In practice it defines the live request pipeline that makes the handler model real.
  • The pprof server is started opportunistically in a goroutine and logs errors via fmt.Println, which is operationally weaker than the structured logging used elsewhere.
  • context.TODO() is still used when building downstream identity and region API clients, which suggests some context-propagation cleanup is still pending.

TODO

  • Move OpenTelemetry-specific configuration into a dedicated options struct as the in-code TODO already suggests.
  • Revisit pprof listener lifecycle and logging so it follows the same structured-operational conventions as the main server.
  • Audit whether downstream client construction should inherit a more explicit startup context than context.TODO().

Cross-Package Context

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Namespace string

	// ListenAddress tells the server what to listen on, you shouldn't
	// need to change this, its already non-privileged and the default
	// should be modified to avoid clashes with other services e.g prometheus.
	ListenAddress string

	// ReadTimeout defines how long before we give up on the client,
	// this should be fairly short.
	ReadTimeout time.Duration

	// ReadHeaderTimeout defines how long before we give up on the client,
	// this should be fairly short.
	ReadHeaderTimeout time.Duration

	// WriteTimeout defines how long we take to respond before we give up.
	// Ideally we'd like this to be short, but Openstack in general sucks
	// for performance. Some operations may still involve multiple dependent
	// API calls before a response can be returned.
	WriteTimeout time.Duration

	// RequestTimeout places a hard limit on all requests lengths.
	RequestTimeout time.Duration
}

Options allows server options to be overridden.

func (*Options) AddFlags

func (o *Options) AddFlags(f *pflag.FlagSet)

addFlags allows server options to be modified.

type Server

type Server struct {
	// CoreOptions are all common across everything e.g. namespace.
	CoreOptions options.CoreOptions

	// ServerOptions are server specific options e.g. listener address etc.
	ServerOptions options.ServerOptions

	// HandlerOptions sets options for the HTTP handler.
	HandlerOptions handler.Options

	// CORSOptions are for remote resource sharing.
	CORSOptions cors.Options

	// ClientOptions are for generic TLS client options e.g. certificates.
	ClientOptions coreclient.HTTPClientOptions

	// IdentityOptions are for a shared identity client.
	IdentityOptions *identityclient.Options

	// RegionOptions are for a shared region client.
	RegionOptions *regionclient.Options

	// OpenAPIOptions are for OpenAPI processing.
	OpenAPIOptions openapimiddleware.Options
}

func (*Server) AddFlags

func (s *Server) AddFlags(flags *pflag.FlagSet)

func (*Server) GetServer

func (s *Server) GetServer(client client.Client) (*http.Server, error)

func (*Server) SetupLogging

func (s *Server) SetupLogging()

func (*Server) SetupOpenTelemetry

func (s *Server) SetupOpenTelemetry(ctx context.Context) error

SetupOpenTelemetry adds a span processor that will print root spans to the logs by default, and optionally ship the spans to an OTLP listener. TODO: move config into an otel specific options struct.

Directories

Path Synopsis
region/mock
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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