This repository has been archived by the owner on May 2, 2018. It is now read-only.
/
main.go
99 lines (86 loc) · 2.99 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
_ "net/http/pprof"
"os"
"github.com/Financial-Times/base-ft-rw-app-go/baseftrwapp"
"github.com/Financial-Times/go-fthealth/v1a"
"github.com/Financial-Times/neo-utils-go/neoutils"
"github.com/Financial-Times/subjects-rw-neo4j/subjects"
log "github.com/Sirupsen/logrus"
"github.com/jawher/mow.cli"
)
func init() {
log.SetFormatter(new(log.JSONFormatter))
}
func main() {
app := cli.App("subjetcs-rw-neo4j", "A RESTful API for managing Subjects in neo4j")
neoURL := app.String(cli.StringOpt{
Name: "neo-url",
Value: "http://localhost:7474/db/data",
Desc: "neo4j endpoint URL",
EnvVar: "NEO_URL",
})
graphiteTCPAddress := app.String(cli.StringOpt{
Name: "graphite-tcp-address",
Value: "",
Desc: "Graphite TCP address, e.g. graphite.ft.com:2003. Leave as default if you do NOT want to output to graphite (e.g. if running locally",
EnvVar: "GRAPHITE_TCP_ADDRESS",
})
graphitePrefix := app.String(cli.StringOpt{
Name: "graphite-prefix",
Value: "",
Desc: "Prefix to use. Should start with content, include the environment, and the host name. e.g. coco.pre-prod.subjects-rw-neo4j.1",
EnvVar: "GRAPHITE_PREFIX",
})
port := app.Int(cli.IntOpt{
Name: "port",
Value: 8080,
Desc: "Port to listen on",
EnvVar: "PORT",
})
batchSize := app.Int(cli.IntOpt{
Name: "batch-size",
Value: 1024,
Desc: "Maximum number of statements to execute per batch",
EnvVar: "BATCH_SIZE",
})
logMetrics := app.Bool(cli.BoolOpt{
Name: "log-metrics",
Value: false,
Desc: "Whether to log metrics. Set to true if running locally and you want metrics output",
EnvVar: "LOG_METRICS",
})
app.Action = func() {
conf := neoutils.DefaultConnectionConfig()
conf.BatchSize = *batchSize
db, err := neoutils.Connect(*neoURL, conf)
if err != nil {
log.Errorf("Could not connect to neo4j, error=[%s]\n", err)
}
subjectsDriver := subjects.NewCypherSubjectsService(db)
subjectsDriver.Initialise()
baseftrwapp.OutputMetricsIfRequired(*graphiteTCPAddress, *graphitePrefix, *logMetrics)
endpoints := map[string]baseftrwapp.Service{
"subjects": subjectsDriver,
}
var checks []v1a.Check
for _, e := range endpoints {
checks = append(checks, makeCheck(e, db))
}
baseftrwapp.RunServer(endpoints,
v1a.Handler("ft-subjects_rw_neo4j ServiceModule", "Writes 'subjects' to Neo4j, usually as part of a bulk upload done on a schedule", checks...),
*port, "subjects-rw-neo4j", "local")
}
app.Run(os.Args)
}
func makeCheck(service baseftrwapp.Service, cr neoutils.CypherRunner) v1a.Check {
return v1a.Check{
BusinessImpact: "Cannot read/write subjects via this writer",
Name: "Check connectivity to Neo4j - neoUrl is a parameter in hieradata for this service",
PanicGuide: "TODO - write panic guide",
Severity: 1,
TechnicalSummary: fmt.Sprintf("Cannot connect to Neo4j instance %s with at least one subject loaded in it", cr),
Checker: func() (string, error) { return "", service.Check() },
}
}