| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "strconv" | 9 "strconv" |
| 10 "strings" | 10 "strings" |
| 11 "unicode/utf8" | 11 "unicode/utf8" |
| 12 | 12 |
| 13 "github.com/luci/luci-go/common/data/stringset" | 13 "github.com/luci/luci-go/common/data/stringset" |
| 14 "github.com/luci/luci-go/common/logging" | 14 "github.com/luci/luci-go/common/logging" |
| 15 miloProto "github.com/luci/luci-go/common/proto/milo" | 15 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 16 "github.com/luci/luci-go/grpc/grpcutil" | 16 "github.com/luci/luci-go/grpc/grpcutil" |
| 17 "github.com/luci/luci-go/logdog/client/coordinator" | 17 "github.com/luci/luci-go/logdog/client/coordinator" |
| 18 "github.com/luci/luci-go/logdog/common/types" | 18 "github.com/luci/luci-go/logdog/common/types" |
| 19 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 19 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 20 milo "github.com/luci/luci-go/milo/api/proto" | 20 milo "github.com/luci/luci-go/milo/api/proto" |
| 21 » "github.com/luci/luci-go/milo/build_source/raw_presentation" | 21 » "github.com/luci/luci-go/milo/buildsource/rawpresentation" |
| 22 | 22 |
| 23 "google.golang.org/grpc/codes" | 23 "google.golang.org/grpc/codes" |
| 24 | 24 |
| 25 "golang.org/x/net/context" | 25 "golang.org/x/net/context" |
| 26 ) | 26 ) |
| 27 | 27 |
| 28 // BuildInfoProvider is a configuration that provides build information. | 28 // BuildInfoProvider is a configuration that provides build information. |
| 29 // | 29 // |
| 30 // In a production system, this will be completely defaults. For testing, the | 30 // In a production system, this will be completely defaults. For testing, the |
| 31 // various services and data sources may be substituted for testing stubs. | 31 // various services and data sources may be substituted for testing stubs. |
| 32 type BuildInfoProvider struct { | 32 type BuildInfoProvider struct { |
| 33 // LogdogClientFunc returns a coordinator Client instance for the suppli
ed | 33 // LogdogClientFunc returns a coordinator Client instance for the suppli
ed |
| 34 // parameters. | 34 // parameters. |
| 35 // | 35 // |
| 36 // If nil, a production client will be generated. | 36 // If nil, a production client will be generated. |
| 37 LogdogClientFunc func(c context.Context) (*coordinator.Client, error) | 37 LogdogClientFunc func(c context.Context) (*coordinator.Client, error) |
| 38 } | 38 } |
| 39 | 39 |
| 40 func (p *BuildInfoProvider) newLogdogClient(c context.Context) (*coordinator.Cli
ent, error) { | 40 func (p *BuildInfoProvider) newLogdogClient(c context.Context) (*coordinator.Cli
ent, error) { |
| 41 if p.LogdogClientFunc != nil { | 41 if p.LogdogClientFunc != nil { |
| 42 return p.LogdogClientFunc(c) | 42 return p.LogdogClientFunc(c) |
| 43 } | 43 } |
| 44 » return raw_presentation.NewClient(c, "") | 44 » return rawpresentation.NewClient(c, "") |
| 45 } | 45 } |
| 46 | 46 |
| 47 // GetBuildInfo resolves a Milo protobuf Step for a given BuildBot build. | 47 // GetBuildInfo resolves a Milo protobuf Step for a given BuildBot build. |
| 48 // | 48 // |
| 49 // On failure, it returns a (potentially-wrapped) gRPC error. | 49 // On failure, it returns a (potentially-wrapped) gRPC error. |
| 50 // | 50 // |
| 51 // This: | 51 // This: |
| 52 // | 52 // |
| 53 // 1) Fetches the BuildBot build JSON from datastore. | 53 // 1) Fetches the BuildBot build JSON from datastore. |
| 54 // 2) Resolves the LogDog annotation stream path from the BuildBot state. | 54 // 2) Resolves the LogDog annotation stream path from the BuildBot state. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 // Identify the LogDog annotation stream from the build. | 85 // Identify the LogDog annotation stream from the build. |
| 86 // | 86 // |
| 87 // This will return a gRPC error on failure. | 87 // This will return a gRPC error on failure. |
| 88 addr, err := getLogDogAnnotationAddr(c, client, build, projectHint) | 88 addr, err := getLogDogAnnotationAddr(c, client, build, projectHint) |
| 89 if err != nil { | 89 if err != nil { |
| 90 return nil, err | 90 return nil, err |
| 91 } | 91 } |
| 92 logging.Infof(c, "Resolved annotation stream: %s / %s", addr.Project, ad
dr.Path) | 92 logging.Infof(c, "Resolved annotation stream: %s / %s", addr.Project, ad
dr.Path) |
| 93 | 93 |
| 94 // Load the annotation protobuf. | 94 // Load the annotation protobuf. |
| 95 » as := raw_presentation.AnnotationStream{ | 95 » as := rawpresentation.AnnotationStream{ |
| 96 Client: client, | 96 Client: client, |
| 97 Path: addr.Path, | 97 Path: addr.Path, |
| 98 Project: addr.Project, | 98 Project: addr.Project, |
| 99 } | 99 } |
| 100 if err := as.Normalize(); err != nil { | 100 if err := as.Normalize(); err != nil { |
| 101 logging.WithError(err).Errorf(c, "Failed to normalize annotation
stream.") | 101 logging.WithError(err).Errorf(c, "Failed to normalize annotation
stream.") |
| 102 return nil, grpcutil.Internal | 102 return nil, grpcutil.Internal |
| 103 } | 103 } |
| 104 | 104 |
| 105 step, err := as.Fetch(c) | 105 step, err := as.Fetch(c) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 allProps.Add(prop.Name) | 264 allProps.Add(prop.Name) |
| 265 | 265 |
| 266 step.Property = append(step.Property, &miloProto.Step_Property{ | 266 step.Property = append(step.Property, &miloProto.Step_Property{ |
| 267 Name: prop.Name, | 267 Name: prop.Name, |
| 268 Value: fmt.Sprintf("%v", prop.Value), | 268 Value: fmt.Sprintf("%v", prop.Value), |
| 269 }) | 269 }) |
| 270 } | 270 } |
| 271 | 271 |
| 272 return nil | 272 return nil |
| 273 } | 273 } |
| OLD | NEW |