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

Side by Side Diff: appengine/logdog/coordinator/endpoints/registration/registerPrefix.go

Issue 1972753002: LogDog: Implement prefix expiration. (Closed) Base URL: https://github.com/luci/luci-go@logdog-butler-register-coordinator-impl
Patch Set: Updated patchset dependency 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 registration 5 package registration
6 6
7 import ( 7 import (
8 ds "github.com/luci/gae/service/datastore" 8 ds "github.com/luci/gae/service/datastore"
9 "golang.org/x/net/context" 9 "golang.org/x/net/context"
10 "google.golang.org/grpc/codes" 10 "google.golang.org/grpc/codes"
11 11
12 "github.com/luci/luci-go/appengine/logdog/coordinator" 12 "github.com/luci/luci-go/appengine/logdog/coordinator"
13 "github.com/luci/luci-go/appengine/logdog/coordinator/endpoints"
13 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy" 14 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy"
14 "github.com/luci/luci-go/common/api/logdog_coordinator/registration/v1" 15 "github.com/luci/luci-go/common/api/logdog_coordinator/registration/v1"
15 "github.com/luci/luci-go/common/clock" 16 "github.com/luci/luci-go/common/clock"
16 "github.com/luci/luci-go/common/cryptorand" 17 "github.com/luci/luci-go/common/cryptorand"
17 "github.com/luci/luci-go/common/gcloud/pubsub" 18 "github.com/luci/luci-go/common/gcloud/pubsub"
18 "github.com/luci/luci-go/common/grpcutil" 19 "github.com/luci/luci-go/common/grpcutil"
19 "github.com/luci/luci-go/common/logdog/types" 20 "github.com/luci/luci-go/common/logdog/types"
20 log "github.com/luci/luci-go/common/logging" 21 log "github.com/luci/luci-go/common/logging"
21 ) 22 )
22 23
(...skipping 28 matching lines...) Expand all
51 } 52 }
52 53
53 // Load our service and project configurations. 54 // Load our service and project configurations.
54 svcs := coordinator.GetServices(c) 55 svcs := coordinator.GetServices(c)
55 cfg, err := svcs.Config(c) 56 cfg, err := svcs.Config(c)
56 if err != nil { 57 if err != nil {
57 log.WithError(err).Errorf(c, "Failed to load service configurati on.") 58 log.WithError(err).Errorf(c, "Failed to load service configurati on.")
58 return nil, grpcutil.Internal 59 return nil, grpcutil.Internal
59 } 60 }
60 61
62 pcfg, err := coordinator.CurrentProjectConfig(c)
63 if err != nil {
64 log.WithError(err).Errorf(c, "Failed to load project configurati on.")
65 return nil, grpcutil.Internal
66 }
67
68 // Determine our prefix expiration. This must be > 0, else there will be no
69 // window when log streams can be registered and this prefix is useless.
70 //
71 // We will choose the shortest expiration window defined by our request and
72 // our project and service configurations.
73 expiration := endpoints.MinDuration(req.Expiration, cfg.Coordinator.Pref ixExpiration, pcfg.PrefixExpiration)
74 if expiration <= 0 {
75 log.Errorf(c, "Refusing to register prefix in expired state.")
76 return nil, grpcutil.Errf(codes.InvalidArgument, "no prefix expi ration defined")
77 }
78
61 // Determine our Pub/Sub topic. 79 // Determine our Pub/Sub topic.
62 cfgTransport := cfg.Transport 80 cfgTransport := cfg.Transport
63 if cfgTransport == nil { 81 if cfgTransport == nil {
64 log.Errorf(c, "Missing transport configuration.") 82 log.Errorf(c, "Missing transport configuration.")
65 return nil, grpcutil.Internal 83 return nil, grpcutil.Internal
66 } 84 }
67 85
68 cfgTransportPubSub := cfgTransport.GetPubsub() 86 cfgTransportPubSub := cfgTransport.GetPubsub()
69 if cfgTransportPubSub == nil { 87 if cfgTransportPubSub == nil {
70 log.Errorf(c, "Missing transport Pub/Sub configuration.") 88 log.Errorf(c, "Missing transport Pub/Sub configuration.")
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 case exists: 144 case exists:
127 log.Errorf(c, "The prefix is already registered (transac tional).") 145 log.Errorf(c, "The prefix is already registered (transac tional).")
128 return grpcutil.AlreadyExists 146 return grpcutil.AlreadyExists
129 } 147 }
130 148
131 // The Prefix is not registered, so let's register it. 149 // The Prefix is not registered, so let's register it.
132 pfx.Created = now 150 pfx.Created = now
133 pfx.Prefix = string(prefix) 151 pfx.Prefix = string(prefix)
134 pfx.Source = req.SourceInfo 152 pfx.Source = req.SourceInfo
135 pfx.Secret = []byte(secret) 153 pfx.Secret = []byte(secret)
154 pfx.Expiration = now.Add(expiration)
136 155
137 if err := di.Put(pfx); err != nil { 156 if err := di.Put(pfx); err != nil {
138 log.WithError(err).Errorf(c, "Failed to register prefix. ") 157 log.WithError(err).Errorf(c, "Failed to register prefix. ")
139 return grpcutil.Internal 158 return grpcutil.Internal
140 } 159 }
141 160
142 log.Infof(c, "The prefix was successfully registered.") 161 log.Infof(c, "The prefix was successfully registered.")
143 return nil 162 return nil
144 }, nil) 163 }, nil)
145 if err != nil { 164 if err != nil {
146 log.WithError(err).Errorf(c, "Failed to register prefix (transac tional).") 165 log.WithError(err).Errorf(c, "Failed to register prefix (transac tional).")
147 return nil, err 166 return nil, err
148 } 167 }
149 168
150 return &logdog.RegisterPrefixResponse{ 169 return &logdog.RegisterPrefixResponse{
151 Secret: []byte(secret), 170 Secret: []byte(secret),
152 LogBundleTopic: string(pubsubTopic), 171 LogBundleTopic: string(pubsubTopic),
153 }, nil 172 }, nil
154 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698