github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/opensearch_dashboards/opensearch_dashboards.go (about) 1 // Copyright (C) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package dashboards 5 6 import ( 7 "fmt" 8 vmcontrollerv1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1" 9 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/resources" 10 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/util/logs/vzlog" 11 "net/http" 12 ) 13 14 type ( 15 OSDashboardsClient struct { 16 httpClient *http.Client 17 DoHTTP func(request *http.Request) (*http.Response, error) 18 } 19 ) 20 21 func NewOSDashboardsClient() *OSDashboardsClient { 22 od := &OSDashboardsClient{ 23 httpClient: http.DefaultClient, 24 } 25 od.DoHTTP = func(request *http.Request) (*http.Response, error) { 26 return od.httpClient.Do(request) 27 } 28 return od 29 } 30 31 // UpdatePatterns updates the index patterns configured for old indices if any to match the corresponding data streams. 32 func (od *OSDashboardsClient) UpdatePatterns(log vzlog.VerrazzanoLogger, vmi *vmcontrollerv1.VerrazzanoMonitoringInstance) error { 33 if !vmi.Spec.Kibana.Enabled { 34 log.Debugf("OpenSearch Dashboards is not configured to run. Skipping the post upgrade step for OpenSearch Dashboards") 35 return nil 36 } 37 openSearchDashboardsEndpoint := resources.GetOpenSearchDashboardsHTTPEndpoint(vmi) 38 // Update index patterns in OpenSearch dashboards 39 err := od.updatePatternsInternal(log, openSearchDashboardsEndpoint) 40 if err != nil { 41 return fmt.Errorf("failed to update index patterns: %v", err) 42 } 43 return nil 44 }