Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: appengine/logdog/coordinator/endpoints/services/loadStream.go

Issue 1910923002: LogDog: Add project namespace to service endpoint. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-coordinator-backend
Patch Set: Comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package services 5 package services
6 6
7 import ( 7 import (
8 ds "github.com/luci/gae/service/datastore" 8 ds "github.com/luci/gae/service/datastore"
9 "github.com/luci/luci-go/appengine/logdog/coordinator" 9 "github.com/luci/luci-go/appengine/logdog/coordinator"
10 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" 10 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
11 "github.com/luci/luci-go/common/clock" 11 "github.com/luci/luci-go/common/clock"
12 "github.com/luci/luci-go/common/grpcutil" 12 "github.com/luci/luci-go/common/grpcutil"
13 "github.com/luci/luci-go/common/logdog/types" 13 "github.com/luci/luci-go/common/logdog/types"
14 log "github.com/luci/luci-go/common/logging" 14 log "github.com/luci/luci-go/common/logging"
15 "github.com/luci/luci-go/common/proto/google" 15 "github.com/luci/luci-go/common/proto/google"
16 "golang.org/x/net/context" 16 "golang.org/x/net/context"
17 "google.golang.org/grpc/codes" 17 "google.golang.org/grpc/codes"
18 ) 18 )
19 19
20 // LoadStream loads the log stream state. 20 // LoadStream loads the log stream state.
21 func (s *server) LoadStream(c context.Context, req *logdog.LoadStreamRequest) (* logdog.LoadStreamResponse, error) { 21 func (s *server) LoadStream(c context.Context, req *logdog.LoadStreamRequest) (* logdog.LoadStreamResponse, error) {
22 log.Fields{
23 "project": req.Project,
24 "path": req.Path,
25 }.Infof(c, "Loading log stream state.")
26
22 path := types.StreamPath(req.Path) 27 path := types.StreamPath(req.Path)
23 if err := path.Validate(); err != nil { 28 if err := path.Validate(); err != nil {
24 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid path ( %s): %s", path, err) 29 return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid path ( %s): %s", path, err)
25 } 30 }
26 log.Fields{
27 "path": path,
28 }.Infof(c, "Loading log stream state.")
29 31
30 ls := coordinator.LogStreamFromPath(path) 32 ls := coordinator.LogStreamFromPath(path)
31 switch err := ds.Get(c).Get(ls); err { 33 switch err := ds.Get(c).Get(ls); err {
32 case nil: 34 case nil:
33 // The log stream loaded successfully. 35 // The log stream loaded successfully.
34 resp := logdog.LoadStreamResponse{ 36 resp := logdog.LoadStreamResponse{
35 » » » State: loadLogStreamState(ls), 37 » » » State: loadLogStreamState(coordinator.Project(c), ls),
36 } 38 }
37 if req.Desc { 39 if req.Desc {
38 resp.Desc = ls.Descriptor 40 resp.Desc = ls.Descriptor
39 } 41 }
40 resp.ArchivalKey = ls.ArchivalKey 42 resp.ArchivalKey = ls.ArchivalKey
41 resp.Age = google.NewDuration(ds.RoundTime(clock.Now(c)).Sub(ls. Created)) 43 resp.Age = google.NewDuration(ds.RoundTime(clock.Now(c)).Sub(ls. Created))
42 44
43 log.Fields{ 45 log.Fields{
44 "path": path, 46 "path": path,
45 "hash": ls.HashID, 47 "hash": ls.HashID,
46 "terminalIndex": resp.State.TerminalIndex, 48 "terminalIndex": resp.State.TerminalIndex,
47 "archived": resp.State.Archived, 49 "archived": resp.State.Archived,
48 "purged": resp.State.Purged, 50 "purged": resp.State.Purged,
49 "age": resp.Age.Duration(), 51 "age": resp.Age.Duration(),
50 "archivalKeySize": len(resp.ArchivalKey), 52 "archivalKeySize": len(resp.ArchivalKey),
51 }.Infof(c, "Successfully loaded log stream state.") 53 }.Infof(c, "Successfully loaded log stream state.")
52 return &resp, nil 54 return &resp, nil
53 55
54 case ds.ErrNoSuchEntity: 56 case ds.ErrNoSuchEntity:
55 return nil, grpcutil.Errf(codes.NotFound, "Log stream was not fo und.") 57 return nil, grpcutil.Errf(codes.NotFound, "Log stream was not fo und.")
56 58
57 default: 59 default:
58 log.WithError(err).Errorf(c, "Failed to load log stream.") 60 log.WithError(err).Errorf(c, "Failed to load log stream.")
59 return nil, grpcutil.Internal 61 return nil, grpcutil.Internal
60 } 62 }
61 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698