Skip to content

Commit d6fd74d

Browse files
authored
fix: fix a bug when elastic as a provider (#3904)
Signed-off-by: SandeepD2697 <[email protected]>
1 parent deeb73e commit d6fd74d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

metrics-operator/controllers/common/providers/elastic/elastic.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (r *KeptnElasticProvider) FetchAnalysisValue(ctx context.Context, query str
8484
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
8585
defer cancel()
8686

87-
result, err := r.runElasticQuery(ctx, query)
87+
result, err := r.runElasticQuery(ctx, *provider, query)
8888
if err != nil {
8989
return "", err
9090
}
@@ -98,7 +98,7 @@ func (r *KeptnElasticProvider) EvaluateQuery(ctx context.Context, metric metrics
9898
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
9999
defer cancel()
100100

101-
result, err := r.runElasticQuery(ctx, metric.Spec.Query)
101+
result, err := r.runElasticQuery(ctx, provider, metric.Spec.Query)
102102
if err != nil {
103103
return "", nil, err
104104
}
@@ -117,7 +117,13 @@ func (r *KeptnElasticProvider) EvaluateQueryForStep(ctx context.Context, metric
117117
}
118118

119119
// runElasticQuery runs query on elastic search to get output from elasticsearch
120-
func (r *KeptnElasticProvider) runElasticQuery(ctx context.Context, query string) (map[string]interface{}, error) {
120+
func (r *KeptnElasticProvider) runElasticQuery(ctx context.Context, provider metricsapi.KeptnMetricsProvider, query string) (map[string]interface{}, error) {
121+
var err error
122+
r.Log.Info("Running Elasticsearch query", "query", query)
123+
r.Elastic, err = GetElasticClient(provider)
124+
if err != nil {
125+
return nil, err
126+
}
121127

122128
res, err := r.Elastic.Search(
123129
r.Elastic.Search.WithContext(ctx),

metrics-operator/controllers/common/providers/elastic/elastic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestRunElasticQuery(t *testing.T) {
152152
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
153153
defer cancel()
154154

155-
result, err := provider.runElasticQuery(ctx, tt.query)
155+
result, err := provider.runElasticQuery(ctx, metricsapi.KeptnMetricsProvider{}, tt.query)
156156

157157
if tt.expectedError {
158158
assert.Error(t, err)

0 commit comments

Comments
 (0)