The Transit Connection Generator (TCG). TCG contains two sub-systems/packages:
- Transit agent - connects and sends metrics to Groundwork Monitor
- Controller service - an http server for external control of agent
The TCG project is built with Go Modules. See go.mod
for a list of dependencies. Here are some main frameworks used by this project:
-
Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster.
github.com/gin-gonic/gin
-
Gin middleware for session management with multi-backend support.
github.com/gin-gonic/contrib/sessions
-
github.com/nats-io/go-nats-streaming github.com/nats-io/nats-streaming-server/server github.com/nats-io/nats-streaming-server/stores
-
Package envconfig implements decoding of environment variables based on a user defined specification. A typical use is using environment variables for configuration settings.
github.com/kelseyhightower/envconfig
-
Go-Cache is an in-memory key:value store/cache similar to memcached that is suitable for applications running on a single machine. Its major advantage is that, being essentially a thread-safe map[string]interface{} with expiration times, it doesn't need to serialize or transmit its contents over the network. Any object can be stored, for a given duration or forever, and the cache can be safely used by multiple goroutines.
github.com/patrickmn/go-cache
-
Go code (golang) set of packages that provide many tools for testifying that your code will behave as you intend.
github.com/stretchr/testify
-
Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.
github.com/sirupsen/logrus
Log levels:
0 - Error; 1 - Warn; 2 - Info; 3 - Debug
-
The challenge is porting all psutil functions on some architectures.
github.com/shirou/gopsutil
-
Gin Gonic middleware to automatically generate RESTful API documentation with Swagger 2.0.
github.com/swaggo/gin-swagger
Generate 'docs.go' for Swagger UI
$ swag init
Swagger url:
{host}:{port}/swagger/index.html
$ cd tcg
$ go build .
$ go build -ldflags "-X 'github.com/gwos/tcg/config.buildTime=`date --rfc-3339=s`' -X 'github.com/gwos/tcg/config.buildTag=<TAG>'" -buildmode=c-shared -o libtransit/libtransit.so libtransit/libtransit.go
LINUX:
$ cd connectors/<connector>
$ go build -ldflags "-X 'github.com/gwos/tcg/config.buildTime=`date --rfc-3339=s`' -X 'github.com/gwos/tcg/config.buildTag=<TAG>'"
OS X:
$ cd connectors/<connector>
$ go build -ldflags "-X 'github.com/gwos/tcg/config.buildTime=`date -u +"%Y-%m-%dT%H:%M:%SZ"`' -X 'github.com/gwos/tcg/config.buildTag=<TAG>'"
env GOOS=linux GOARCH=386 go build -ldflags "-X 'github.com/gwos/tcg/config.buildTime=`date -u +"%Y-%m-%dT%H:%M:%SZ"`' -X 'github.com/gwos/tcg/config.buildTag=8.1.0.1'"
To enable:
sudo systemctl enable tcg-elastic
To start:
sudo systemctl start tcg-elastic
Show status:
sudo systemctl status tcg-elastic
To stop:
sudo systemctl stop tcg-elastic
To disable:
sudo systemctl disable tcg-elastic
To reconfigure:
sudo systemctl daemon-reload
To tail:
journalctl -f -u tcg-elastic
$ cd tcg
$ go run .
$ docker build -t groundworkdevelopment/tcg --build-arg GITHUB_TOKEN .
The gotests tool can generate Go tests.
Without logs:
$ TEST_GW_USERNAME=**** TEST_GW_PASSWORD=**** go test ./...
With logs:
$ TEST_GW_USERNAME=**** TEST_GW_PASSWORD=**** go test -v ./...
Without logs:
$ go test ./<package_name>/
With logs:
$ go test -v ./<package_one>/ ./<package_two>/
Before running integration tests you must provide environment variables for Groundwork Connection username and password:
$ TEST_GW_USERNAME=**** TEST_GW_PASSWORD=**** go test ./integration
$ go test ./integration/
$ go test -v ./config
Defines the path to libtransit.so
library in docker container and tests.
$ export LIBTRANSIT=/path/to/libtransit.so
By default, the config file is looked for in the work directory as tcg_config.yaml
.
The path to config file and any config option can be overridden with env vars:
$ export TCG_CONFIG=/path/to/tcg_config.yaml
$ export TCG_CONNECTOR_NATSSTORETYPE=MEMORY
For more info see package config
and tests.