Documentation ¶
Overview ¶
Package server contains implementation of REST API server (HTTPServer) for the Insights results aggregator service. In current version, the following REST API endpoints are available:
API_PREFIX/organizations - list of all organizations (HTTP GET)
API_PREFIX/organizations/{organization}/clusters - list of all clusters for given organization (HTTP GET)
API_PREFIX/report/{organization}/{cluster} - insights OCP results for given cluster name (HTTP GET)
API_PREFIX/rule/{cluster}/{rule_id}/like - like a rule for cluster with current user (from auth token)
API_PREFIX/rule/{cluster}/{rule_id}/dislike - dislike a rule for cluster with current user (from auth token)
API_PREFIX/rule/{cluster}/{rule_id}/reset_vote- reset vote for a rule for cluster with current user (from auth token)
Please note that API_PREFIX is part of server configuration (see Configuration). Also please note that JSON format is used to transfer data between server and clients.
Configuration:
It is possible to configure the HTTP server. Currently, two configuration options are available and can be changed by using Configuration structure:
Address - usually just in a form ":8080", ie. just the port needs to be configured in most cases APIPrefix - usually "/api/v1/" used for all REST API calls
Index ¶
- Constants
- type Cluster
- type Configuration
- type DVOObject
- type DVORecommendation
- type ForbiddenError
- type HTTPServer
- func (server *HTTPServer) Authentication(next http.Handler, noAuthURLs []string) http.Handler
- func (server *HTTPServer) GetCurrentUserID(request *http.Request) (types.UserID, error)
- func (server *HTTPServer) Initialize() http.Handler
- func (server *HTTPServer) RuleClusterDetailEndpoint(writer http.ResponseWriter, request *http.Request)
- func (server *HTTPServer) Start(serverInstanceReady context.CancelFunc) error
- func (server *HTTPServer) Stop(ctx context.Context) error
- type Identity
- type Metadata
- type Namespace
- type NoBodyError
- type RouterMissingParamError
- type RouterParsingError
- type SystemWideRuleSelector
- type Token
- type UnauthorizedError
- type WorkloadsForCluster
- type WorkloadsForNamespace
Constants ¶
const ( // MainEndpoint returns status ok MainEndpoint = "" // DeleteOrganizationsEndpoint deletes all {organizations}(comma separated array). DEBUG only DeleteOrganizationsEndpoint = "organizations/{organizations}" // DeleteClustersEndpoint deletes all {clusters}(comma separated array). DEBUG only DeleteClustersEndpoint = "clusters/{clusters}" // OrganizationsEndpoint returns all organizations OrganizationsEndpoint = "organizations" // ReportEndpoint returns report for provided {organization}, {cluster}, and {user_id} ReportEndpoint = "organizations/{org_id}/clusters/{cluster}/users/{user_id}/report" // ReportMetainfoEndpoint returns (meta)information about report for provided {organization} {cluster} and {user_id} ReportMetainfoEndpoint = "organizations/{org_id}/clusters/{cluster}/users/{user_id}/report/info" // RuleEndpoint returns rule report for provided {organization} {cluster} and {rule_id} RuleEndpoint = "organizations/{org_id}/clusters/{cluster}/users/{user_id}/rules/{rule_id}" // ReportForListOfClustersEndpoint returns rule returns reports for provided list of clusters // Reports that are going to be returned are specified by list of cluster IDs that is part of path ReportForListOfClustersEndpoint = "organizations/{org_id}/clusters/{cluster_list}/reports" // ReportForListOfClustersPayloadEndpoint returns the latest reports for the given list of clusters // Reports that are going to be returned are specified by list of cluster IDs that is part of request body ReportForListOfClustersPayloadEndpoint = "organizations/{org_id}/clusters/reports" // LikeRuleEndpoint likes rule with {rule_id} for {cluster} using current user(from auth header) LikeRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/users/{user_id}/like" // DislikeRuleEndpoint dislikes rule with {rule_id} for {cluster} using current user(from auth header) DislikeRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/users/{user_id}/dislike" // ResetVoteOnRuleEndpoint resets vote on rule with {rule_id} for {cluster} using current user(from auth header) ResetVoteOnRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/users/{user_id}/reset_vote" // GetVoteOnRuleEndpoint is an endpoint to get vote on rule. DEBUG only GetVoteOnRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/users/{user_id}/get_vote" // ClustersForOrganizationEndpoint returns all clusters for {organization} ClustersForOrganizationEndpoint = "organizations/{organization}/clusters" // DisableRuleForClusterEndpoint disables a rule for specified cluster DisableRuleForClusterEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/disable" // EnableRuleForClusterEndpoint re-enables a rule for specified cluster EnableRuleForClusterEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/enable" // DisableRuleFeedbackEndpoint accepts a feedback from user when (s)he disables a rule DisableRuleFeedbackEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/users/{user_id}/disable_feedback" // ListOfDisabledRules returns a list of rules disabled from current account ListOfDisabledRules = "rules/organizations/{org_id}/disabled" // ListOfDisabledRulesForClusters returns a list of rules disabled from current organization for given list of clusters in POST body ListOfDisabledRulesForClusters = "rules/organizations/{org_id}/disabled_for_clusters" // ListOfDisabledRulesFeedback returns a list of reasons why rule has been disabled ListOfDisabledRulesFeedback = "rules/users/{user_id}/disabled/feedback" // ListOfDisabledClusters returns a list of clusters which the user disabled for a rule with latest justification ListOfDisabledClusters = "clusters/rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/disabled" // RuleClusterDetailEndpoint returns a list of clusters affected by a given rule for current account RuleClusterDetailEndpoint = "rules/{rule_selector}/organizations/{org_id}/users/{user_id}/clusters_detail" // EnableRuleSystemWide re-enables a rule for all clusters EnableRuleSystemWide = "rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/enable" // DisableRuleSystemWide disables a rule for all clusters DisableRuleSystemWide = "rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/disable" // UpdateRuleSystemWide updates disable justification of a rule for all clusters UpdateRuleSystemWide = "rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/update" // ReadRuleSystemWide queries rule disabled system-wide ReadRuleSystemWide = "rules/{rule_id}/error_key/{error_key}/organizations/{org_id}/" // ListOfDisabledRulesSystemWide returns a list of rules disabled from current account ListOfDisabledRulesSystemWide = "rules/organizations/{org_id}/disabled_system_wide" // RecommendationsListEndpoint receives a list of clusters in POST body and returns a list of all recommendations hitting for them RecommendationsListEndpoint = "recommendations/organizations/{org_id}/users/{user_id}/list" // ClustersRecommendationsListEndpoint receives a list of clusters in POST body and returns a list of clusters with lists of hitting recommendations ClustersRecommendationsListEndpoint = "clusters/organizations/{org_id}/users/{user_id}/recommendations" // DVOWorkloadRecommendations returns a list of cluster + namespace workloads for given organization ID. DVOWorkloadRecommendations = "organization/{org_id}/workloads" // DVOWorkloadRecommendationsSingleNamespace returns workloads for a single cluster + namespace ID. DVOWorkloadRecommendationsSingleNamespace = "organization/{org_id}/namespace/{namespace}/cluster/{cluster}/workloads" // Rating accepts a list of ratings in the request body and store them in the database for the given user Rating = "rules/organizations/{org_id}/rating" // GetRating retrieves the rating for a specific rule and user GetRating = "rules/{rule_selector}/organizations/{org_id}/rating" // InfoEndpoint returns basic information about Insights Aggregator // version, utils repository version, commit hash etc. InfoEndpoint = "info" // MetricsEndpoint returns prometheus metrics MetricsEndpoint = "metrics" )
const ( // ReportResponse constant defines the name of response field ReportResponse = "report" // ReportResponseMetainfo constant defines the name of response field ReportResponseMetainfo = "metainfo" )
const (
// OkStatusPayload is the text returned as body payload when an OK Status request is sent
OkStatusPayload = "ok"
)
const (
// RecommendationSuffix is used to strip a suffix from rule ID
RecommendationSuffix = ".recommendation"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration struct { Address string `mapstructure:"address" toml:"address"` APIPrefix string `mapstructure:"api_prefix" toml:"api_prefix"` APISpecFile string `mapstructure:"api_spec_file" toml:"api_spec_file"` Debug bool `mapstructure:"debug" toml:"debug"` Auth bool `mapstructure:"auth" toml:"auth"` AuthType string `mapstructure:"auth_type" toml:"auth_type"` MaximumFeedbackMessageLength int `mapstructure:"maximum_feedback_message_length" toml:"maximum_feedback_message_length"` // OrgOverviewLimitHours is temporary until request param parsing, but lets make it atleast configurable OrgOverviewLimitHours int64 `mapstructure:"org_overview_limit_hours" toml:"org_overview_limit_hours"` }
Configuration represents configuration of REST API HTTP server
type DVORecommendation ¶ added in v1.4.0
type DVORecommendation struct { Check string `json:"check"` Details string `json:"details"` Resolution string `json:"resolution"` Modified string `json:"modified"` MoreInfo string `json:"more_info"` TemplateData map[string]interface{} `json:"extra_data"` Objects []DVOObject `json:"objects"` }
DVORecommendation structure represents one DVO-related recommendation
type ForbiddenError ¶ added in v1.1.1
type ForbiddenError = operator_utils_types.ForbiddenError
ForbiddenError means you don't have permission to do a particular action,
type HTTPServer ¶
type HTTPServer struct { Config Configuration Storage storage.OCPRecommendationsStorage StorageDvo storage.DVORecommendationsStorage Serv *http.Server InfoParams map[string]string InfoParamsDVO map[string]string }
HTTPServer in an implementation of Server interface
func New ¶
func New(config Configuration, storage storage.OCPRecommendationsStorage, storageDVO storage.DVORecommendationsStorage) *HTTPServer
New constructs new implementation of Server interface
func (*HTTPServer) Authentication ¶
Authentication middleware for checking auth rights
func (*HTTPServer) GetCurrentUserID ¶
GetCurrentUserID retrieves current user's id from request
func (*HTTPServer) Initialize ¶
func (server *HTTPServer) Initialize() http.Handler
Initialize perform the server initialization
func (*HTTPServer) RuleClusterDetailEndpoint ¶ added in v1.1.8
func (server *HTTPServer) RuleClusterDetailEndpoint(writer http.ResponseWriter, request *http.Request)
RuleClusterDetailEndpoint returns a list of clusters were the given rule is currently hitting
func (*HTTPServer) Start ¶
func (server *HTTPServer) Start(serverInstanceReady context.CancelFunc) error
Start starts server
type Metadata ¶ added in v1.4.0
type Metadata struct { Recommendations int `json:"recommendations"` Objects int `json:"objects"` ReportedAt string `json:"reported_at"` LastCheckedAt string `json:"last_checked_at"` HighestSeverity int `json:"highest_severity"` HitsBySeverity map[int]int `json:"hits_by_severity"` }
Metadata structure contains basic information about workload metadata
type NoBodyError ¶
type NoBodyError = operator_utils_types.NoBodyError
NoBodyError error meaning that client didn't provide body when it's required
type RouterMissingParamError ¶
type RouterMissingParamError = operator_utils_types.RouterMissingParamError
RouterMissingParamError missing parameter in request
type RouterParsingError ¶
type RouterParsingError = operator_utils_types.RouterParsingError
RouterParsingError parsing error, for example string when we expected integer
type SystemWideRuleSelector ¶ added in v1.1.6
type SystemWideRuleSelector struct { OrgID types.OrgID RuleID types.RuleID ErrorKey types.ErrorKey }
SystemWideRuleSelector contains all four fields that are used to select system-wide rule disable
type UnauthorizedError ¶ added in v1.1.1
type UnauthorizedError = operator_utils_types.UnauthorizedError
UnauthorizedError means server can't authorize you, for example the token is missing or malformed
type WorkloadsForCluster ¶ added in v1.4.0
type WorkloadsForCluster struct { Status string `json:"status"` Cluster Cluster `json:"cluster"` Namespace Namespace `json:"namespace"` Metadata Metadata `json:"metadata"` Recommendations []DVORecommendation `json:"recommendations"` }
WorkloadsForCluster structure represents workload for one selected cluster
type WorkloadsForNamespace ¶ added in v1.4.0
type WorkloadsForNamespace struct { Cluster Cluster `json:"cluster"` Namespace Namespace `json:"namespace"` Metadata Metadata `json:"metadata"` RecommendationsHitCount map[string]int `json:"recommendations_hit_count"` }
WorkloadsForNamespace structure represents a single entry of the namespace list with some aggregations