66 "sort"
77 "strconv"
88 "strings"
9- "sync"
109 "time"
1110
1211 "cloud.google.com/go/bigquery"
@@ -19,11 +18,9 @@ import (
1918 "github.com/openshift/sippy/pkg/apis/api/componentreport/crtest"
2019 "github.com/openshift/sippy/pkg/apis/api/componentreport/reqopts"
2120 apiCache "github.com/openshift/sippy/pkg/apis/cache"
22- configv1 "github.com/openshift/sippy/pkg/apis/config/v1"
2321 v1 "github.com/openshift/sippy/pkg/apis/sippy/v1"
2422 bqcachedclient "github.com/openshift/sippy/pkg/bigquery"
2523 "github.com/openshift/sippy/pkg/bigquery/bqlabel"
26- "github.com/openshift/sippy/pkg/util"
2724 "github.com/openshift/sippy/pkg/util/param"
2825 "github.com/openshift/sippy/pkg/util/sets"
2926)
@@ -33,12 +30,11 @@ var _ dataprovider.DataProvider = &BigQueryProvider{}
3330// BigQueryProvider implements dataprovider.DataProvider using Google BigQuery
3431// as the backing data store, wrapping the existing query generators.
3532type BigQueryProvider struct {
36- client * bqcachedclient.Client
37- variantJunitTableOverrides []configv1.VariantJunitTableOverride
33+ client * bqcachedclient.Client
3834}
3935
40- func NewBigQueryProvider (client * bqcachedclient.Client , overrides []configv1. VariantJunitTableOverride ) * BigQueryProvider {
41- return & BigQueryProvider {client : client , variantJunitTableOverrides : overrides }
36+ func NewBigQueryProvider (client * bqcachedclient.Client ) * BigQueryProvider {
37+ return & BigQueryProvider {client : client }
4238}
4339
4440// Client returns the underlying BigQuery client for callers that still need direct access
@@ -72,92 +68,7 @@ func (p *BigQueryProvider) QuerySampleTestStatus(ctx context.Context, reqOptions
7268 includeVariants map [string ][]string ,
7369 start , end time.Time ) (map [string ]crstatus.TestStatus , []error ) {
7470
75- fLog := log .WithField ("func" , "QuerySampleTestStatus" )
76-
77- // Filter out overridden variants from the default query
78- filteredVariants , skipDefault := copyIncludeVariantsAndRemoveOverrides (p .variantJunitTableOverrides , - 1 , includeVariants )
79-
80- type result struct {
81- status map [string ]crstatus.TestStatus
82- errs []error
83- }
84- resultCh := make (chan result )
85- var wg sync.WaitGroup
86-
87- // Run default query (unless all variants were overridden)
88- if ! skipDefault {
89- wg .Add (1 )
90- go func () {
91- defer wg .Done ()
92- select {
93- case <- ctx .Done ():
94- return
95- default :
96- fLog .Infof ("running default sample query with includeVariants: %+v" , filteredVariants )
97- s , e := p .querySampleTestStatusForTable (ctx , reqOptions , allJobVariants , filteredVariants , start , end , DefaultJunitTable )
98- resultCh <- result {s , e }
99- }
100- }()
101- }
102-
103- // Run override queries for applicable variants
104- for i , or := range p .variantJunitTableOverrides {
105- if ! containsOverriddenVariant (includeVariants , or .VariantName , or .VariantValue ) {
106- continue
107- }
108- index , override := i , or
109- wg .Add (1 )
110- go func () {
111- defer wg .Done ()
112- select {
113- case <- ctx .Done ():
114- return
115- default :
116- overrideVariants , skip := copyIncludeVariantsAndRemoveOverrides (p .variantJunitTableOverrides , index , includeVariants )
117- if skip {
118- fLog .Infof ("skipping override sample query as all values for a variant were overridden" )
119- return
120- }
121- overrideEnd := end
122- overrideStart , err := util .ParseCRReleaseTime ([]v1.Release {}, "" , override .RelativeStart ,
123- true , & overrideEnd , reqOptions .CacheOption .CRTimeRoundingFactor )
124- if err != nil {
125- resultCh <- result {nil , []error {err }}
126- return
127- }
128- fLog .Infof ("running override sample query for %+v with includeVariants: %+v" , override , overrideVariants )
129- s , e := p .querySampleTestStatusForTable (ctx , reqOptions , allJobVariants , overrideVariants , overrideStart , overrideEnd , override .TableName )
130- resultCh <- result {s , e }
131- }
132- }()
133- }
134-
135- go func () {
136- wg .Wait ()
137- close (resultCh )
138- }()
139-
140- merged := make (map [string ]crstatus.TestStatus )
141- var allErrs []error
142- for r := range resultCh {
143- allErrs = append (allErrs , r .errs ... )
144- for k , v := range r .status {
145- merged [k ] = v
146- }
147- }
148- if len (allErrs ) > 0 {
149- return nil , allErrs
150- }
151- return merged , nil
152- }
153-
154- func (p * BigQueryProvider ) querySampleTestStatusForTable (ctx context.Context , reqOptions reqopts.RequestOptions ,
155- allJobVariants crtest.JobVariants ,
156- includeVariants map [string ][]string ,
157- start , end time.Time ,
158- junitTable string ) (map [string ]crstatus.TestStatus , []error ) {
159-
160- generator := NewSampleQueryGenerator (p .client , reqOptions , allJobVariants , includeVariants , start , end , junitTable )
71+ generator := NewSampleQueryGenerator (p .client , reqOptions , allJobVariants , includeVariants , start , end )
16172 result , errs := apiPkg .GetDataFromCacheOrGenerate [crstatus.ReportTestStatus ](
16273 ctx , p .client .Cache , reqOptions .CacheOption ,
16374 apiPkg .NewCacheSpec (generator , "SampleTestStatus~" , & reqOptions .SampleRelease .End ),
@@ -194,89 +105,7 @@ func (p *BigQueryProvider) QuerySampleJobRunTestStatus(ctx context.Context, reqO
194105 includeVariants map [string ][]string ,
195106 start , end time.Time ) (map [string ][]crstatus.TestJobRunRows , []error ) {
196107
197- fLog := log .WithField ("func" , "QuerySampleJobRunTestStatus" )
198-
199- filteredVariants , skipDefault := copyIncludeVariantsAndRemoveOverrides (p .variantJunitTableOverrides , - 1 , includeVariants )
200-
201- type result struct {
202- status map [string ][]crstatus.TestJobRunRows
203- errs []error
204- }
205- resultCh := make (chan result )
206- var wg sync.WaitGroup
207-
208- if ! skipDefault {
209- wg .Add (1 )
210- go func () {
211- defer wg .Done ()
212- select {
213- case <- ctx .Done ():
214- return
215- default :
216- fLog .Infof ("running default sample job run query with includeVariants: %+v" , filteredVariants )
217- s , e := p .querySampleJobRunTestStatusForTable (ctx , reqOptions , allJobVariants , filteredVariants , start , end , DefaultJunitTable )
218- resultCh <- result {s , e }
219- }
220- }()
221- }
222-
223- for i , or := range p .variantJunitTableOverrides {
224- if ! containsOverriddenVariant (includeVariants , or .VariantName , or .VariantValue ) {
225- continue
226- }
227- index , override := i , or
228- wg .Add (1 )
229- go func () {
230- defer wg .Done ()
231- select {
232- case <- ctx .Done ():
233- return
234- default :
235- overrideVariants , skip := copyIncludeVariantsAndRemoveOverrides (p .variantJunitTableOverrides , index , includeVariants )
236- if skip {
237- fLog .Infof ("skipping override sample job run query as all values for a variant were overridden" )
238- return
239- }
240- overrideEnd := end
241- overrideStart , err := util .ParseCRReleaseTime ([]v1.Release {}, "" , override .RelativeStart ,
242- true , & overrideEnd , reqOptions .CacheOption .CRTimeRoundingFactor )
243- if err != nil {
244- resultCh <- result {nil , []error {err }}
245- return
246- }
247- fLog .Infof ("running override sample job run query for %+v with includeVariants: %+v" , override , overrideVariants )
248- s , e := p .querySampleJobRunTestStatusForTable (ctx , reqOptions , allJobVariants , overrideVariants , overrideStart , overrideEnd , override .TableName )
249- resultCh <- result {s , e }
250- }
251- }()
252- }
253-
254- go func () {
255- wg .Wait ()
256- close (resultCh )
257- }()
258-
259- merged := make (map [string ][]crstatus.TestJobRunRows )
260- var allErrs []error
261- for r := range resultCh {
262- allErrs = append (allErrs , r .errs ... )
263- for k , v := range r .status {
264- merged [k ] = v
265- }
266- }
267- if len (allErrs ) > 0 {
268- return nil , allErrs
269- }
270- return merged , nil
271- }
272-
273- func (p * BigQueryProvider ) querySampleJobRunTestStatusForTable (ctx context.Context , reqOptions reqopts.RequestOptions ,
274- allJobVariants crtest.JobVariants ,
275- includeVariants map [string ][]string ,
276- start , end time.Time ,
277- junitTable string ) (map [string ][]crstatus.TestJobRunRows , []error ) {
278-
279- generator := NewSampleTestDetailsQueryGenerator (p .client , reqOptions , allJobVariants , includeVariants , start , end , junitTable )
108+ generator := NewSampleTestDetailsQueryGenerator (p .client , reqOptions , allJobVariants , includeVariants , start , end )
280109 result , errs := apiPkg .GetDataFromCacheOrGenerate [crstatus.TestJobRunStatuses ](
281110 ctx , p .client .Cache , reqOptions .CacheOption ,
282111 apiPkg .NewCacheSpec (generator , "SampleJobRunTestStatusV2~" , & end ),
@@ -568,58 +397,3 @@ func getSingleColumnResultToSlice(ctx context.Context, q *bigquery.Query) ([]str
568397 }
569398 return names , nil
570399}
571-
572- // containsOverriddenVariant checks whether the given variant key/value pair
573- // is present in the includeVariants map (i.e. the request actually includes
574- // data for this overridden variant).
575- func containsOverriddenVariant (includeVariants map [string ][]string , key , value string ) bool {
576- for k , v := range includeVariants {
577- if k != key {
578- continue
579- }
580- for _ , vv := range v {
581- if vv == value {
582- return true
583- }
584- }
585- }
586- return false
587- }
588-
589- // copyIncludeVariantsAndRemoveOverrides copies includeVariants and removes
590- // overridden variant values. For the default query (currOverride=-1), all
591- // overridden values are removed. For an override query at index i, only
592- // other overrides' values are removed. Returns true if the query should be
593- // skipped because all values for a variant were removed.
594- func copyIncludeVariantsAndRemoveOverrides (
595- overrides []configv1.VariantJunitTableOverride ,
596- currOverride int ,
597- includeVariants map [string ][]string ) (map [string ][]string , bool ) {
598-
599- cp := make (map [string ][]string )
600- for key , values := range includeVariants {
601- var newSlice []string
602- for _ , v := range values {
603- if ! shouldSkipVariant (overrides , currOverride , key , v ) {
604- newSlice = append (newSlice , v )
605- }
606- }
607- if len (newSlice ) == 0 {
608- return cp , true
609- }
610- cp [key ] = newSlice
611- }
612- return cp , false
613- }
614-
615- func shouldSkipVariant (overrides []configv1.VariantJunitTableOverride , currOverride int , key , value string ) bool {
616- for i , override := range overrides {
617- if i == currOverride {
618- return false
619- }
620- if override .VariantName == key && override .VariantValue == value {
621- return true
622- }
623- }
624- return false
625- }
0 commit comments