Chore: Add context to datasource service (#42294)
* Add context to datasource service * Adjust wire for ShouldBeReported method * Replace inTransactionCtx
This commit is contained in:
@@ -29,7 +29,7 @@ func (usm *UsageStatsMock) GetUsageReport(ctx context.Context) (Report, error) {
|
||||
return Report{Metrics: all}, nil
|
||||
}
|
||||
|
||||
func (usm *UsageStatsMock) ShouldBeReported(_ string) bool {
|
||||
func (usm *UsageStatsMock) ShouldBeReported(_ context.Context, _ string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -23,5 +23,5 @@ type Service interface {
|
||||
GetUsageReport(context.Context) (Report, error)
|
||||
RegisterMetricsFunc(MetricsFunc)
|
||||
RegisterSendReportCallback(SendReportCallbackFunc)
|
||||
ShouldBeReported(string) bool
|
||||
ShouldBeReported(context.Context, string) bool
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
|
||||
// as sending that name could be sensitive information
|
||||
dsOtherCount := 0
|
||||
for _, dsStat := range dsStats.Result {
|
||||
if uss.ShouldBeReported(dsStat.Type) {
|
||||
if uss.ShouldBeReported(ctx, dsStat.Type) {
|
||||
metrics["stats.ds."+dsStat.Type+".count"] = dsStat.Count
|
||||
} else {
|
||||
dsOtherCount += dsStat.Count
|
||||
@@ -131,7 +131,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
|
||||
metrics["stats.ds.other.count"] = dsOtherCount
|
||||
|
||||
esDataSourcesQuery := models.GetDataSourcesByTypeQuery{Type: models.DS_ES}
|
||||
if err := uss.Bus.Dispatch(&esDataSourcesQuery); err != nil {
|
||||
if err := uss.Bus.DispatchCtx(ctx, &esDataSourcesQuery); err != nil {
|
||||
uss.log.Error("Failed to get elasticsearch json data", "error", err)
|
||||
return report, err
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
|
||||
|
||||
access := strings.ToLower(dsAccessStat.Access)
|
||||
|
||||
if uss.ShouldBeReported(dsAccessStat.Type) {
|
||||
if uss.ShouldBeReported(ctx, dsAccessStat.Type) {
|
||||
metrics["stats.ds_access."+dsAccessStat.Type+"."+access+".count"] = dsAccessStat.Count
|
||||
} else {
|
||||
old := dsAccessOtherCount[access]
|
||||
@@ -329,8 +329,8 @@ func (uss *UsageStats) updateTotalStats(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (uss *UsageStats) ShouldBeReported(dsType string) bool {
|
||||
ds, exists := uss.pluginStore.Plugin(context.TODO(), dsType)
|
||||
func (uss *UsageStats) ShouldBeReported(ctx context.Context, dsType string) bool {
|
||||
ds, exists := uss.pluginStore.Plugin(ctx, dsType)
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user