prow/spyglass/gcsartifact_fetcher.go
func (af *GCSArtifactFetcher) artifacts(key string) ([]string, error) {
	src, err := newGCSJobSource(key)
	if err != nil {
		return nil, fmt.Errorf("Failed to get GCS job source from %s: %v", key, err)
	}

	listStart := time.Now()
	bucketName, prefix := extractBucketPrefixPair(src.jobPath())
	artifacts := []string{}
	bkt := af.client.Bucket(bucketName)
	q := storage.Query{
		Prefix:   prefix,
		Versions: false,
	}
	objIter := bkt.Objects(context.Background(), &q)
	wait := []time.Duration{16, 32, 64, 128, 256, 256, 512, 512}
	for i := 0; ; {
		oAttrs, err := objIter.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			logrus.WithFields(fieldsForJob(src)).WithError(err).Error("Error accessing GCS artifact.")
			if i >= len(wait) {
				return artifacts, fmt.Errorf("timed out: error accessing GCS artifact: %v", err)
			}
			time.Sleep((wait[i] + time.Duration(rand.Intn(10))) * time.Millisecond)
			i++
			continue
		}
		artifacts = append(artifacts, strings.TrimPrefix(oAttrs.Name, prefix))
		i = 0
	}
	listElapsed := time.Since(listStart)
	logrus.WithField("duration", listElapsed).Infof("Listed %d artifacts.", len(artifacts))
	return artifacts, nil
}
func (af *GCSArtifactFetcher) artifacts(key string) ([]string, error) {
	src, err := newGCSJobSource(key)
	if err != nil {
		return nil, fmt.Errorf("Failed to get GCS job source from %s: %v", key, err)
	}

	listStart := time.Now()
	bucketName, prefix := extractBucketPrefixPair(src.jobPath())
	artifacts := []string{}
	bkt := af.client.Bucket(bucketName)
	q := storage.Query{
		Prefix:   prefix,
		Versions: false,
	}
	objIter := bkt.Objects(context.Background(), &q)
	wait := []time.Duration{16, 32, 64, 128, 256, 256, 512, 512}
	for i := 0; ; {
		oAttrs, err := objIter.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			logrus.WithFields(fieldsForJob(src)).WithError(err).Error("Error accessing GCS artifact.")
			if i >= len(wait) {
				return artifacts, fmt.Errorf("timed out: error accessing GCS artifact: %v", err)
			}
			time.Sleep((wait[i] + time.Duration(rand.Intn(10))) * time.Millisecond)
			i++
			continue
		}
		artifacts = append(artifacts, strings.TrimPrefix(oAttrs.Name, prefix))
		i = 0
	}
	listElapsed := time.Since(listStart)
	logrus.WithField("duration", listElapsed).Infof("Listed %d artifacts.", len(artifacts))
	return artifacts, nil
}
func ( af * GCSArtifactFetcher ) artifacts ( key string ) ( [ ] string , error ) { src , err := newGCSJobSource ( key ) if err != nil { return nil , fmt . Errorf ( " " , key , err ) } listStart := time . Now ( ) bucketName , prefix := extractBucketPrefixPair ( src . jobPath ( ) ) artifacts := [ ] string { } bkt := af . client . Bucket ( bucketName ) q := storage . Query { Prefix : prefix , Versions : false , } objIter := bkt . Objects ( context . Background ( ) , & q ) wait := [ ] time . Duration { 16 , 32 , 64 , 128 , 256 , 256 , 512 , 512 } for i := 0 ; ; { oAttrs , err := objIter . Next ( ) if err == iterator . Done { break } if err != nil { logrus . WithFields ( fieldsForJob ( src ) ) . WithError ( err ) . Error ( " " ) if i >= len ( wait ) { return artifacts , fmt . Errorf ( " " , err ) } time . Sleep ( ( wait [ i ] + time . Duration ( rand . Intn ( 10 ) ) ) * time . Millisecond ) i ++ continue } artifacts = append ( artifacts , strings . TrimPrefix ( oAttrs . Name , prefix ) ) i = 0 } listElapsed := time . Since ( listStart ) logrus . WithField ( " " , listElapsed ) . Infof ( " " , len ( artifacts ) ) return artifacts , nil }
// Artifacts lists all artifacts available for the given job source
Artifacts lists all artifacts available for the given job source