Skip to content

Commit 0e0f72e

Browse files
authored
Add install_ci dependency in Makefile (#5) - Issue #1
* Add install_ci dependency in Makefile * Fix negation * Address comments PR#5 * Minor edits
1 parent 4090cc7 commit 0e0f72e

14 files changed

+86
-79
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ${builddir}:
88
mkdir -p $(builddir)
99

1010
.PHONY: bins
11-
bins:
11+
bins: install_ci
1212
go build -o ${builddir}/arachned github.com/uber/arachne/arachned/
1313

1414
all: bins
@@ -22,7 +22,7 @@ lint:
2222
go vet $(PACKAGES)
2323

2424
.PHONY: test
25-
test: check-license lint
25+
test: check-license lint install_ci
2626
find . -type f -name '*.go' | xargs golint
2727
go test $(PACKAGES)
2828

arachned/config/test_target_config_darwin.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
"internal": [
1919
{"ip": "10.10.39.31"},
20-
{"ip": "10.10.15.27"}
20+
{"ip": "10.10.15.27"},
21+
{"host_name": "compute777.myservers.com"},
22+
{"host_name": "hadoop375.myservers.com"}
23+
],
24+
25+
"external": [
26+
{"host_name": "payments.service.org"},
27+
{"host_name": "maps.service.com"}
2128
]
2229
}

arachned/config/test_target_config_linux.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
"internal": [
1919
{"ip": "10.10.39.31"},
20-
{"ip": "10.10.15.27"}
20+
{"ip": "10.10.15.27"},
21+
{"host_name": "compute777.myservers.com"},
22+
{"host_name": "hadoop375.myservers.com"}
23+
],
24+
25+
"external": [
26+
{"host_name": "payments.service.org"},
27+
{"host_name": "maps.service.com"}
2128
]
2229
}

bootstrap.go

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func Run(ec *config.Extended, opts ...Option) {
4949
apply(&gl, opts...)
5050
gl.App, err = config.Get(*gl.CLI.ConfigFile, ec, bootstrapLogger)
5151
if err != nil {
52+
bootstrapLogger.Error("error reading the configuration file",
53+
zap.String("file", *gl.CLI.ConfigFile),
54+
zap.Error(err))
5255
os.Exit(1)
5356
}
5457

collector/collector.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (rs resultStore) walkResults(
151151
}
152152
}
153153

154-
// processResults calculates metrics, uploads stats and stores in results[] for stdout, if needed
154+
// processResults calculates metrics, uploads stats and stores in results[] for stdout, if needed.
155155
func (rs resultStore) processResults(
156156
gl *config.Global,
157157
remotes config.RemoteStore,
@@ -390,7 +390,7 @@ func statsUpload(
390390

391391
}
392392

393-
// zeroOutResults fills latencies for targets not existing in resultStore with zeros
393+
// zeroOutResults fills latencies for targets not existing in resultStore with zeros.
394394
func zeroOutResults(
395395
glr *config.RemoteConfig,
396396
ms messageStore,

config/config.go

+31-36
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package config
2222

2323
import (
2424
"encoding/json"
25+
"errors"
2526
"fmt"
2627
"io/ioutil"
2728
"net"
@@ -61,7 +62,6 @@ type OrchestratorConfig struct {
6162
// BasicConfig holds the basic parameter configurations for the application.
6263
type BasicConfig struct {
6364
Logging log.Config `yaml:"logging"`
64-
Verbose bool `yaml:"verbose"`
6565
Arachne ArachneConfiguration `yaml:"arachne"`
6666
}
6767

@@ -70,7 +70,7 @@ type Extended struct {
7070
Metrics metrics.Opt
7171
}
7272

73-
// RemoteStore holds all Remotes
73+
// RemoteStore holds all Remotes.
7474
type RemoteStore map[string]Remote
7575

7676
// Remote holds the info for every target to be echoed.
@@ -191,48 +191,50 @@ func Get(cf string, ec *Extended, logger zap.Logger) (*AppConfig, error) {
191191

192192
data, err := ioutil.ReadFile(cf)
193193
if err != nil {
194-
logger.Error("error reading the configuration file", zap.String("file", cf), zap.Error(err))
195194
return nil, err
196195
}
197196

198197
b, err := unmarshalBasicConfig(data, cf, logger)
198+
if err != nil {
199+
return nil, err
200+
}
201+
199202
mc, err := ec.Metrics.UnmarshalConfig(data, cf, logger)
200203
if err != nil {
201204
return nil, err
202205
}
203206

204207
cfg := AppConfig{
205208
Logging: b.Logging,
206-
Verbose: b.Verbose,
207209
PIDPath: b.Arachne.PIDPath,
208210
Orchestrator: b.Arachne.Orchestrator,
209211
StandaloneTargetConfig: b.Arachne.StandaloneTargetConfig,
210212
Metrics: mc,
211213
}
212214

215+
if !cfg.Orchestrator.Enabled && cfg.StandaloneTargetConfig == "" {
216+
return nil, errors.New("the standalone-mode target configuration file has not been specified")
217+
}
218+
213219
return &cfg, nil
214220
}
215221

216-
// unmarshalBasicConfig fetches the configuration file from local path
222+
// unmarshalBasicConfig fetches the configuration file from local path.
217223
func unmarshalBasicConfig(data []byte, fname string, logger zap.Logger) (*BasicConfig, error) {
218224

219225
cfg := new(BasicConfig)
220226
if err := yaml.Unmarshal(data, cfg); err != nil {
221-
logger.Error("error unmarshaling the configuration file",
222-
zap.String("file", fname),
223-
zap.Error(err))
224-
return nil, err
227+
return nil, fmt.Errorf("error unmarshaling the configuration file %s: %v", fname, err)
225228
}
226229
// Validate on the merged config at the end
227230
if err := validator.Validate(cfg); err != nil {
228-
logger.Error("invalid info in configuration file", zap.String("file", fname), zap.Error(err))
229-
return nil, err
231+
return nil, fmt.Errorf("invalid info in configuration file %s: %v", fname, err)
230232
}
231233

232234
return cfg, nil
233235
}
234236

235-
// FetchRemoteList fetches the configuration file from local path or, remotely, from Arachne Orchestrator
237+
// FetchRemoteList fetches the configuration file from local path or, remotely, from Arachne Orchestrator.
236238
func FetchRemoteList(
237239
gl *Global,
238240
maxNumRemoteTargets int,
@@ -254,7 +256,7 @@ func FetchRemoteList(
254256
zap.String("path", gl.App.StandaloneTargetConfig))
255257

256258
if err := localFileReadable(gl.App.StandaloneTargetConfig); err != nil {
257-
logger.Fatal("unable to retrieve local configuration file",
259+
logger.Fatal("unable to retrieve local target configuration file",
258260
zap.String("file", gl.App.StandaloneTargetConfig),
259261
zap.Error(err))
260262
}
@@ -294,7 +296,7 @@ func FetchRemoteList(
294296
return err
295297
}
296298

297-
// createHTTPClient returns an HTTP client to connect to remote server
299+
// createHTTPClient returns an HTTP client to connect to remote server.
298300
func createHTTPClient(timeout time.Duration, disableKeepAlives bool) *http.Client {
299301
client := &http.Client{
300302
Transport: &http.Transport{
@@ -309,7 +311,7 @@ func createHTTPClient(timeout time.Duration, disableKeepAlives bool) *http.Clien
309311
return client
310312
}
311313

312-
// GetHostname returns the hostname
314+
// GetHostname returns the hostname.
313315
func GetHostname(logger zap.Logger) (string, error) {
314316
host, err := os.Hostname()
315317
if err != nil {
@@ -319,7 +321,7 @@ func GetHostname(logger zap.Logger) (string, error) {
319321
return host, nil
320322
}
321323

322-
// refreshRemoteList checks with Arachne Orchestrator if new a config file should be fetched
324+
// refreshRemoteList checks with Arachne Orchestrator if new a config file should be fetched.
323325
func refreshRemoteList(
324326
gl *Global,
325327
remotes RemoteStore,
@@ -335,8 +337,6 @@ func refreshRemoteList(
335337
retryTime := gl.RemoteConfig.PollOrchestratorInterval.Failure
336338

337339
for {
338-
var err error
339-
340340
hostname, _ := GetHostname(logger)
341341
RESTReq := fmt.Sprintf("http://%s/%s/%s?hostname=%s",
342342
gl.App.Orchestrator.AddrPort,
@@ -395,7 +395,7 @@ func fetchRemoteListFromOrchestrator(
395395
// Build the request
396396
req, err := http.NewRequest("GET", url, nil)
397397
if err != nil {
398-
logger.Debug("NewRequest", zap.Error(err))
398+
logger.Warn("NewRequest", zap.Error(err))
399399
return 0, nil, err
400400
}
401401
resp, err := client.Do(req)
@@ -411,19 +411,14 @@ func fetchRemoteListFromOrchestrator(
411411
switch resp.StatusCode {
412412
case http.StatusOK:
413413
logger.Debug("HTTP response status code from Orchestrator")
414-
415-
if bResp, err = ioutil.ReadAll(resp.Body); err != nil {
416-
break
417-
}
418-
414+
bResp, err = ioutil.ReadAll(resp.Body)
419415
case http.StatusNotFound:
420-
logger.Error("HTTP response from Orchestrator: 'Idle mode'")
416+
err = fmt.Errorf("HTTP response from Orchestrator: 'Idle mode'")
421417
case http.StatusBadRequest:
422-
logger.Error("HTTP response from Orchestrator: 'Please specify hostname or DC!'")
418+
err = fmt.Errorf("HTTP response from Orchestrator: 'Please specify hostname or DC!'")
423419
case http.StatusInternalServerError:
424420
logger.Warn("HTTP response from Orchestrator: Error opening requested configuration file")
425421
default:
426-
logger.Error("unhandled HTTP response from Orchestrator")
427422
err = fmt.Errorf("unhandled HTTP response from Orchestrator")
428423
}
429424

@@ -448,8 +443,7 @@ func readRemoteList(
448443
c := new(RemoteFileConfig)
449444

450445
if err := json.Unmarshal(raw, c); err != nil {
451-
logger.Error("configuration file parse error", zap.Error(err))
452-
return err
446+
return fmt.Errorf("configuration file parse error (%v)", err)
453447
}
454448

455449
// Populate global variables
@@ -475,15 +469,15 @@ func readRemoteList(
475469
srcIP, err = network.GetSourceAddr("ip6", strings.ToLower(c.Local.SrcAddress),
476470
glRC.HostName, glRC.InterfaceName, logger)
477471
if err != nil {
478-
return fmt.Errorf("could not retrieve an IPv4 or IPv6 source address")
472+
return fmt.Errorf("could not retrieve an IPv4 or IPv6 source address (%v)", err)
479473
}
480474
}
481475
glRC.SrcAddress = *srcIP
482476
logger.Debug("Arachne agent's source IP address", zap.Object("address", glRC.SrcAddress))
483477

484478
glRC.TargetTCPPort = c.Local.TargetTCPPort
485479
if glRC.Timeout, err = time.ParseDuration(c.Local.Timeout); err != nil {
486-
return fmt.Errorf("failed to parse the timeout")
480+
return fmt.Errorf("failed to parse the timeout (%v)", err)
487481
}
488482
glRC.SrcTCPPortRange[0] = c.Local.BaseSrcTCPPort
489483
if c.Local.NumSrcTCPPorts > maxNumSrcTCPPorts {
@@ -498,18 +492,18 @@ func readRemoteList(
498492
"source ports [%d-%d]", glRC.SrcTCPPortRange[0], glRC.SrcTCPPortRange[1])
499493
}
500494
if glRC.BatchInterval, err = time.ParseDuration(c.Local.BatchInterval); err != nil {
501-
return fmt.Errorf("failed to parse the batch interval")
495+
return fmt.Errorf("failed to parse the batch interval (%v)", err)
502496
}
503497
if glRC.BatchInterval < minBatchInterval {
504498
return fmt.Errorf("the batch cycle interval cannot be shorter than %v", minBatchInterval)
505499
}
506500
if glRC.PollOrchestratorInterval.Success, err =
507501
time.ParseDuration(c.Local.PollOrchestratorIntervalSuccess); err != nil {
508-
return fmt.Errorf("failed to parse the Orchestrator poll interval for success")
502+
return fmt.Errorf("failed to parse the Orchestrator poll interval for success (%v)", err)
509503
}
510504
if glRC.PollOrchestratorInterval.Failure, err =
511505
time.ParseDuration(c.Local.PollOrchestratorIntervalFailure); err != nil {
512-
return fmt.Errorf("failed to parse the Orchestrator poll interval for failure")
506+
return fmt.Errorf("failed to parse the Orchestrator poll interval for failure (%v)", err)
513507
}
514508

515509
glRC.QoSEnabled = isTrue(c.Local.QoSEnabled)
@@ -537,7 +531,7 @@ func readRemoteList(
537531
return nil
538532
}
539533

540-
// Validate and create map of ipv4 and ipv6 addresses with string as their key
534+
// Validate and create map of ipv4 and ipv6 addresses with string as their key.
541535
func walkTargets(grc *RemoteConfig, ts []target, ext bool, remotes RemoteStore, logger zap.Logger) {
542536

543537
for _, t := range ts {
@@ -563,7 +557,8 @@ func walkTargets(grc *RemoteConfig, ts []target, ext bool, remotes RemoteStore,
563557
zap.String("target", currIP.String()))
564558
continue
565559
}
566-
remotes[currIP.String()] = Remote{currIP, network.Family(&currIP), t.HostName, ext}
560+
remotes[currIP.String()] = Remote{currIP, network.Family(&currIP),
561+
t.HostName, ext}
567562
}
568563
}
569564

internal/log/log.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ type Config struct {
4444
LogSink string `yaml:"logSink"`
4545
}
4646

47-
// Fatal extends the zap Fatal to also remove the PID file
47+
// Fatal extends the zap Fatal to also remove the PID file.
4848
func (log PIDRemoverLogger) Fatal(msg string, fields ...zap.Field) {
4949
log.RemovePID(log.PIDPath, log.Logger)
5050
log.Logger.Fatal(msg, fields...)
5151
}
5252

53-
// Panic extends the zap Panic to also remove the PID file
53+
// Panic extends the zap Panic to also remove the PID file.
5454
func (log PIDRemoverLogger) Panic(msg string, fields ...zap.Field) {
5555
log.RemovePID(log.PIDPath, log.Logger)
5656
log.Logger.Fatal(msg, fields...)
5757
}
5858

59-
// CreateLogger creates a zap logger
59+
// CreateLogger creates a zap logger.
6060
func CreateLogger(
6161
c *Config,
6262
service string,
@@ -101,7 +101,7 @@ func CreateLogger(
101101
}
102102

103103
// ResetLogFile keeps the last 'LogFileSizeKeepKB' KB of the log file if the size of the log file
104-
// has exceeded 'LogFileSizeMaxMB' MB within the last 'PollOrchestratorIntervalSuccess' hours
104+
// has exceeded 'LogFileSizeMaxMB' MB within the last 'PollOrchestratorIntervalSuccess' hours.
105105
func ResetLogFile(logFilePath string, fileSizeMaxMB int, fileSizeKeepKB int, logger zap.Logger) error {
106106
file, err := os.Open(logFilePath)
107107
if err != nil {

internal/network/network.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func GetSourceAddr(
6363
return anyInterfaceAddress(af)
6464
}
6565

66-
// Resolve given domain hostname/address in the given address family
66+
// Resolve given domain hostname/address in the given address family.
6767
//TODO replace with net.LookupHost?
6868
func resolveHost(af string, hostname string, logger zap.Logger) (*net.IP, error) {
6969
addr, err := net.ResolveIPAddr(af, hostname)

0 commit comments

Comments
 (0)