storage

package
v1.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package storage contains an implementation of interface between Go code and (almost any) SQL database like PostgreSQL or MariaDB. An implementation named DBStorage is constructed using the function 'New' and it is mandatory to call 'Close' for any opened connection to the database. The storage might be initialized by 'Init' method if database schema is empty.

It is possible to configure connection to selected database by using Configuration structure. Currently, that structure contains two configurable parameter:

Driver - a SQL driver, like "pq", "pgx", etc. DataSource - specification of data source. The content of this parameter depends on the database used.

Index

Constants

View Source
const DefaultValue = ""

DefaultValue represents value that is stored under some key. We don't care about the value right now so it can be empty.

View Source
const ExpirationDuration = "24h"

ExpirationDuration set to keys stored into Redis

View Source
const (
	// ReportSuffix is used to strip away .report suffix from rule module names
	ReportSuffix = ".report"
)

Variables

This section is empty.

Functions

func InitSQLDriverWithLogs

func InitSQLDriverWithLogs(
	realDriver sql_driver.Driver,
	realDriverName string,
) string

InitSQLDriverWithLogs initializes wrapped version of driver with logging sql queries and returns its name

Types

type ClusterRuleToggle

type ClusterRuleToggle struct {
	ClusterID  types.ClusterName
	RuleID     types.RuleID
	Disabled   RuleToggle
	DisabledAt sql.NullTime
	EnabledAt  sql.NullTime
	UpdatedAt  sql.NullTime
}

ClusterRuleToggle represents a record from rule_cluster_toggle

type Configuration

type Configuration struct {
	Driver             string `mapstructure:"db_driver" toml:"db_driver"`
	LogSQLQueries      bool   `mapstructure:"log_sql_queries" toml:"log_sql_queries"`
	PGUsername         string `mapstructure:"pg_username" toml:"pg_username"`
	PGPassword         string `mapstructure:"pg_password" toml:"pg_password"`
	PGHost             string `mapstructure:"pg_host" toml:"pg_host"`
	PGPort             int    `mapstructure:"pg_port" toml:"pg_port"`
	PGDBName           string `mapstructure:"pg_db_name" toml:"pg_db_name"`
	PGParams           string `mapstructure:"pg_params" toml:"pg_params"`
	Type               string `mapstructure:"type" toml:"type"`
	RedisConfiguration RedisConfiguration
}

Configuration represents configuration of data storage

type DVORecommendationsDBStorage added in v1.4.0

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

DVORecommendationsDBStorage is an implementation of Storage interface that use selected SQL like database like PostgreSQL or RDS etc. That implementation is based on the standard sql package. It is possible to configure connection via Configuration structure. SQLQueriesLog is log for sql queries, default is nil which means nothing is logged

func NewDVORecommendationsFromConnection added in v1.4.0

func NewDVORecommendationsFromConnection(connection *sql.DB, dbDriverType types.DBDriver) *DVORecommendationsDBStorage

NewDVORecommendationsFromConnection function creates and initializes a new instance of Storage interface from prepared connection

func (DVORecommendationsDBStorage) Close added in v1.4.0

func (storage DVORecommendationsDBStorage) Close() error

Close method closes the connection to database. Needs to be called at the end of application lifecycle.

func (DVORecommendationsDBStorage) DeleteReportsForOrg added in v1.4.0

func (storage DVORecommendationsDBStorage) DeleteReportsForOrg(orgID types.OrgID) error

DeleteReportsForOrg deletes all reports related to the specified organization from the storage.

func (DVORecommendationsDBStorage) GetConnection added in v1.4.0

func (storage DVORecommendationsDBStorage) GetConnection() *sql.DB

GetConnection returns db connection(useful for testing)

func (DVORecommendationsDBStorage) GetDBDriverType added in v1.4.0

func (storage DVORecommendationsDBStorage) GetDBDriverType() types.DBDriver

GetDBDriverType returns db driver type

func (DVORecommendationsDBStorage) GetDBSchema added in v1.4.0

func (storage DVORecommendationsDBStorage) GetDBSchema() migration.Schema

GetDBSchema returns the schema name to be used in queries

func (DVORecommendationsDBStorage) GetMaxVersion added in v1.4.0

func (storage DVORecommendationsDBStorage) GetMaxVersion() migration.Version

GetMaxVersion returns the highest available migration version. The DB version cannot be set to a value higher than this. This value is equivalent to the length of the list of available migrations.

func (DVORecommendationsDBStorage) GetMigrations added in v1.4.0

func (storage DVORecommendationsDBStorage) GetMigrations() []migration.Migration

GetMigrations returns a list of database migrations related to DVO recommendation tables

func (DVORecommendationsDBStorage) Init added in v1.4.0

func (storage DVORecommendationsDBStorage) Init() error

Init performs all database initialization tasks necessary for further service operation.

func (DVORecommendationsDBStorage) MigrateToLatest added in v1.4.0

func (storage DVORecommendationsDBStorage) MigrateToLatest() error

MigrateToLatest migrates the database to the latest available migration version. This must be done before an Init() call.

func (DVORecommendationsDBStorage) ReadWorkloadsForClusterAndNamespace added in v1.4.0

func (storage DVORecommendationsDBStorage) ReadWorkloadsForClusterAndNamespace(
	orgID types.OrgID,
	clusterID types.ClusterName,
	namespaceID string,
) (
	workload types.DVOReport,
	err error,
)

ReadWorkloadsForClusterAndNamespace returns a single result from the dvo.dvo_report table

func (DVORecommendationsDBStorage) ReadWorkloadsForOrganization added in v1.4.0

func (storage DVORecommendationsDBStorage) ReadWorkloadsForOrganization(orgID types.OrgID) (
	workloads []types.DVOReport,
	err error,
)

ReadWorkloadsForOrganization returns all rows from dvo.dvo_report table for given organizaiton

func (DVORecommendationsDBStorage) ReportsCount added in v1.4.0

func (storage DVORecommendationsDBStorage) ReportsCount() (int, error)

ReportsCount reads number of all records stored in the dvo.dvo_report table

func (DVORecommendationsDBStorage) WriteReportForCluster added in v1.4.0

func (storage DVORecommendationsDBStorage) WriteReportForCluster(
	orgID types.OrgID,
	clusterName types.ClusterName,
	report types.ClusterReport,
	workloads []types.WorkloadRecommendation,
	lastCheckedTime time.Time,
	_ time.Time,
	_ time.Time,
	_ types.RequestID,
) error

WriteReportForCluster writes result (health status) for selected cluster for given organization

type DVORecommendationsStorage added in v1.4.0

type DVORecommendationsStorage interface {
	Init() error
	Close() error
	GetMigrations() []migration.Migration
	GetDBDriverType() types.DBDriver
	GetDBSchema() migration.Schema
	GetConnection() *sql.DB
	GetMaxVersion() migration.Version
	MigrateToLatest() error
	ReportsCount() (int, error)
	WriteReportForCluster(
		orgID types.OrgID,
		clusterName types.ClusterName,
		report types.ClusterReport,
		workloads []types.WorkloadRecommendation,
		lastCheckedTime time.Time,
		gatheredAtTime time.Time,
		storedAtTime time.Time,
		requestID types.RequestID,
	) error
	ReadWorkloadsForOrganization(types.OrgID) ([]types.DVOReport, error)
	ReadWorkloadsForClusterAndNamespace(
		types.OrgID,
		types.ClusterName,
		string,
	) (types.DVOReport, error)
	DeleteReportsForOrg(orgID types.OrgID) error
}

DVORecommendationsStorage represents an interface to almost any database or storage system

func NewDVORecommendationsStorage added in v1.4.0

func NewDVORecommendationsStorage(configuration Configuration) (DVORecommendationsStorage, error)

NewDVORecommendationsStorage function creates and initializes a new instance of Storage interface

type DisabledRuleReason added in v1.1.5

type DisabledRuleReason struct {
	ClusterID types.ClusterName
	RuleID    types.RuleID
	ErrorKey  types.ErrorKey
	Message   string
	AddedAt   sql.NullTime
	UpdatedAt sql.NullTime
}

DisabledRuleReason represents a record from cluster_user_rule_disable_feedback table

type NoopDVOStorage added in v1.4.0

type NoopDVOStorage struct{}

NoopDVOStorage represents a storage which does nothing (for benchmarking without a storage)

func (*NoopDVOStorage) Close added in v1.4.0

func (*NoopDVOStorage) Close() error

Close noop

func (*NoopDVOStorage) DeleteReportsForOrg added in v1.4.0

func (*NoopDVOStorage) DeleteReportsForOrg(types.OrgID) error

DeleteReportsForOrg noop

func (*NoopDVOStorage) GetConnection added in v1.4.0

func (*NoopDVOStorage) GetConnection() *sql.DB

GetConnection noop

func (*NoopDVOStorage) GetDBDriverType added in v1.4.0

func (*NoopDVOStorage) GetDBDriverType() types.DBDriver

GetDBDriverType noop

func (*NoopDVOStorage) GetDBSchema added in v1.4.0

func (*NoopDVOStorage) GetDBSchema() migration.Schema

GetDBSchema noop

func (*NoopDVOStorage) GetMaxVersion added in v1.4.0

func (*NoopDVOStorage) GetMaxVersion() migration.Version

GetMaxVersion noop

func (*NoopDVOStorage) GetMigrations added in v1.4.0

func (*NoopDVOStorage) GetMigrations() []migration.Migration

GetMigrations noop

func (*NoopDVOStorage) Init added in v1.4.0

func (*NoopDVOStorage) Init() error

Init noop

func (*NoopDVOStorage) MigrateToLatest added in v1.4.0

func (*NoopDVOStorage) MigrateToLatest() error

MigrateToLatest noop

func (*NoopDVOStorage) ReadWorkloadsForClusterAndNamespace added in v1.4.0

func (*NoopDVOStorage) ReadWorkloadsForClusterAndNamespace(
	types.OrgID,
	types.ClusterName,
	string,
) (types.DVOReport, error)

ReadWorkloadsForClusterAndNamespace noop

func (*NoopDVOStorage) ReadWorkloadsForOrganization added in v1.4.0

func (*NoopDVOStorage) ReadWorkloadsForOrganization(types.OrgID) ([]types.DVOReport, error)

ReadWorkloadsForOrganization noop

func (*NoopDVOStorage) ReportsCount added in v1.4.0

func (*NoopDVOStorage) ReportsCount() (int, error)

ReportsCount noop

func (*NoopDVOStorage) WriteReportForCluster added in v1.4.0

WriteReportForCluster noop

type NoopOCPStorage added in v1.4.0

type NoopOCPStorage struct{}

NoopOCPStorage represents a storage which does nothing (for benchmarking without a storage)

func (*NoopOCPStorage) AddFeedbackOnRuleDisable added in v1.4.0

AddFeedbackOnRuleDisable noop

func (*NoopOCPStorage) AddOrUpdateFeedbackOnRule added in v1.4.0

AddOrUpdateFeedbackOnRule noop

func (*NoopOCPStorage) Close added in v1.4.0

func (*NoopOCPStorage) Close() error

Close noop

func (*NoopOCPStorage) CreateRule added in v1.4.0

func (*NoopOCPStorage) CreateRule(types.Rule) error

CreateRule noop

func (*NoopOCPStorage) CreateRuleErrorKey added in v1.4.0

func (*NoopOCPStorage) CreateRuleErrorKey(types.RuleErrorKey) error

CreateRuleErrorKey noop

func (*NoopOCPStorage) DeleteFromRuleClusterToggle added in v1.4.0

func (*NoopOCPStorage) DeleteFromRuleClusterToggle(
	types.ClusterName, types.RuleID) error

DeleteFromRuleClusterToggle noop

func (*NoopOCPStorage) DeleteReportsForCluster added in v1.4.0

func (*NoopOCPStorage) DeleteReportsForCluster(types.ClusterName) error

DeleteReportsForCluster noop

func (*NoopOCPStorage) DeleteReportsForOrg added in v1.4.0

func (*NoopOCPStorage) DeleteReportsForOrg(types.OrgID) error

DeleteReportsForOrg noop

func (*NoopOCPStorage) DeleteRule added in v1.4.0

func (*NoopOCPStorage) DeleteRule(types.RuleID) error

DeleteRule noop

func (*NoopOCPStorage) DeleteRuleErrorKey added in v1.4.0

func (*NoopOCPStorage) DeleteRuleErrorKey(types.RuleID, types.ErrorKey) error

DeleteRuleErrorKey noop

func (*NoopOCPStorage) DisableRuleSystemWide added in v1.4.0

func (*NoopOCPStorage) DisableRuleSystemWide(
	_ types.OrgID, _ types.RuleID,
	_ types.ErrorKey, _ string,
) error

DisableRuleSystemWide disables the selected rule for all clusters visible to given user

func (*NoopOCPStorage) DoesClusterExist added in v1.4.0

func (*NoopOCPStorage) DoesClusterExist(types.ClusterName) (bool, error)

DoesClusterExist noop

func (*NoopOCPStorage) EnableRuleSystemWide added in v1.4.0

func (*NoopOCPStorage) EnableRuleSystemWide(
	_ types.OrgID, _ types.RuleID, _ types.ErrorKey,
) error

EnableRuleSystemWide enables the selected rule for all clusters visible to given user

func (*NoopOCPStorage) GetConnection added in v1.4.0

func (*NoopOCPStorage) GetConnection() *sql.DB

GetConnection returns db connection(useful for testing)

func (*NoopOCPStorage) GetDBDriverType added in v1.4.0

func (*NoopOCPStorage) GetDBDriverType() types.DBDriver

GetDBDriverType returns db driver type

func (*NoopOCPStorage) GetDBSchema added in v1.4.0

func (*NoopOCPStorage) GetDBSchema() migration.Schema

GetDBSchema noop

func (*NoopOCPStorage) GetFromClusterRuleToggle added in v1.4.0

func (*NoopOCPStorage) GetFromClusterRuleToggle(
	types.ClusterName,
	types.RuleID,
) (*ClusterRuleToggle, error)

GetFromClusterRuleToggle noop

func (*NoopOCPStorage) GetMaxVersion added in v1.4.0

func (*NoopOCPStorage) GetMaxVersion() migration.Version

GetMaxVersion noop

func (*NoopOCPStorage) GetMigrations added in v1.4.0

func (*NoopOCPStorage) GetMigrations() []migration.Migration

GetMigrations noop

func (*NoopOCPStorage) GetOrgIDByClusterID added in v1.4.0

func (*NoopOCPStorage) GetOrgIDByClusterID(types.ClusterName) (types.OrgID, error)

GetOrgIDByClusterID noop

func (*NoopOCPStorage) GetRuleByID added in v1.4.0

func (*NoopOCPStorage) GetRuleByID(types.RuleID) (*types.Rule, error)

GetRuleByID noop

func (*NoopOCPStorage) GetRuleRating added in v1.4.0

func (*NoopOCPStorage) GetRuleRating(
	_ types.OrgID,
	_ types.RuleSelector,
) (
	ruleRating types.RuleRating,
	err error,
)

GetRuleRating retrieves rating for given rule and user

func (*NoopOCPStorage) GetRuleWithContent added in v1.4.0

func (*NoopOCPStorage) GetRuleWithContent(
	types.RuleID, types.ErrorKey,
) (*types.RuleWithContent, error)

GetRuleWithContent noop

func (*NoopOCPStorage) GetTogglesForRules added in v1.4.0

func (*NoopOCPStorage) GetTogglesForRules(
	types.ClusterName,
	[]types.RuleOnReport,
	types.OrgID,
) (map[types.RuleID]bool, error)

GetTogglesForRules noop

func (*NoopOCPStorage) GetUserDisableFeedbackOnRules added in v1.4.0

func (*NoopOCPStorage) GetUserDisableFeedbackOnRules(
	types.ClusterName, []types.RuleOnReport, types.UserID,
) (map[types.RuleID]UserFeedbackOnRule, error)

GetUserDisableFeedbackOnRules noop

func (*NoopOCPStorage) GetUserFeedbackOnRule added in v1.4.0

GetUserFeedbackOnRule noop

func (*NoopOCPStorage) GetUserFeedbackOnRuleDisable added in v1.4.0

func (*NoopOCPStorage) GetUserFeedbackOnRuleDisable(
	types.ClusterName, types.RuleID, types.ErrorKey, types.UserID,
) (*UserFeedbackOnRule, error)

GetUserFeedbackOnRuleDisable noop

func (*NoopOCPStorage) GetUserFeedbackOnRules added in v1.4.0

func (*NoopOCPStorage) GetUserFeedbackOnRules(
	types.ClusterName,
	[]types.RuleOnReport,
	types.UserID,
) (map[types.RuleID]types.UserVote, error)

GetUserFeedbackOnRules noop

func (*NoopOCPStorage) Init added in v1.4.0

func (*NoopOCPStorage) Init() error

Init noop

func (*NoopOCPStorage) ListOfClustersForOrg added in v1.4.0

func (*NoopOCPStorage) ListOfClustersForOrg(types.OrgID, time.Time) ([]types.ClusterName, error)

ListOfClustersForOrg noop

func (*NoopOCPStorage) ListOfClustersForOrgSpecificRule added in v1.4.0

func (*NoopOCPStorage) ListOfClustersForOrgSpecificRule(
	_ types.OrgID, _ types.RuleSelector, _ []string,
) ([]ctypes.HittingClustersData, error)

ListOfClustersForOrgSpecificRule returns list of all clusters for given organization that are affected by given rule

func (*NoopOCPStorage) ListOfDisabledClusters added in v1.4.0

func (*NoopOCPStorage) ListOfDisabledClusters(
	_ types.OrgID,
	_ types.RuleID,
	_ types.ErrorKey,
) ([]ctypes.DisabledClusterInfo, error)

ListOfDisabledClusters function returns list of all clusters disabled for a rule from a specified account (noop).

func (*NoopOCPStorage) ListOfDisabledRules added in v1.4.0

func (*NoopOCPStorage) ListOfDisabledRules(_ types.OrgID) ([]ctypes.DisabledRule, error)

ListOfDisabledRules function returns list of all rules disabled from a specified account (noop).

func (*NoopOCPStorage) ListOfDisabledRulesForClusters added in v1.4.0

func (*NoopOCPStorage) ListOfDisabledRulesForClusters(
	_ []string,
	_ types.OrgID,
) ([]ctypes.DisabledRule, error)

ListOfDisabledRulesForClusters function returns list of disabled rules for given clusters from a specified account (noop).

func (*NoopOCPStorage) ListOfOrgs added in v1.4.0

func (*NoopOCPStorage) ListOfOrgs() ([]types.OrgID, error)

ListOfOrgs noop

func (*NoopOCPStorage) ListOfReasons added in v1.4.0

func (*NoopOCPStorage) ListOfReasons(_ types.UserID) ([]DisabledRuleReason, error)

ListOfReasons function returns list of reasons for all rules disabled from a specified account (noop).

func (*NoopOCPStorage) ListOfSystemWideDisabledRules added in v1.4.0

func (*NoopOCPStorage) ListOfSystemWideDisabledRules(
	_ types.OrgID,
) ([]ctypes.SystemWideRuleDisable, error)

ListOfSystemWideDisabledRules function returns list of all rules that have been disabled for all clusters by given user

func (*NoopOCPStorage) MigrateToLatest added in v1.4.0

func (*NoopOCPStorage) MigrateToLatest() error

MigrateToLatest migrates the database to the latest available migration version. This must be done before an Init() call.

func (*NoopOCPStorage) PrintRuleDisableDebugInfo added in v1.4.0

func (*NoopOCPStorage) PrintRuleDisableDebugInfo()

PrintRuleDisableDebugInfo is a temporary helper function used to print form cluster rule toggle related tables

func (*NoopOCPStorage) RateOnRule added in v1.4.0

RateOnRule function stores the vote (rating) given by an user to a rule+error key

func (*NoopOCPStorage) ReadClusterListRecommendations added in v1.4.0

func (*NoopOCPStorage) ReadClusterListRecommendations(
	_ []string, _ types.OrgID,
) (ctypes.ClusterRecommendationMap, error)

ReadClusterListRecommendations retrieves cluster IDs and a list of hitting rules for each one

func (*NoopOCPStorage) ReadClusterVersionsForClusterList added in v1.4.0

func (*NoopOCPStorage) ReadClusterVersionsForClusterList(
	types.OrgID, []string,
) (map[types.ClusterName]types.Version, error)

ReadClusterVersionsForClusterList noop

func (*NoopOCPStorage) ReadDisabledRule added in v1.4.0

ReadDisabledRule function returns disabled rule (if disabled) from database

func (*NoopOCPStorage) ReadOrgIDsForClusters added in v1.4.0

func (*NoopOCPStorage) ReadOrgIDsForClusters(_ []types.ClusterName) ([]types.OrgID, error)

ReadOrgIDsForClusters read organization IDs for given list of cluster names.

func (*NoopOCPStorage) ReadRecommendationsForClusters added in v1.4.0

func (*NoopOCPStorage) ReadRecommendationsForClusters(
	_ []string,
	_ types.OrgID,
) (ctypes.RecommendationImpactedClusters, error)

ReadRecommendationsForClusters reads all recommendations from recommendation table for given organization

func (*NoopOCPStorage) ReadReportForCluster added in v1.4.0

ReadReportForCluster noop

func (*NoopOCPStorage) ReadReportForClusterByClusterName added in v1.4.0

func (*NoopOCPStorage) ReadReportForClusterByClusterName(
	types.ClusterName,
) ([]types.RuleOnReport, types.Timestamp, error)

ReadReportForClusterByClusterName noop

func (*NoopOCPStorage) ReadReportInfoForCluster added in v1.4.0

func (*NoopOCPStorage) ReadReportInfoForCluster(types.OrgID, types.ClusterName) (types.Version, error)

ReadReportInfoForCluster noop

func (*NoopOCPStorage) ReadReportsForClusters added in v1.4.0

func (*NoopOCPStorage) ReadReportsForClusters(_ []types.ClusterName) (map[types.ClusterName]types.ClusterReport, error)

ReadReportsForClusters function reads reports for given list of cluster names.

func (*NoopOCPStorage) ReadSingleRuleTemplateData added in v1.4.0

func (*NoopOCPStorage) ReadSingleRuleTemplateData(types.OrgID, types.ClusterName, types.RuleID, types.ErrorKey) (interface{}, error)

ReadSingleRuleTemplateData noop

func (*NoopOCPStorage) ReportsCount added in v1.4.0

func (*NoopOCPStorage) ReportsCount() (int, error)

ReportsCount noop

func (*NoopOCPStorage) ToggleRuleForCluster added in v1.4.0

ToggleRuleForCluster noop

func (*NoopOCPStorage) UpdateDisabledRuleJustification added in v1.4.0

func (*NoopOCPStorage) UpdateDisabledRuleJustification(
	_ types.OrgID,
	_ types.RuleID,
	_ types.ErrorKey,
	_ string,
) error

UpdateDisabledRuleJustification change justification for already disabled rule

func (*NoopOCPStorage) VoteOnRule added in v1.4.0

VoteOnRule noop

func (*NoopOCPStorage) WriteConsumerError added in v1.4.0

func (*NoopOCPStorage) WriteConsumerError(*sarama.ConsumerMessage, error) error

WriteConsumerError noop

func (*NoopOCPStorage) WriteRecommendationsForCluster added in v1.4.0

func (*NoopOCPStorage) WriteRecommendationsForCluster(
	types.OrgID, types.ClusterName, types.ClusterReport, types.Timestamp,
) error

WriteRecommendationsForCluster noop

func (*NoopOCPStorage) WriteReportForCluster added in v1.4.0

WriteReportForCluster noop

func (*NoopOCPStorage) WriteReportInfoForCluster added in v1.4.0

func (*NoopOCPStorage) WriteReportInfoForCluster(
	_ types.OrgID,
	_ types.ClusterName,
	_ []types.InfoItem,
	_ time.Time,
) error

WriteReportInfoForCluster noop

type OCPRecommendationsDBStorage added in v1.4.0

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

OCPRecommendationsDBStorage is an implementation of Storage interface that use selected SQL like database like PostgreSQL, MariaDB, RDS etc. That implementation is based on the standard sql package. It is possible to configure connection via Configuration structure. SQLQueriesLog is log for sql queries, default is nil which means nothing is logged

func NewOCPRecommendationsFromConnection added in v1.4.0

func NewOCPRecommendationsFromConnection(connection *sql.DB, dbDriverType types.DBDriver) *OCPRecommendationsDBStorage

NewOCPRecommendationsFromConnection function creates and initializes a new instance of Storage interface from prepared connection

func (OCPRecommendationsDBStorage) AddFeedbackOnRuleDisable added in v1.4.0

func (storage OCPRecommendationsDBStorage) AddFeedbackOnRuleDisable(
	clusterID types.ClusterName,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	orgID types.OrgID,
	userID types.UserID,
	message string,
) error

AddFeedbackOnRuleDisable adds feedback on rule disable

func (OCPRecommendationsDBStorage) AddOrUpdateFeedbackOnRule added in v1.4.0

func (storage OCPRecommendationsDBStorage) AddOrUpdateFeedbackOnRule(
	clusterID types.ClusterName,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	orgID types.OrgID,
	userID types.UserID,
	message string,
) error

AddOrUpdateFeedbackOnRule adds feedback on rule for cluster by user. If entry exists, it overwrites it

func (OCPRecommendationsDBStorage) Close added in v1.4.0

func (storage OCPRecommendationsDBStorage) Close() error

Close method closes the connection to database. Needs to be called at the end of application lifecycle.

func (OCPRecommendationsDBStorage) DeleteFromRuleClusterToggle added in v1.4.0

func (storage OCPRecommendationsDBStorage) DeleteFromRuleClusterToggle(
	clusterID types.ClusterName, ruleID types.RuleID,
) error

DeleteFromRuleClusterToggle deletes a record from the table rule_cluster_toggle. Only exposed in debug mode.

func (OCPRecommendationsDBStorage) DeleteReportsForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) DeleteReportsForCluster(clusterName types.ClusterName) error

DeleteReportsForCluster deletes all reports related to the specified cluster from the storage.

func (OCPRecommendationsDBStorage) DeleteReportsForOrg added in v1.4.0

func (storage OCPRecommendationsDBStorage) DeleteReportsForOrg(orgID types.OrgID) error

DeleteReportsForOrg deletes all reports related to the specified organization from the storage.

func (OCPRecommendationsDBStorage) DisableRuleSystemWide added in v1.4.0

func (storage OCPRecommendationsDBStorage) DisableRuleSystemWide(
	orgID types.OrgID,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	justification string,
) error

DisableRuleSystemWide disables the selected rule for all clusters visible to given user

func (OCPRecommendationsDBStorage) DoesClusterExist added in v1.4.0

func (storage OCPRecommendationsDBStorage) DoesClusterExist(clusterID types.ClusterName) (bool, error)

DoesClusterExist checks if cluster with this id exists

func (OCPRecommendationsDBStorage) EnableRuleSystemWide added in v1.4.0

func (storage OCPRecommendationsDBStorage) EnableRuleSystemWide(
	orgID types.OrgID,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
) error

EnableRuleSystemWide enables the selected rule for all clusters visible to given user

func (OCPRecommendationsDBStorage) GetConnection added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetConnection() *sql.DB

GetConnection returns db connection(useful for testing)

func (OCPRecommendationsDBStorage) GetDBDriverType added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetDBDriverType() types.DBDriver

GetDBDriverType returns db driver type

func (OCPRecommendationsDBStorage) GetDBSchema added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetDBSchema() migration.Schema

GetDBSchema returns the schema name to be used in queries

func (OCPRecommendationsDBStorage) GetFromClusterRuleToggle added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetFromClusterRuleToggle(
	clusterID types.ClusterName, ruleID types.RuleID,
) (*ClusterRuleToggle, error)

GetFromClusterRuleToggle gets a rule from cluster_rule_toggle

func (OCPRecommendationsDBStorage) GetMaxVersion added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetMaxVersion() migration.Version

GetMaxVersion returns the highest available migration version. The DB version cannot be set to a value higher than this. This value is equivalent to the length of the list of available migrations.

func (OCPRecommendationsDBStorage) GetMigrations added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetMigrations() []migration.Migration

GetMigrations returns a list of database migrations related to OCP recommendation tables

func (OCPRecommendationsDBStorage) GetOrgIDByClusterID added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetOrgIDByClusterID(cluster types.ClusterName) (types.OrgID, error)

GetOrgIDByClusterID reads OrgID for specified cluster

func (OCPRecommendationsDBStorage) GetRuleHitInsertStatement added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetRuleHitInsertStatement(rules []types.ReportItem) string

GetRuleHitInsertStatement method prepares DB statement to be used to write rule FQDN + rule error key into rule_hit table for given cluster_id

func (*OCPRecommendationsDBStorage) GetRuleRating added in v1.4.0

func (storage *OCPRecommendationsDBStorage) GetRuleRating(
	orgID types.OrgID,
	ruleSelector types.RuleSelector,
) (
	ruleRating types.RuleRating,
	err error,
)

GetRuleRating retrieves rating for given rule and user

func (OCPRecommendationsDBStorage) GetTogglesForRules added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetTogglesForRules(
	clusterID types.ClusterName,
	rulesReport []types.RuleOnReport,
	orgID types.OrgID,
) (map[types.RuleID]bool, error)

GetTogglesForRules gets enable/disable toggle for rules

func (OCPRecommendationsDBStorage) GetUserDisableFeedbackOnRules added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetUserDisableFeedbackOnRules(
	clusterID types.ClusterName, rulesReport []types.RuleOnReport, userID types.UserID,
) (map[types.RuleID]UserFeedbackOnRule, error)

GetUserDisableFeedbackOnRules gets user disable feedbacks for defined array of rule IDs from DB

func (OCPRecommendationsDBStorage) GetUserFeedbackOnRule added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetUserFeedbackOnRule(
	clusterID types.ClusterName, ruleID types.RuleID, errorKey types.ErrorKey, userID types.UserID,
) (*UserFeedbackOnRule, error)

GetUserFeedbackOnRule gets user feedback from DB

func (OCPRecommendationsDBStorage) GetUserFeedbackOnRuleDisable added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetUserFeedbackOnRuleDisable(
	clusterID types.ClusterName, ruleID types.RuleID, errorKey types.ErrorKey, userID types.UserID,
) (*UserFeedbackOnRule, error)

GetUserFeedbackOnRuleDisable gets user feedback from DB

func (OCPRecommendationsDBStorage) GetUserFeedbackOnRules added in v1.4.0

func (storage OCPRecommendationsDBStorage) GetUserFeedbackOnRules(
	clusterID types.ClusterName, rulesReport []types.RuleOnReport, userID types.UserID,
) (map[types.RuleID]types.UserVote, error)

GetUserFeedbackOnRules gets user feedbacks for defined array of rule IDs from DB

func (OCPRecommendationsDBStorage) Init added in v1.4.0

func (storage OCPRecommendationsDBStorage) Init() error

Init performs all database initialization tasks necessary for further service operation.

func (OCPRecommendationsDBStorage) ListOfClustersForOrg added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfClustersForOrg(orgID types.OrgID, timeLimit time.Time) ([]types.ClusterName, error)

ListOfClustersForOrg reads list of all clusters fro given organization

func (OCPRecommendationsDBStorage) ListOfClustersForOrgSpecificRule added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfClustersForOrgSpecificRule(
	orgID types.OrgID,
	ruleID types.RuleSelector,
	activeClusters []string) (
	[]ctypes.HittingClustersData, error)

ListOfClustersForOrgSpecificRule returns list of all clusters for given organization that are affect by given rule

func (OCPRecommendationsDBStorage) ListOfDisabledClusters added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfDisabledClusters(
	orgID types.OrgID,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
) (
	disabledClusters []ctypes.DisabledClusterInfo,
	err error,
)

ListOfDisabledClusters function returns list of all clusters disabled for a rule from a specified account.

func (OCPRecommendationsDBStorage) ListOfDisabledRules added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfDisabledRules(orgID types.OrgID) ([]ctypes.DisabledRule, error)

ListOfDisabledRules function returns list of all rules disabled from a specified account.

func (OCPRecommendationsDBStorage) ListOfDisabledRulesForClusters added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfDisabledRulesForClusters(
	clusterList []string,
	orgID types.OrgID,
) ([]ctypes.DisabledRule, error)

ListOfDisabledRulesForClusters function returns list of all rules disabled from a specified account for given list of clusters.

func (OCPRecommendationsDBStorage) ListOfOrgs added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfOrgs() ([]types.OrgID, error)

ListOfOrgs reads list of all organizations that have at least one cluster report

func (OCPRecommendationsDBStorage) ListOfReasons added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfReasons(userID types.UserID) ([]DisabledRuleReason, error)

ListOfReasons function returns list of reasons for all disabled rules

func (OCPRecommendationsDBStorage) ListOfSystemWideDisabledRules added in v1.4.0

func (storage OCPRecommendationsDBStorage) ListOfSystemWideDisabledRules(
	orgID types.OrgID,
) ([]ctypes.SystemWideRuleDisable, error)

ListOfSystemWideDisabledRules function returns list of all rules that have been disabled for all clusters by given user

func (OCPRecommendationsDBStorage) MigrateToLatest added in v1.4.0

func (storage OCPRecommendationsDBStorage) MigrateToLatest() error

MigrateToLatest migrates the database to the latest available migration version. This must be done before an Init() call.

func (OCPRecommendationsDBStorage) PrintRuleDisableDebugInfo added in v1.4.0

func (storage OCPRecommendationsDBStorage) PrintRuleDisableDebugInfo()

PrintRuleDisableDebugInfo is a temporary helper function used to print form cluster rule toggle related tables

func (OCPRecommendationsDBStorage) PrintRuleDisableFeedbacks added in v1.4.0

func (storage OCPRecommendationsDBStorage) PrintRuleDisableFeedbacks() error

PrintRuleDisableFeedbacks prints enable/disable feedback counts for all rules TEMPORARY because we currently don't have access to stage database when testing migrations.

func (OCPRecommendationsDBStorage) PrintRuleToggles added in v1.4.0

func (storage OCPRecommendationsDBStorage) PrintRuleToggles() error

PrintRuleToggles prints enable/disable counts for all rules TEMPORARY because we currently don't have access to stage database when testing migrations.

func (*OCPRecommendationsDBStorage) RateOnRule added in v1.4.0

func (storage *OCPRecommendationsDBStorage) RateOnRule(
	orgID types.OrgID,
	ruleFqdn types.RuleID,
	errorKey types.ErrorKey,
	rating types.UserVote,
) error

RateOnRule function stores the vote (rating) from a given user to a rule+error key

func (OCPRecommendationsDBStorage) ReadClusterListRecommendations added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadClusterListRecommendations(
	clusterList []string,
	orgID types.OrgID,
) (ctypes.ClusterRecommendationMap, error)

ReadClusterListRecommendations retrieves cluster IDs and a list of hitting rules for each one

func (*OCPRecommendationsDBStorage) ReadClusterVersionsForClusterList added in v1.4.0

func (storage *OCPRecommendationsDBStorage) ReadClusterVersionsForClusterList(
	orgID types.OrgID,
	clusterList []string,
) (map[types.ClusterName]types.Version, error)

ReadClusterVersionsForClusterList retrieve the cluster version for a given cluster list and org id

func (OCPRecommendationsDBStorage) ReadDisabledRule added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadDisabledRule(
	orgID types.OrgID, ruleID types.RuleID, errorKey types.ErrorKey,
) (ctypes.SystemWideRuleDisable, bool, error)

ReadDisabledRule function returns disabled rule (if disabled) from database

func (OCPRecommendationsDBStorage) ReadOrgIDsForClusters added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadOrgIDsForClusters(clusterNames []types.ClusterName) ([]types.OrgID, error)

ReadOrgIDsForClusters read organization IDs for given list of cluster names.

func (OCPRecommendationsDBStorage) ReadRecommendationsForClusters added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadRecommendationsForClusters(
	clusterList []string,
	orgID types.OrgID,
) (ctypes.RecommendationImpactedClusters, error)

ReadRecommendationsForClusters reads all recommendations from recommendation table for given organization

func (OCPRecommendationsDBStorage) ReadReportForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadReportForCluster(
	orgID types.OrgID, clusterName types.ClusterName,
) ([]types.RuleOnReport, types.Timestamp, types.Timestamp, types.Timestamp, error)

ReadReportForCluster reads result (health status) for selected cluster

func (OCPRecommendationsDBStorage) ReadReportForClusterByClusterName added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadReportForClusterByClusterName(
	clusterName types.ClusterName,
) ([]types.RuleOnReport, types.Timestamp, error)

ReadReportForClusterByClusterName reads result (health status) for selected cluster for given organization

func (*OCPRecommendationsDBStorage) ReadReportInfoForCluster added in v1.4.0

func (storage *OCPRecommendationsDBStorage) ReadReportInfoForCluster(
	orgID types.OrgID,
	clusterName types.ClusterName,
) (types.Version, error)

ReadReportInfoForCluster retrieve the Version for a given cluster and org id

func (OCPRecommendationsDBStorage) ReadReportsForClusters added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadReportsForClusters(clusterNames []types.ClusterName) (map[types.ClusterName]types.ClusterReport, error)

ReadReportsForClusters function reads reports for given list of cluster names.

func (OCPRecommendationsDBStorage) ReadSingleRuleTemplateData added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReadSingleRuleTemplateData(
	orgID types.OrgID, clusterName types.ClusterName, ruleID types.RuleID, errorKey types.ErrorKey,
) (interface{}, error)

ReadSingleRuleTemplateData reads template data for a single rule

func (OCPRecommendationsDBStorage) ReportsCount added in v1.4.0

func (storage OCPRecommendationsDBStorage) ReportsCount() (int, error)

ReportsCount reads number of all records stored in database

func (OCPRecommendationsDBStorage) ToggleRuleForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) ToggleRuleForCluster(
	clusterID types.ClusterName,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	orgID types.OrgID,
	ruleToggle RuleToggle,
) error

ToggleRuleForCluster toggles rule for specified cluster

func (OCPRecommendationsDBStorage) UpdateDisabledRuleJustification added in v1.4.0

func (storage OCPRecommendationsDBStorage) UpdateDisabledRuleJustification(
	orgID types.OrgID,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	justification string,
) error

UpdateDisabledRuleJustification change justification for already disabled rule

func (OCPRecommendationsDBStorage) VoteOnRule added in v1.4.0

func (storage OCPRecommendationsDBStorage) VoteOnRule(
	clusterID types.ClusterName,
	ruleID types.RuleID,
	errorKey types.ErrorKey,
	orgID types.OrgID,
	userID types.UserID,
	userVote types.UserVote,
	voteMessage string,
) error

VoteOnRule likes or dislikes rule for cluster by user. If entry exists, it overwrites it

func (OCPRecommendationsDBStorage) WriteConsumerError added in v1.4.0

func (storage OCPRecommendationsDBStorage) WriteConsumerError(msg *sarama.ConsumerMessage, consumerErr error) error

WriteConsumerError writes a report about a consumer error into the storage.

func (OCPRecommendationsDBStorage) WriteRecommendationsForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) WriteRecommendationsForCluster(
	orgID types.OrgID,
	clusterName types.ClusterName,
	stringReport types.ClusterReport,
	creationTime types.Timestamp,
) (err error)

WriteRecommendationsForCluster writes hitting rules in received report for selected cluster

func (OCPRecommendationsDBStorage) WriteReportForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) WriteReportForCluster(
	orgID types.OrgID,
	clusterName types.ClusterName,
	report types.ClusterReport,
	rules []types.ReportItem,
	lastCheckedTime time.Time,
	gatheredAt time.Time,
	storedAtTime time.Time,
	_ types.RequestID,
) error

WriteReportForCluster writes result (health status) for selected cluster for given organization

func (OCPRecommendationsDBStorage) WriteReportInfoForCluster added in v1.4.0

func (storage OCPRecommendationsDBStorage) WriteReportInfoForCluster(
	orgID types.OrgID,
	clusterName types.ClusterName,
	info []types.InfoItem,
	_ time.Time,
) error

WriteReportInfoForCluster writes the relevant report info for selected cluster for hiven organization

type OCPRecommendationsStorage added in v1.4.0

type OCPRecommendationsStorage interface {
	Init() error
	Close() error
	ListOfOrgs() ([]types.OrgID, error)
	ListOfClustersForOrg(
		orgID types.OrgID, timeLimit time.Time) ([]types.ClusterName, error,
	)
	ListOfClustersForOrgSpecificRule(
		orgID types.OrgID, ruleID types.RuleSelector, activeClusters []string,
	) ([]ctypes.HittingClustersData, error)
	ReadReportForCluster(
		orgID types.OrgID, clusterName types.ClusterName) (
		[]types.RuleOnReport, types.Timestamp, types.Timestamp, types.Timestamp, error,
	)
	ReadReportInfoForCluster(
		types.OrgID, types.ClusterName) (
		types.Version, error,
	)
	ReadClusterVersionsForClusterList(
		types.OrgID, []string,
	) (map[types.ClusterName]types.Version, error)
	ReadReportsForClusters(
		clusterNames []types.ClusterName) (map[types.ClusterName]types.ClusterReport, error)
	ReadOrgIDsForClusters(
		clusterNames []types.ClusterName) ([]types.OrgID, error)
	ReadSingleRuleTemplateData(
		orgID types.OrgID, clusterName types.ClusterName, ruleID types.RuleID, errorKey types.ErrorKey,
	) (interface{}, error)
	ReadReportForClusterByClusterName(clusterName types.ClusterName) ([]types.RuleOnReport, types.Timestamp, error)
	WriteReportForCluster(
		orgID types.OrgID,
		clusterName types.ClusterName,
		report types.ClusterReport,
		rules []types.ReportItem,
		collectedAtTime time.Time,
		gatheredAtTime time.Time,
		storedAtTime time.Time,
		requestID types.RequestID,
	) error
	WriteReportInfoForCluster(
		types.OrgID,
		types.ClusterName,
		[]types.InfoItem,
		time.Time,
	) error
	WriteRecommendationsForCluster(
		orgID types.OrgID,
		clusterName types.ClusterName,
		report types.ClusterReport,
		creationTime types.Timestamp,
	) error
	ReportsCount() (int, error)
	VoteOnRule(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		orgID types.OrgID,
		userID types.UserID,
		userVote types.UserVote,
		voteMessage string,
	) error
	AddOrUpdateFeedbackOnRule(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		orgID types.OrgID,
		userID types.UserID,
		message string,
	) error
	AddFeedbackOnRuleDisable(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		orgID types.OrgID,
		userID types.UserID,
		message string,
	) error
	GetUserFeedbackOnRule(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		userID types.UserID,
	) (*UserFeedbackOnRule, error)
	GetUserFeedbackOnRuleDisable(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		userID types.UserID,
	) (*UserFeedbackOnRule, error)
	DeleteReportsForOrg(orgID types.OrgID) error
	DeleteReportsForCluster(clusterName types.ClusterName) error
	ToggleRuleForCluster(
		clusterID types.ClusterName,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		orgID types.OrgID,
		ruleToggle RuleToggle,
	) error
	GetFromClusterRuleToggle(
		types.ClusterName,
		types.RuleID,
	) (*ClusterRuleToggle, error)
	GetTogglesForRules(
		clusterID types.ClusterName,
		rulesReport []types.RuleOnReport,
		orgID types.OrgID,
	) (map[types.RuleID]bool, error)
	DeleteFromRuleClusterToggle(
		clusterID types.ClusterName,
		ruleID types.RuleID,
	) error
	GetOrgIDByClusterID(cluster types.ClusterName) (types.OrgID, error)
	WriteConsumerError(msg *sarama.ConsumerMessage, consumerErr error) error
	GetUserFeedbackOnRules(
		clusterID types.ClusterName,
		rulesReport []types.RuleOnReport,
		userID types.UserID,
	) (map[types.RuleID]types.UserVote, error)
	GetUserDisableFeedbackOnRules(
		clusterID types.ClusterName,
		rulesReport []types.RuleOnReport,
		userID types.UserID,
	) (map[types.RuleID]UserFeedbackOnRule, error)
	DoesClusterExist(clusterID types.ClusterName) (bool, error)
	ListOfDisabledRules(orgID types.OrgID) ([]ctypes.DisabledRule, error)
	ListOfReasons(userID types.UserID) ([]DisabledRuleReason, error)
	ListOfDisabledRulesForClusters(
		clusterList []string,
		orgID types.OrgID,
	) ([]ctypes.DisabledRule, error)
	ListOfDisabledClusters(
		orgID types.OrgID,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
	) ([]ctypes.DisabledClusterInfo, error)
	RateOnRule(
		types.OrgID,
		types.RuleID,
		types.ErrorKey,
		types.UserVote,
	) error
	GetRuleRating(
		types.OrgID,
		types.RuleSelector,
	) (types.RuleRating, error)
	DisableRuleSystemWide(
		orgID types.OrgID, ruleID types.RuleID,
		errorKey types.ErrorKey, justification string,
	) error
	EnableRuleSystemWide(
		orgID types.OrgID,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
	) error
	UpdateDisabledRuleJustification(
		orgID types.OrgID,
		ruleID types.RuleID,
		errorKey types.ErrorKey,
		justification string,
	) error
	ReadDisabledRule(
		orgID types.OrgID, ruleID types.RuleID, errorKey types.ErrorKey,
	) (ctypes.SystemWideRuleDisable, bool, error)
	ListOfSystemWideDisabledRules(
		orgID types.OrgID,
	) ([]ctypes.SystemWideRuleDisable, error)
	ReadRecommendationsForClusters([]string, types.OrgID) (ctypes.RecommendationImpactedClusters, error)
	ReadClusterListRecommendations(clusterList []string, orgID types.OrgID) (
		ctypes.ClusterRecommendationMap, error,
	)
	MigrateToLatest() error
	GetConnection() *sql.DB
	PrintRuleDisableDebugInfo()
	GetDBDriverType() types.DBDriver
	GetMigrations() []migration.Migration
	GetDBSchema() migration.Schema
	GetMaxVersion() migration.Version
}

OCPRecommendationsStorage represents an interface to almost any database or storage system

func NewOCPRecommendationsStorage added in v1.4.0

func NewOCPRecommendationsStorage(configuration Configuration) (OCPRecommendationsStorage, error)

NewOCPRecommendationsStorage function creates and initializes a new instance of Storage interface

type RedisConfiguration added in v1.4.0

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 RedisStorage added in v1.4.0

type RedisStorage struct {
	Client     redis.Client
	Expiration time.Duration
}

RedisStorage represents a storage which does nothing (for benchmarking without a storage)

func (*RedisStorage) AddFeedbackOnRuleDisable added in v1.4.0

func (*RedisStorage) AddFeedbackOnRuleDisable(
	types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, types.UserID, string,
) error

AddFeedbackOnRuleDisable noop

func (*RedisStorage) AddOrUpdateFeedbackOnRule added in v1.4.0

func (*RedisStorage) AddOrUpdateFeedbackOnRule(
	types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, types.UserID, string,
) error

AddOrUpdateFeedbackOnRule noop

func (*RedisStorage) Close added in v1.4.0

func (storage *RedisStorage) Close() error

Close noop

func (*RedisStorage) CreateRule added in v1.4.0

func (*RedisStorage) CreateRule(types.Rule) error

CreateRule noop

func (*RedisStorage) CreateRuleErrorKey added in v1.4.0

func (*RedisStorage) CreateRuleErrorKey(types.RuleErrorKey) error

CreateRuleErrorKey noop

func (*RedisStorage) DeleteFromRuleClusterToggle added in v1.4.0

func (*RedisStorage) DeleteFromRuleClusterToggle(
	types.ClusterName, types.RuleID) error

DeleteFromRuleClusterToggle noop

func (*RedisStorage) DeleteReportsForCluster added in v1.4.0

func (*RedisStorage) DeleteReportsForCluster(types.ClusterName) error

DeleteReportsForCluster noop

func (*RedisStorage) DeleteReportsForOrg added in v1.4.0

func (*RedisStorage) DeleteReportsForOrg(types.OrgID) error

DeleteReportsForOrg noop

func (*RedisStorage) DeleteRule added in v1.4.0

func (*RedisStorage) DeleteRule(types.RuleID) error

DeleteRule noop

func (*RedisStorage) DeleteRuleErrorKey added in v1.4.0

func (*RedisStorage) DeleteRuleErrorKey(types.RuleID, types.ErrorKey) error

DeleteRuleErrorKey noop

func (*RedisStorage) DisableRuleSystemWide added in v1.4.0

func (*RedisStorage) DisableRuleSystemWide(
	_ types.OrgID, _ types.RuleID,
	_ types.ErrorKey, _ string,
) error

DisableRuleSystemWide disables the selected rule for all clusters visible to given user

func (*RedisStorage) DoesClusterExist added in v1.4.0

func (*RedisStorage) DoesClusterExist(types.ClusterName) (bool, error)

DoesClusterExist noop

func (*RedisStorage) EnableRuleSystemWide added in v1.4.0

func (*RedisStorage) EnableRuleSystemWide(
	_ types.OrgID, _ types.RuleID, _ types.ErrorKey,
) error

EnableRuleSystemWide enables the selected rule for all clusters visible to given user

func (*RedisStorage) GetConnection added in v1.4.0

func (*RedisStorage) GetConnection() *sql.DB

GetConnection returns db connection(useful for testing)

func (*RedisStorage) GetDBDriverType added in v1.4.0

func (*RedisStorage) GetDBDriverType() types.DBDriver

GetDBDriverType returns db driver type

func (*RedisStorage) GetDBSchema added in v1.4.0

func (*RedisStorage) GetDBSchema() migration.Schema

GetDBSchema returns db schema (unused for Redis)

func (*RedisStorage) GetFromClusterRuleToggle added in v1.4.0

func (*RedisStorage) GetFromClusterRuleToggle(
	types.ClusterName,
	types.RuleID,
) (*ClusterRuleToggle, error)

GetFromClusterRuleToggle noop

func (*RedisStorage) GetMaxVersion added in v1.4.0

func (storage *RedisStorage) GetMaxVersion() migration.Version

GetMaxVersion noop

func (*RedisStorage) GetMigrations added in v1.4.0

func (storage *RedisStorage) GetMigrations() []migration.Migration

GetMigrations noop

func (*RedisStorage) GetOrgIDByClusterID added in v1.4.0

func (*RedisStorage) GetOrgIDByClusterID(types.ClusterName) (types.OrgID, error)

GetOrgIDByClusterID noop

func (*RedisStorage) GetRuleByID added in v1.4.0

func (*RedisStorage) GetRuleByID(types.RuleID) (*types.Rule, error)

GetRuleByID noop

func (*RedisStorage) GetRuleRating added in v1.4.0

func (*RedisStorage) GetRuleRating(
	_ types.OrgID,
	_ types.RuleSelector,
) (
	ruleRating types.RuleRating,
	err error,
)

GetRuleRating retrieves rating for given rule and user

func (*RedisStorage) GetRuleWithContent added in v1.4.0

func (*RedisStorage) GetRuleWithContent(
	types.RuleID, types.ErrorKey,
) (*types.RuleWithContent, error)

GetRuleWithContent noop

func (*RedisStorage) GetTogglesForRules added in v1.4.0

func (*RedisStorage) GetTogglesForRules(
	types.ClusterName,
	[]types.RuleOnReport,
	types.OrgID,
) (map[types.RuleID]bool, error)

GetTogglesForRules noop

func (*RedisStorage) GetUserDisableFeedbackOnRules added in v1.4.0

func (*RedisStorage) GetUserDisableFeedbackOnRules(
	types.ClusterName, []types.RuleOnReport, types.UserID,
) (map[types.RuleID]UserFeedbackOnRule, error)

GetUserDisableFeedbackOnRules noop

func (*RedisStorage) GetUserFeedbackOnRule added in v1.4.0

GetUserFeedbackOnRule noop

func (*RedisStorage) GetUserFeedbackOnRuleDisable added in v1.4.0

func (*RedisStorage) GetUserFeedbackOnRuleDisable(
	types.ClusterName, types.RuleID, types.ErrorKey, types.UserID,
) (*UserFeedbackOnRule, error)

GetUserFeedbackOnRuleDisable noop

func (*RedisStorage) GetUserFeedbackOnRules added in v1.4.0

func (*RedisStorage) GetUserFeedbackOnRules(
	types.ClusterName,
	[]types.RuleOnReport,
	types.UserID,
) (map[types.RuleID]types.UserVote, error)

GetUserFeedbackOnRules noop

func (*RedisStorage) Init added in v1.4.0

func (storage *RedisStorage) Init() error

Init method initializes Redis storage

func (*RedisStorage) ListOfClustersForOrg added in v1.4.0

func (*RedisStorage) ListOfClustersForOrg(types.OrgID, time.Time) ([]types.ClusterName, error)

ListOfClustersForOrg noop

func (*RedisStorage) ListOfClustersForOrgSpecificRule added in v1.4.0

func (*RedisStorage) ListOfClustersForOrgSpecificRule(
	_ types.OrgID, _ types.RuleSelector, _ []string,
) ([]ctypes.HittingClustersData, error)

ListOfClustersForOrgSpecificRule returns list of all clusters for given organization that are affected by given rule

func (*RedisStorage) ListOfDisabledClusters added in v1.4.0

func (*RedisStorage) ListOfDisabledClusters(
	_ types.OrgID,
	_ types.RuleID,
	_ types.ErrorKey,
) ([]ctypes.DisabledClusterInfo, error)

ListOfDisabledClusters function returns list of all clusters disabled for a rule from a specified account (noop).

func (*RedisStorage) ListOfDisabledRules added in v1.4.0

func (*RedisStorage) ListOfDisabledRules(_ types.OrgID) ([]ctypes.DisabledRule, error)

ListOfDisabledRules function returns list of all rules disabled from a specified account (noop).

func (*RedisStorage) ListOfDisabledRulesForClusters added in v1.4.0

func (*RedisStorage) ListOfDisabledRulesForClusters(
	_ []string,
	_ types.OrgID,
) ([]ctypes.DisabledRule, error)

ListOfDisabledRulesForClusters function returns list of disabled rules for given clusters from a specified account (noop).

func (*RedisStorage) ListOfOrgs added in v1.4.0

func (*RedisStorage) ListOfOrgs() ([]types.OrgID, error)

ListOfOrgs noop

func (*RedisStorage) ListOfReasons added in v1.4.0

func (*RedisStorage) ListOfReasons(_ types.UserID) ([]DisabledRuleReason, error)

ListOfReasons function returns list of reasons for all rules disabled from a specified account (noop).

func (*RedisStorage) ListOfSystemWideDisabledRules added in v1.4.0

func (*RedisStorage) ListOfSystemWideDisabledRules(
	_ types.OrgID,
) ([]ctypes.SystemWideRuleDisable, error)

ListOfSystemWideDisabledRules function returns list of all rules that have been disabled for all clusters by given user

func (*RedisStorage) MigrateToLatest added in v1.4.0

func (*RedisStorage) MigrateToLatest() error

MigrateToLatest migrates the database to the latest available migration version. This must be done before an Init() call.

func (*RedisStorage) PrintRuleDisableDebugInfo added in v1.4.0

func (*RedisStorage) PrintRuleDisableDebugInfo()

PrintRuleDisableDebugInfo is a temporary helper function used to print form cluster rule toggle related tables

func (*RedisStorage) RateOnRule added in v1.4.0

RateOnRule function stores the vote (rating) given by an user to a rule+error key

func (*RedisStorage) ReadClusterListRecommendations added in v1.4.0

func (*RedisStorage) ReadClusterListRecommendations(
	_ []string, _ types.OrgID,
) (ctypes.ClusterRecommendationMap, error)

ReadClusterListRecommendations retrieves cluster IDs and a list of hitting rules for each one

func (*RedisStorage) ReadClusterVersionsForClusterList added in v1.4.0

func (*RedisStorage) ReadClusterVersionsForClusterList(
	types.OrgID, []string,
) (map[types.ClusterName]types.Version, error)

ReadClusterVersionsForClusterList noop

func (*RedisStorage) ReadDisabledRule added in v1.4.0

ReadDisabledRule function returns disabled rule (if disabled) from database

func (*RedisStorage) ReadOrgIDsForClusters added in v1.4.0

func (*RedisStorage) ReadOrgIDsForClusters(_ []types.ClusterName) ([]types.OrgID, error)

ReadOrgIDsForClusters read organization IDs for given list of cluster names.

func (*RedisStorage) ReadRecommendationsForClusters added in v1.4.0

func (*RedisStorage) ReadRecommendationsForClusters(
	_ []string,
	_ types.OrgID,
) (ctypes.RecommendationImpactedClusters, error)

ReadRecommendationsForClusters reads all recommendations from recommendation table for given organization

func (*RedisStorage) ReadReportForCluster added in v1.4.0

ReadReportForCluster noop

func (*RedisStorage) ReadReportForClusterByClusterName added in v1.4.0

func (*RedisStorage) ReadReportForClusterByClusterName(
	types.ClusterName,
) ([]types.RuleOnReport, types.Timestamp, error)

ReadReportForClusterByClusterName noop

func (*RedisStorage) ReadReportInfoForCluster added in v1.4.0

func (*RedisStorage) ReadReportInfoForCluster(types.OrgID, types.ClusterName) (types.Version, error)

ReadReportInfoForCluster noop

func (*RedisStorage) ReadReportsForClusters added in v1.4.0

func (*RedisStorage) ReadReportsForClusters(_ []types.ClusterName) (map[types.ClusterName]types.ClusterReport, error)

ReadReportsForClusters function reads reports for given list of cluster names.

func (*RedisStorage) ReadSingleRuleTemplateData added in v1.4.0

func (*RedisStorage) ReadSingleRuleTemplateData(types.OrgID, types.ClusterName, types.RuleID, types.ErrorKey) (interface{}, error)

ReadSingleRuleTemplateData noop

func (*RedisStorage) ReportsCount added in v1.4.0

func (*RedisStorage) ReportsCount() (int, error)

ReportsCount noop

func (*RedisStorage) ToggleRuleForCluster added in v1.4.0

ToggleRuleForCluster noop

func (*RedisStorage) UpdateDisabledRuleJustification added in v1.4.0

func (*RedisStorage) UpdateDisabledRuleJustification(
	_ types.OrgID,
	_ types.RuleID,
	_ types.ErrorKey,
	_ string,
) error

UpdateDisabledRuleJustification change justification for already disabled rule

func (*RedisStorage) VoteOnRule added in v1.4.0

VoteOnRule noop

func (*RedisStorage) WriteConsumerError added in v1.4.0

func (*RedisStorage) WriteConsumerError(*sarama.ConsumerMessage, error) error

WriteConsumerError noop

func (*RedisStorage) WriteRecommendationsForCluster added in v1.4.0

func (*RedisStorage) WriteRecommendationsForCluster(
	types.OrgID, types.ClusterName, types.ClusterReport, types.Timestamp,
) error

WriteRecommendationsForCluster noop

func (*RedisStorage) WriteReportForCluster added in v1.4.0

func (storage *RedisStorage) WriteReportForCluster(
	orgID types.OrgID, clusterName types.ClusterName, _ types.ClusterReport,
	reportItems []types.ReportItem,
	_ time.Time, gatheredAtTime time.Time, storedAtTime time.Time,
	requestID types.RequestID,
) error

WriteReportForCluster method writes rule hits and other information about new report into Redis storage

func (*RedisStorage) WriteReportInfoForCluster added in v1.4.0

func (*RedisStorage) WriteReportInfoForCluster(
	_ types.OrgID,
	_ types.ClusterName,
	_ []types.InfoItem,
	_ time.Time,
) error

WriteReportInfoForCluster noop

type Report

type Report struct {
	Org        types.OrgID         `json:"org"`
	Name       types.ClusterName   `json:"cluster"`
	Report     types.ClusterReport `json:"report"`
	ReportedAt types.Timestamp     `json:"reported_at"`
}

Report represents one (latest) cluster report.

Org: organization ID
Name: cluster GUID in the following format:
    c8590f31-e97e-4b85-b506-c45ce1911a12

type RuleToggle

type RuleToggle int

RuleToggle is a type for user's vote

const (
	// RuleToggleDisable indicates the rule has been disabled
	RuleToggleDisable RuleToggle = 1
	// RuleToggleEnable indicates the rule has been (re)enabled
	RuleToggleEnable RuleToggle = 0
)

type Storage

type Storage interface {
	Init() error
	Close() error
	GetConnection() *sql.DB
	GetMigrations() []migration.Migration
	GetDBDriverType() types.DBDriver
	GetDBSchema() migration.Schema
	GetMaxVersion() migration.Version
	MigrateToLatest() error
}

Storage represents an interface to almost any database or storage system

type UserFeedbackOnRule

type UserFeedbackOnRule struct {
	ClusterID types.ClusterName
	RuleID    types.RuleID
	ErrorKey  types.ErrorKey
	UserID    types.UserID
	Message   string
	UserVote  types.UserVote
	AddedAt   time.Time
	UpdatedAt time.Time
}

UserFeedbackOnRule shows user's feedback on rule

Jump to

Keyboard shortcuts

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