services

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package services contains interface implementations to other services that are called from Smart Proxy.

Package services contains interface implementations to other REST API services that are called from Smart Proxy. Currently the interface is implemented for Content Service.

Index

Constants

View Source
const (
	// RequestIDFieldName represents the name of the field in Redis hash containing request_id
	RequestIDFieldName = "request_id"
	// ReceivedTimestampFieldName represents the name of the field in Redis hash containing received timestamp
	ReceivedTimestampFieldName = "received_timestamp"
	// ProcessedTimestampFieldName represents the name of the field in Redis hash containing processed timestamp
	ProcessedTimestampFieldName = "processed_timestamp"
	// RuleHitsFieldName represent the name of hte field in Redis hash containing simplified rule hits
	RuleHitsFieldName = "rule_hits"
	// ScanBatchCount is the number of records to go through in a single SCAN operation
	ScanBatchCount = 1000
)
View Source
const (
	// ContentEndpoint is the content-service endpoint for getting the static content for all rules
	ContentEndpoint = "content"
	// GroupsEndpoint is the content-service endpoint for getting the list of groups
	GroupsEndpoint = "groups"
)

Variables

View Source
var (
	// RequestIDsScanPattern is a glob-style pattern to find all matching keys. Uses ?* instead of * to avoid
	// matching "organization:%v:cluster:%v:request:". [^:reports] is an exclude pattern to not match the
	// simplified report keys
	RequestIDsScanPattern = "organization:%v:cluster:%v:request:?*[^:reports]"

	// SimplifiedReportKey is a key under which the information about specific requests is stored
	SimplifiedReportKey = "organization:%v:cluster:%v:request:%v:reports"
)

Functions

func CloseResponseBody

func CloseResponseBody(response *http.Response)

CloseResponseBody is used to close the response body so that there are no memory leaks in the TCP socket: CCXDEV-10514

func GetContent

func GetContent(conf Configuration) (*types.RuleContentDirectory, error)

GetContent get the static rule content from content-service

func GetGroups

func GetGroups(conf Configuration) ([]groups.Group, error)

GetGroups get the list of groups from content-service

Types

type Configuration

type Configuration struct {
	AggregatorBaseEndpoint         string        `mapstructure:"aggregator" toml:"aggregator"`
	ContentBaseEndpoint            string        `mapstructure:"content" toml:"content"`
	UpgradeRisksPredictionEndpoint string        `mapstructure:"upgrade_risks_prediction" toml:"upgrade_risks_prediction"`
	GroupsPollingTime              time.Duration `mapstructure:"groups_poll_time" toml:"groups_poll_time"`
	ContentDirectoryTimeout        time.Duration `mapstructure:"content_directory_timeout" toml:"content_directory_timeout"`
}

Configuration represents configuration of services on which smart-proxy depends.

type RedisClient

type RedisClient struct {
	redis.Client
}

RedisClient is a local type which embeds the imported redis.Client to include its own functionality

func (*RedisClient) GetRequestIDsForClusterID

func (redis *RedisClient) GetRequestIDsForClusterID(
	orgID types.OrgID,
	clusterID types.ClusterName,
) (requestIDs []types.RequestID, err error)

GetRequestIDsForClusterID retrieves a list of request IDs from Redis. "List" of request IDs is in the form of keys with empty values in the following structure: organization:{org_id}:cluster:{cluster_id}:request:{request_id1}.

func (*RedisClient) GetRuleHitsForRequest

func (redis *RedisClient) GetRuleHitsForRequest(
	orgID types.OrgID,
	clusterID types.ClusterName,
	requestID types.RequestID,
) (ruleHits []types.RuleID, err error)

GetRuleHitsForRequest is used to get the rule_hits field from Hash type stored in Redis.

func (*RedisClient) GetTimestampsForRequestIDs

func (redis *RedisClient) GetTimestampsForRequestIDs(
	orgID types.OrgID,
	clusterID types.ClusterName,
	requestIDs []types.RequestID,
	omitMissing bool,
) (requestStatuses []types.RequestStatus, err error)

GetTimestampsForRequestIDs retrieves the 'received' and 'processed' timestamps of each Request for given list of Request IDs. It doesn't retrieve the whole Hash, but only the fields we need. It utilizes Redis pipelines in order to avoid multiple client-server round trips.

type RedisConfiguration

type RedisConfiguration struct {
	RedisEndpoint       string `mapstructure:"endpoint" toml:"endpoint"`
	RedisDatabase       int    `mapstructure:"database" toml:"database"`
	RedisTimeoutSeconds int    `mapstructure:"timeout_seconds" toml:"timeout_seconds"`
	RedisPassword       string `mapstructure:"password" toml:"password"`
}

RedisConfiguration represents configuration of Redis client

type RedisInterface

type RedisInterface interface {
	// HealthCheck defined in utils
	HealthCheck() error
	GetRequestIDsForClusterID(
		types.OrgID,
		types.ClusterName,
	) ([]types.RequestID, error)
	GetTimestampsForRequestIDs(
		types.OrgID,
		types.ClusterName,
		[]types.RequestID,
		bool,
	) ([]types.RequestStatus, error)
	GetRuleHitsForRequest(
		types.OrgID,
		types.ClusterName,
		types.RequestID,
	) ([]types.RuleID, error)
}

RedisInterface represents interface for functions executed against a Redis server

func NewRedisClient

func NewRedisClient(conf RedisConfiguration) (RedisInterface, error)

NewRedisClient creates a new Redis client based on configuration and returns RedisInterface

Jump to

Keyboard shortcuts

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