https://github.com/financial-times/neo-utils-go
Neo4j Utils in Go
https://github.com/financial-times/neo-utils-go
universal-publishing
Last synced: 5 months ago
JSON representation
Neo4j Utils in Go
- Host: GitHub
- URL: https://github.com/financial-times/neo-utils-go
- Owner: Financial-Times
- License: mit
- Archived: true
- Created: 2016-01-11T13:20:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T08:32:36.000Z (almost 5 years ago)
- Last Synced: 2025-08-15T06:21:58.687Z (10 months ago)
- Topics: universal-publishing
- Language: Go
- Size: 78.1 KB
- Stars: 2
- Watchers: 23
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# neo-utils-go
[](https://circleci.com/gh/Financial-Times/neo-utils-go)
Neo4j Utils in Go.
Provides a wrapper for neoism.Database to output the database URL in the String() method.
Provides an EnsureIndexes function that will take a map of label/property pairs,
and an IndexManager (normally this will be a neoism.Database) and checks whether these
indexes exist. If not, they are created.
## Batch Cypher Runner
Currently supports batch running of queries.
1. Import "github.com/Financial-Times/neo-cypher-runner-go"
2. Create a batch cypher runner like this:
cypherRunner := neocypherrunner.NewBatchCypherRunner(db, maxBatchSize)
3. Execute a batch of queries like this:
cypherRunner.CypherBatch([]*neoism.CypherQuery{query})
### Logging
To use neo-utils-go in a service, follow these steps:
1. Migrate the service to Go modules and then to go-logger v2
2. Update the neo-utils-go version to v2.
3. Initialize the logger and add the instance to the function parameters in any of the neo-utils-go functions that requires it.
The logger initialization will vary depending on the service logs.
// Non-JSON
l := logger.NewUnstructuredLogger()
// JSON, no "@time" key
l := logger.NewUPPLogger(*serviceName, "INFO")
// JSON + @time
logConf := logger.KeyNamesConfig{KeyTime: "@time"}
l := logger.NewUPPLogger(*serviceName, "INFO", logConf)
The logger is an optional parameter. If it is not provided by the user, the library will create a logger with an INFO logging level.
### Metrics
There are three metrics that this library will capture, using go-metrics:
- batchQueueSize: a gauge which keeps track of the number of queued requests, i.e. waiting to be written to Neo4j
- batchThroughput: a meter keeping track of queries processed, with throughput over several time periods
- execute-neo4j-batch: a timer measuring how long each batch or queries takes to run against neo4j
To use the metrics, set up metrics in your application, for example to output to graphite.ft.com:
addr, _ := net.ResolveTCPAddr("tcp", graphiteTCPAddress)
go graphite.Graphite(metrics.DefaultRegistry, 1*time.Minute, graphitePrefix, addr)
where, for example:
- graphiteTCPAddress is for graphite.ft.com:2003
- and graphitePrefix is unique for your service, e.g. content.[env].people.rw.neo4j.[hostname] - you should probably set this from environment-specific configuration, e.g. hiera data