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

Side by Side Diff: common/tsmon/target/flags.go

Issue 2225933003: tsmon: read hostname and region from config file (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Created 4 years, 4 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
« common/tsmon/iface.go ('K') | « common/tsmon/iface_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 target 5 package target
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "os" 9 "os"
10 "regexp" 10 "regexp"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // SetDefaultsFromHostname computes the expensive default values for hostname, 59 // SetDefaultsFromHostname computes the expensive default values for hostname,
60 // region and network fields. 60 // region and network fields.
61 func (fl *Flags) SetDefaultsFromHostname() { 61 func (fl *Flags) SetDefaultsFromHostname() {
62 if fl.SysInfo == nil { 62 if fl.SysInfo == nil {
63 hostname, region := getFQDN() 63 hostname, region := getFQDN()
64 fl.SysInfo = &SysInfo{Hostname: hostname, Region: region} 64 fl.SysInfo = &SysInfo{Hostname: hostname, Region: region}
65 } 65 }
66 network := getNetwork(fl.SysInfo.Hostname) 66 network := getNetwork(fl.SysInfo.Hostname)
67 hostname := fl.SysInfo.Hostname 67 hostname := fl.SysInfo.Hostname
68 68
69 if fl.AutoGenHostname {
70 hostname = "autogen:" + hostname
71 }
72 if fl.DeviceHostname == "" { 69 if fl.DeviceHostname == "" {
73 fl.DeviceHostname = hostname 70 fl.DeviceHostname = hostname
74 } 71 }
75 if fl.DeviceRegion == "" { 72 if fl.DeviceRegion == "" {
76 fl.DeviceRegion = fl.SysInfo.Region 73 fl.DeviceRegion = fl.SysInfo.Region
77 } 74 }
78 if fl.DeviceNetwork == "" { 75 if fl.DeviceNetwork == "" {
79 fl.DeviceNetwork = network 76 fl.DeviceNetwork = network
80 } 77 }
81 if fl.TaskRegion == "" { 78 if fl.TaskRegion == "" {
82 fl.TaskRegion = fl.SysInfo.Region 79 fl.TaskRegion = fl.SysInfo.Region
83 } 80 }
84 if fl.TaskHostname == "" { 81 if fl.TaskHostname == "" {
85 fl.TaskHostname = hostname 82 fl.TaskHostname = hostname
86 } 83 }
84 if fl.AutoGenHostname {
85 fl.DeviceHostname = "autogen:" + fl.DeviceHostname
86 fl.TaskHostname = "autogen:" + fl.TaskHostname
87 }
87 } 88 }
88 89
89 // Register adds tsmon target related flags to a FlagSet. 90 // Register adds tsmon target related flags to a FlagSet.
90 func (fl *Flags) Register(f *flag.FlagSet) { 91 func (fl *Flags) Register(f *flag.FlagSet) {
91 f.Var(&fl.TargetType, "ts-mon-target-type", 92 f.Var(&fl.TargetType, "ts-mon-target-type",
92 "the type of target that is being monitored ("+targetTypeEnum.Ch oices()+")") 93 "the type of target that is being monitored ("+targetTypeEnum.Ch oices()+")")
93 f.StringVar(&fl.DeviceHostname, "ts-mon-device-hostname", fl.DeviceHostn ame, 94 f.StringVar(&fl.DeviceHostname, "ts-mon-device-hostname", fl.DeviceHostn ame,
94 "name of this device") 95 "name of this device")
95 f.StringVar(&fl.DeviceRegion, "ts-mon-device-region", fl.DeviceRegion, 96 f.StringVar(&fl.DeviceRegion, "ts-mon-device-region", fl.DeviceRegion,
96 "name of the region this devices lives in") 97 "name of the region this devices lives in")
(...skipping 27 matching lines...) Expand all
124 } 125 }
125 return "unknown", "unknown" 126 return "unknown", "unknown"
126 } 127 }
127 128
128 func getNetwork(hostname string) string { 129 func getNetwork(hostname string) string {
129 if m := regexp.MustCompile(`^([\w-]*?-[acm]|master)(\d+)a?$`).FindString Submatch(hostname); m != nil { 130 if m := regexp.MustCompile(`^([\w-]*?-[acm]|master)(\d+)a?$`).FindString Submatch(hostname); m != nil {
130 return m[2] 131 return m[2]
131 } 132 }
132 return "" 133 return ""
133 } 134 }
OLDNEW
« common/tsmon/iface.go ('K') | « common/tsmon/iface_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698