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

Side by Side Diff: server/internal/logdog/config/flag.go

Issue 1610993002: LogDog: Add collector service implementation. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Comments, rebase. Created 4 years, 10 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
« no previous file with comments | « server/internal/logdog/config/fileConfig.go ('k') | server/internal/logdog/config/flag_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package config
6
7 import (
8 "errors"
9 "flag"
10 "net/http"
11 "time"
12
13 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
14 "github.com/luci/luci-go/common/clock/clockflag"
15 "github.com/luci/luci-go/common/config"
16 "github.com/luci/luci-go/common/config/impl/remote"
17 "github.com/luci/luci-go/common/proto/google"
18 "github.com/luci/luci-go/common/transport"
19 "golang.org/x/net/context"
20 )
21
22 // Flags is a set of command-line flags used to set up the process'
23 // configuration.
24 type Flags struct {
25 // ConfigPath is the path within the ConfigSet of the configuration.
26 //
27 // If ConfigURL is empty, this will be interpreted as a local filesystem path
28 // from which the configuration should be loaded.
29 ConfigFilePath string
30
31 // KillCheckInterval, if >0, starts a goroutine that polls every interva l to
32 // see if the configuration has changed.
33 KillCheckInterval clockflag.Duration
34
35 // RoundTripper, if not nil, is the http.RoundTripper that will be used to
36 // fetch remote configurations.
37 RoundTripper http.RoundTripper
38 }
39
40 // AddToFlagSet augments the supplied FlagSet with values for Flags.
41 func (f *Flags) AddToFlagSet(fs *flag.FlagSet) {
42 fs.StringVar(&f.ConfigFilePath, "config-file-path", "",
43 "If set, load the configuration protobuf from this path instead of the configuration service.")
44 fs.Var(&f.KillCheckInterval, "config-kill-interval",
45 "If non-zero, poll for configuration changes and kill the applic ation if one is detected.")
46 }
47
48 // CoordinatorOptions returns an Options instance loaded from the supplied flags
49 // and Coordinator instance.
50 func (f *Flags) CoordinatorOptions(c context.Context, client services.ServicesCl ient) (*Options, error) {
51 ccfg, err := client.GetConfig(c, &google.Empty{})
52 if err != nil {
53 return nil, err
54 }
55
56 // If a ConfigFilePath was specified, use a mock configuration service t hat
57 // loads from a local file.
58 var ci config.Interface
59 if f.ConfigFilePath != "" {
60 ci = &fileConfig{
61 path: f.ConfigFilePath,
62 configSet: ccfg.ConfigSet,
63 configPath: ccfg.ConfigPath,
64 }
65 } else {
66 if ccfg.ConfigServiceUrl == "" {
67 return nil, errors.New("coordinator does not specify a c onfig service")
68 }
69 if ccfg.ConfigSet == "" {
70 return nil, errors.New("coordinator does not specify a c onfig set")
71 }
72 if ccfg.ConfigPath == "" {
73 return nil, errors.New("coordinator does not specify a c onfig path")
74 }
75
76 if f.RoundTripper != nil {
77 c = transport.Set(c, f.RoundTripper)
78 }
79 ci = remote.New(c, ccfg.ConfigServiceUrl)
80 }
81
82 return &Options{
83 Config: ci,
84 ConfigSet: ccfg.ConfigSet,
85 ConfigPath: ccfg.ConfigPath,
86 KillCheckInterval: time.Duration(f.KillCheckInterval),
87 }, nil
88 }
OLDNEW
« no previous file with comments | « server/internal/logdog/config/fileConfig.go ('k') | server/internal/logdog/config/flag_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698