OLD | NEW |
| (Empty) |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | |
2 // Use of this source code is governed under the Apache License, Version 2.0 | |
3 // that can be found in the LICENSE file. | |
4 | |
5 package swarming | |
6 | |
7 import ( | |
8 "fmt" | |
9 "path" | |
10 "sort" | |
11 | |
12 "golang.org/x/net/context" | |
13 | |
14 mc "github.com/luci/gae/service/memcache" | |
15 "github.com/luci/luci-go/common/logging" | |
16 ) | |
17 | |
18 // swarmingBuildLogImpl is the implementation for getting a log name from | |
19 // a swarming build via annotee. It returns the full text of the specific log, | |
20 // and whether or not it has been closed. | |
21 func swarmingBuildLogImpl(c context.Context, svc swarmingService, taskID, lognam
e string) (string, bool, error) { | |
22 server := svc.getHost() | |
23 cached, err := mc.GetKey(c, path.Join("swarmingLog", server, taskID, log
name)) | |
24 switch { | |
25 case err == mc.ErrCacheMiss: | |
26 | |
27 case err != nil: | |
28 logging.WithError(err).Errorf(c, "failed to fetch log with key %
s from memcache", cached.Key()) | |
29 | |
30 default: | |
31 logging.Debugf(c, "Cache hit for step log %s/%s/%s", server, tas
kID, logname) | |
32 return string(cached.Value()), false, nil | |
33 } | |
34 | |
35 fetchParams := swarmingFetchParams{ | |
36 fetchRes: true, // Needed so we can validate that this is a Milo
build. | |
37 fetchLog: true, | |
38 } | |
39 fr, err := swarmingFetch(c, svc, taskID, fetchParams) | |
40 if err != nil { | |
41 return "", false, err | |
42 } | |
43 | |
44 // Decode the data using annotee. | |
45 s, err := streamsFromAnnotatedLog(c, fr.log) | |
46 if err != nil { | |
47 return "", false, err | |
48 } | |
49 | |
50 k := fmt.Sprintf("steps%s", logname) | |
51 stream, ok := s.Streams[k] | |
52 if !ok { | |
53 var keys []string | |
54 for sk := range s.Streams { | |
55 keys = append(keys, sk) | |
56 } | |
57 sort.Strings(keys) | |
58 return "", false, fmt.Errorf("stream %q not found; available str
eams: %q", k, keys) | |
59 } | |
60 | |
61 if stream.Closed { | |
62 cached.SetValue([]byte(stream.Text)) | |
63 if err := mc.Set(c, cached); err != nil { | |
64 logging.Errorf(c, "Failed to write log with key %s to me
mcache: %s", cached.Key(), err) | |
65 } | |
66 } | |
67 | |
68 return stream.Text, stream.Closed, nil | |
69 } | |
OLD | NEW |