-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor everywhere uses ESClient to have a Switch #6168
Changes from 4 commits
3ac364c
2de0878
b4028b0
f38277e
59486e9
210cf5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,51 +146,64 @@ | |
return err | ||
} | ||
for _, domainName := range workflowMetricDomainNames { | ||
wfTypeCountEsQuery, err := w.getDomainWorkflowTypeCountQuery(domainName) | ||
if err != nil { | ||
logger.Error("Failed to get ElasticSearch query to find domain workflow type Info", | ||
zap.Error(err), | ||
zap.String("DomainName", domainName), | ||
) | ||
return err | ||
switch w.analyzer.readMode { | ||
case ES: | ||
err = w.emitWorkflowTypeCountMetricsES(ctx, domainName, logger) | ||
default: | ||
err = w.emitWorkflowTypeCountMetricsES(ctx, domainName, logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both cases doing to same thing. did you mean to emit a metric for pinot here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I'll add pinot in the next PR |
||
} | ||
response, err := w.analyzer.esClient.SearchRaw(ctx, w.analyzer.visibilityIndexName, wfTypeCountEsQuery) | ||
if err != nil { | ||
logger.Error("Failed to query ElasticSearch to find workflow type count Info", | ||
zap.Error(err), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
zap.String("DomainName", domainName), | ||
) | ||
return err | ||
} | ||
agg, foundAggregation := response.Aggregations[workflowTypesAggKey] | ||
|
||
if !foundAggregation { | ||
logger.Error("ElasticSearch error: aggregation failed.", | ||
zap.Error(err), | ||
zap.String("Aggregation", string(agg)), | ||
zap.String("DomainName", domainName), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
) | ||
return err | ||
} | ||
var domainWorkflowTypeCount DomainWorkflowTypeCount | ||
err = json.Unmarshal(agg, &domainWorkflowTypeCount) | ||
if err != nil { | ||
logger.Error("ElasticSearch error parsing aggregation.", | ||
zap.Error(err), | ||
zap.String("Aggregation", string(agg)), | ||
zap.String("DomainName", domainName), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
) | ||
return err | ||
} | ||
for _, workflowType := range domainWorkflowTypeCount.WorkflowTypes { | ||
w.analyzer.tallyScope.Tagged( | ||
map[string]string{domainTag: domainName, workflowTypeTag: workflowType.AggregateKey}, | ||
).Gauge(workflowTypeCountMetrics).Update(float64(workflowType.AggregateCount)) | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (w *Workflow) emitWorkflowTypeCountMetricsES(ctx context.Context, domainName string, logger *zap.Logger) error { | ||
wfTypeCountEsQuery, err := w.getDomainWorkflowTypeCountQuery(domainName) | ||
if err != nil { | ||
logger.Error("Failed to get ElasticSearch query to find domain workflow type Info", | ||
zap.Error(err), | ||
zap.String("DomainName", domainName), | ||
) | ||
return err | ||
} | ||
response, err := w.analyzer.esClient.SearchRaw(ctx, w.analyzer.visibilityIndexName, wfTypeCountEsQuery) | ||
if err != nil { | ||
logger.Error("Failed to query ElasticSearch to find workflow type count Info", | ||
zap.Error(err), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
zap.String("DomainName", domainName), | ||
) | ||
return err | ||
} | ||
agg, foundAggregation := response.Aggregations[workflowTypesAggKey] | ||
|
||
if !foundAggregation { | ||
logger.Error("ElasticSearch error: aggregation failed.", | ||
zap.Error(err), | ||
zap.String("Aggregation", string(agg)), | ||
zap.String("DomainName", domainName), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
) | ||
return err | ||
} | ||
var domainWorkflowTypeCount DomainWorkflowTypeCount | ||
err = json.Unmarshal(agg, &domainWorkflowTypeCount) | ||
if err != nil { | ||
logger.Error("ElasticSearch error parsing aggregation.", | ||
zap.Error(err), | ||
zap.String("Aggregation", string(agg)), | ||
zap.String("DomainName", domainName), | ||
zap.String("VisibilityQuery", wfTypeCountEsQuery), | ||
) | ||
return err | ||
} | ||
for _, workflowType := range domainWorkflowTypeCount.WorkflowTypes { | ||
w.analyzer.tallyScope.Tagged( | ||
map[string]string{domainTag: domainName, workflowTypeTag: workflowType.AggregateKey}, | ||
).Gauge(workflowTypeCountMetrics).Update(float64(workflowType.AggregateCount)) | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,6 +283,7 @@ func (s *Service) startESAnalyzer() { | |
s.GetFrontendClient(), | ||
s.GetClientBean(), | ||
s.params.ESClient, | ||
s.params.PinotClient, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it's fine for this PR but as a general pattern we should avoid passing multiple client objects to a component and having it decide based on which one is nil. Ideally there would be one parameter here of |
||
s.params.ESConfig, | ||
s.GetLogger(), | ||
s.params.MetricScope, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this prefers ES if both are present:
could this mode be replaced by "just use the non-nil client" and only pass one?
or is there more stuff coming that'll use both sometimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be. It's just that Pinot and ES has different GenericClients, there'll need a lot efforts to do a refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaah, because esClient is used by other things too, and there is / will be shadowing, so these fields are not just for this mode.
alrighty, makes sense 👍