service

package
v0.0.0-...-8568fd5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// V1Prefix is the version prefix used in the console-dot environment
	V1Prefix = "/v1"
	// V2Prefix is the version prefix used for the newer API v2
	V2Prefix = "/v2"
)
View Source
const APIPrefix = "/api/gathering"

APIPrefix is the prefix used in the console-dot environment

View Source
const CanaryVersion = "canary"

CanaryVersion describes subdirectory with canary version of conditions and remote configurations

View Source
const StableVersion = "stable"

StableVersion describes subdirectory with stable version of conditions and remote configurations

Variables

This section is empty.

Functions

func GetClusterID

func GetClusterID(r *http.Request) string

Types

type Cache

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

Cache type represents thread safe map for storing loaded configurations

func (*Cache) Get

func (c *Cache) Get(key string) []byte

Get retrieves value from the cache

func (*Cache) Set

func (c *Cache) Set(key string, value []byte)

Set stores value under given key to the cache

type CanaryConfig

type CanaryConfig struct {
	UnleashURL     string `mapstructure:"unleash_url" toml:"unleash_url"`
	UnleashToken   string `mapstructure:"unleash_token" toml:"unleash_token"`
	UnleashApp     string `mapstructure:"unleash_app" toml:"unleash_app"`
	UnleashToggle  string `mapstructure:"unleash_toggle" toml:"unleash_toggle"`
	UnleashEnabled bool   `mapstructure:"unleash_enabled" toml:"unleash_enabled"`
}

CanaryConfig structure contains configuration for canary rollout

type ClusterMapping

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

ClusterMapping map OCP versions to remote configurations

func NewClusterMapping

func NewClusterMapping(version string, mapping [][]string) *ClusterMapping

func (ClusterMapping) GetFilepathForVersion

func (cm ClusterMapping) GetFilepathForVersion(ocpVersionParsed semver.Version) (string, error)

GetFilepathForVersion iterates over the cluster map returning the first filepath corresponding to the ocp version. Example:

[

["1.0.0", "first.json"],
["2.0.0", "second.json"],
["3.0.0", "third.json"]

] would return first.json for versions between 1.0.0 and 2.0.0, second.json for versions between 2.0.0 and 3.0.0 and third.json for versions greater than 3.0.0

func (ClusterMapping) IsValid

func (cm ClusterMapping) IsValid(remoteConfigurationPath string) bool

IsValid check the list is in order (based on the versions), that the versions can be parsed and that the remote configurations are accessible

type ContainerLogRequest

type ContainerLogRequest struct {
	Namespace    string   `json:"namespace"`
	PodNameRegex string   `json:"pod_name_regex"`
	Previous     bool     `json:"previous,omitempty"`
	Messages     []string `json:"messages"`
}

ContainerLogRequest defines a type for requesting container log data

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse structure represents HTTP response with error message.

type GatheringRulesResponse

type GatheringRulesResponse struct {
	Version string      `json:"version"`
	Rules   interface{} `json:"rules"`
}

GatheringRulesResponse structure represents HTTP response with rules-related content.

type Handler

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

Handler structure represents HTTP request handler.

func NewHandler

func NewHandler(svc RulesProvider) *Handler

NewHandler function constructs new HTTP request handler.

func (*Handler) Register

func (s *Handler) Register(r *mux.Router)

Register function registers new handler for given endpoint URL.

type RemoteConfiguration

type RemoteConfiguration struct {
	ConditionalRules      []Rule                `json:"conditional_gathering_rules"`
	ContainerLogsRequests []ContainerLogRequest `json:"container_logs"`
	Version               string                `json:"version"`
}

RemoteConfiguration represents the new data structure served by the v2 API

type Repository

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

Repository is definition of objects that implement the RepositoryInterface

func NewRepository

func NewRepository(s StorageInterface) *Repository

NewRepository constructs new instance of Repository

func (*Repository) RemoteConfiguration

func (r *Repository) RemoteConfiguration(request *http.Request, ocpVersion string) (*RemoteConfiguration, error)

RemoteConfiguration returns a remote configuration for v2 endpoint based on the cluster map defined in the settings and loaded on startup

func (*Repository) Rules

func (r *Repository) Rules(request *http.Request) (*Rules, error)

Rules method reads all and unmarshals all rules stored under given path

type RepositoryInterface

type RepositoryInterface interface {
	Rules(r *http.Request) (*Rules, error)
	RemoteConfiguration(r *http.Request, ocpVersion string) (*RemoteConfiguration, error)
}

RepositoryInterface defines methods to be implemented by any rules providers

type Rule

type Rule struct {
	Conditions         []interface{} `json:"conditions,omitempty"`
	GatheringFunctions interface{}   `json:"gathering_functions,omitempty"`
}

Rule data type definition based on original JSON schema

type Rules

type Rules struct {
	Items   []Rule `json:"rules,omitempty"`
	Version string `json:"version,omitempty"`
}

Rules data type definition based on original JSON schema

type RulesProvider

type RulesProvider interface {
	Rules(r *http.Request) (*Rules, error)
	RemoteConfiguration(r *http.Request, ocpVersion string) (*RemoteConfiguration, error)
}

RulesProvider defines methods to be implemented by any rules provider

type Service

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

Service data type represents the whole service for repository interface.

func New

func New(repo RepositoryInterface) *Service

New function constructs new service for given repository interface.

func (*Service) RemoteConfiguration

func (s *Service) RemoteConfiguration(r *http.Request, ocpVersion string) (*RemoteConfiguration, error)

RemoteConfiguration method returns the remote configuration provided by the service.

func (*Service) Rules

func (s *Service) Rules(r *http.Request) (*Rules, error)

Rules method returns all rules provided by the service.

type Storage

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

Storage type represents container for resources.

func NewStorage

func NewStorage(storageConfig StorageConfig, unleashEnabled bool, unleashClient UnleashClientInterface) (*Storage, error)

NewStorage constructs new storage object.

func (*Storage) GetRemoteConfigurationFilepath

func (s *Storage) GetRemoteConfigurationFilepath(isCanary bool, ocpVersion string) (string, error)

GetRemoteConfigurationFilepath returns the filepath to the remote configuration that should be returned for the given OCP version based on the cluster map

func (*Storage) IsCanary

func (s *Storage) IsCanary(r *http.Request) bool

IsCanary queries UnleashClient to determine which version of configurations to serve

func (*Storage) ReadConditionalRules

func (s *Storage) ReadConditionalRules(isCanary bool, path string) []byte

ReadConditionalRules tries to find conditional rule with given name in the storage.

func (*Storage) ReadRemoteConfig

func (s *Storage) ReadRemoteConfig(isCanary bool, path string) []byte

ReadRemoteConfig tries to find remote configuration with given name in the storage

type StorageConfig

type StorageConfig struct {
	RulesPath               string `mapstructure:"rules_path" toml:"rules_path"`
	RemoteConfigurationPath string `mapstructure:"remote_configuration" toml:"remote_configuration"`
	ClusterMappingPath      string `mapstructure:"cluster_mapping" toml:"cluster_mapping"`
	ClusterMappingFile      string `mapstructure:"cluster_mapping_file" toml:"cluster_mapping_file"`
}

StorageConfig structure contains configuration for resource storage.

type StorageInterface

type StorageInterface interface {
	IsCanary(request *http.Request) bool
	ReadConditionalRules(isCanary bool, res string) []byte
	ReadRemoteConfig(isCanary bool, p string) []byte
	GetRemoteConfigurationFilepath(isCanary bool, ocpVersion string) (string, error)
}

StorageInterface describe interface to be implemented by resource storage implementations.

type UnleashClient

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

UnleashClient initializes Unleash on its creation and provides interface to query it

func NewUnleashClient

func NewUnleashClient(cfg CanaryConfig) (*UnleashClient, error)

NewUnleashClient constructs new Unleash client along with Unleash initialization

func (*UnleashClient) IsCanary

func (c *UnleashClient) IsCanary(canaryArgument string) bool

IsCanary queries Unleash to determine whether to serve stable or canary version of data

type UnleashClientInterface

type UnleashClientInterface interface {
	IsCanary(canaryArgument string) bool
}

UnleashClientInterface describes interface for using Unleash in canary rollouts

Jump to

Keyboard shortcuts

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