Skip to content

Commit

Permalink
download Insights analysis report from a new endpoint (using Insights…
Browse files Browse the repository at this point in the history
… request ID) (#812)

* use the new endpoint to get the Insights analysis report in TechPreview

* unit test & additional fixes

* work with dataGather conditions in better way
  • Loading branch information
tremes authored Aug 9, 2023
1 parent 3700733 commit 4efc924
Show file tree
Hide file tree
Showing 18 changed files with 793 additions and 239 deletions.
1 change: 1 addition & 0 deletions config/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pull_report:
timeout: "3000s"
min_retry: "30s"
processingStatusEndpoint: https://console.redhat.com/api/insights-results-aggregator/v2/cluster/%s/request/%s/status
reportEndpointTechPreview: https://console.redhat.com/api/insights-results-aggregator/v2/cluster/%s/request/%s/report
ocm:
scaEndpoint: https://api.openshift.com/api/accounts_mgmt/v1/certificates
scaInterval: "8h"
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func NewGatherAndUpload() *cobra.Command {
ReportMinRetryTime: 10 * time.Second,
ReportPullingTimeout: 30 * time.Minute,
ProcessingStatusEndpoint: "https://console.redhat.com/api/insights-results-aggregator/v2/cluster/%s/request/%s/status",
ReportEndpointTechPreview: "https://console.redhat.com/api/insights-results-aggregator/v2/cluster/%s/request/%s/report",
},
}
cfg := controllercmd.NewControllerCommandConfig("openshift-insights-operator", version.Get(), nil)
Expand Down
14 changes: 12 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type Serialized struct {
ClusterTransferEndpoint string `json:"clusterTransferEndpoint"`
ClusterTransferInterval string `json:"clusterTransferInterval"`
} `json:"ocm"`
DisableInsightsAlerts bool `json:"disableInsightsAlerts"`
ProcessingStatusEndpoint string `json:"processingStatusEndpoint"`
DisableInsightsAlerts bool `json:"disableInsightsAlerts"`
ProcessingStatusEndpoint string `json:"processingStatusEndpoint"`
ReportEndpointTechPreview string `json:"reportEndpointTechPreview"`
}

// Controller defines the standard config for this operator.
Expand All @@ -43,6 +44,7 @@ type Controller struct {
Endpoint string
ConditionalGathererEndpoint string
ReportEndpoint string
ReportEndpointTechPreview string
ReportPullingDelay time.Duration
ReportMinRetryTime time.Duration
ReportPullingTimeout time.Duration
Expand Down Expand Up @@ -116,6 +118,7 @@ func (c *Controller) MergeWith(cfg *Controller) {
c.mergeOCM(cfg)
c.mergeHTTP(cfg)
c.mergeProcessingStatusEndpoint(cfg)
c.mergeReportEndpointTechPreview(cfg)
}

func (c *Controller) mergeCredentials(cfg *Controller) {
Expand All @@ -135,6 +138,12 @@ func (c *Controller) mergeProcessingStatusEndpoint(cfg *Controller) {
}
}

func (c *Controller) mergeReportEndpointTechPreview(cfg *Controller) {
if len(cfg.ReportEndpointTechPreview) > 0 {
c.ReportEndpointTechPreview = cfg.ReportEndpointTechPreview
}
}

func (c *Controller) mergeConditionalGathererEndpoint(cfg *Controller) {
if len(cfg.ConditionalGathererEndpoint) > 0 {
c.ConditionalGathererEndpoint = cfg.ConditionalGathererEndpoint
Expand Down Expand Up @@ -199,6 +208,7 @@ func ToController(s *Serialized, cfg *Controller) (*Controller, error) { // noli
cfg.EnableGlobalObfuscation = s.EnableGlobalObfuscation
cfg.DisableInsightsAlerts = s.DisableInsightsAlerts
cfg.ProcessingStatusEndpoint = s.ProcessingStatusEndpoint
cfg.ReportEndpointTechPreview = s.ReportEndpointTechPreview

if len(s.Interval) > 0 {
d, err := time.ParseDuration(s.Interval)
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/configobserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func LoadConfigFromSecret(secret *v1.Secret) (config.Controller, error) {
cfg.loadReport(secret.Data)
cfg.loadOCM(secret.Data)
cfg.loadProcessingStatusEndpoint(secret.Data)
cfg.loadReportEndpointTechPreview(secret.Data)

if intervalString, ok := secret.Data["interval"]; ok {
var duration time.Duration
Expand Down Expand Up @@ -171,3 +172,9 @@ func (c *Config) loadProcessingStatusEndpoint(data map[string][]byte) {
c.ProcessingStatusEndpoint = string(endpoint)
}
}

func (c *Config) loadReportEndpointTechPreview(data map[string][]byte) {
if endpoint, ok := data["reportEndpointTechPreview"]; ok {
c.ReportEndpointTechPreview = string(endpoint)
}
}
7 changes: 0 additions & 7 deletions pkg/config/mock_configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,3 @@ func (mc *MockAPIConfigurator) GatherDisabled() bool {
}
return false
}

func (mc *MockAPIConfigurator) GatherDataPolicy() *v1alpha1.DataPolicy {
if mc.config != nil {
return &mc.config.DataPolicy
}
return nil
}
Loading

0 comments on commit 4efc924

Please sign in to comment.