go-infrabin
infrabin written in go.
Warning: go-infrabin
exposes sensitive endpoints and should NEVER be used on the public Internet.
Usage
go-infrabin
exposes three ports:
8888
as a http rest port
8899
as the http rest admin port, for liveness and readiness probes
50051
as a grpc port
Installation
See the README.
Command line flags
--admin-host
: HTTP server host (default 0.0.0.0
)
--admin-port
: HTTP server port (default 8889
)
--aws-metadata-endpoint
: AWS Metadata Endpoint (default http://169.254.169.254/latest/meta-data/
)
--drain-timeout
: Drain timeout (default 15s
)
--enable-proxy-endpoint
: When enabled allows /proxy
and /aws
endpoints
--grpc-host
: gRPC host (default 0.0.0.0
)
--grpc-port
: gRPC port (default 50051
)
-h
, --help
: help for go-infrabin
--http-idle-timeout
: HTTP idle timeout (default 15s
)
--http-read-header-timeout
: HTTP read header timeout (default 15s
)
--http-read-timeout
: HTTP read timeout (default 1m0s
)
--http-write-timeout
: HTTP write timeout (default 2m1s
)
--max-delay duration
: Maximum delay (default 2m0s
)
--prom-host
: Prometheus metrics host (default 0.0.0.0
)
--prom-port
: Prometheus metrics port (default 8887
)
--server-host
: HTTP server host (default 0.0.0.0
)
--server-port
: HTTP server port (default 8888
)
Environment variables
INFRABIN_MAX_DELAY
: to change the maximum value for the /delay
endpoint. Default to 120.
FAIL_ROOT_HANDLER
: if set, the /
endpoint will return a 503. This is useful when doing a B/G deployment to test the failure and rollback scenario.
Service Endpoints
-
grpc: infrabin.Infrabin.Root
rest: GET /
- grpc request
message Empty {}
- returns: a JSON response
{
"hostname": "<hostname>",
"kubernetes": {
"pod_name": "<pod_name>",
"namespace": "<namespace>",
"pod_ip": "<pod_ip>",
"node_name": "<node_name>"
}
}
-
grpc: infrabin.Infrabin.Delay
rest: GET /delay/<seconds>
-
grpc: infrabin.Infrabin.Headers
rest: GET /headers
-
grpc: infrabin.Infrabin.Env
rest: GET /env/<env_var>
-
grpc: infrabin.Infrabin.Proxy
rest: GET /proxy
-
grpc: infrabin.Infrabin.AWS
rest: GET /aws/<path>
Admin Endpoints
- grpc:
infrabin.Infrabin.Liveness
rest: GET /liveness
- grpc request
message Empty {}
- returns: a JSON response if healthy or the status code
503
if unhealthy.
{
"liveness": "pass"
}
Errors
When caling the http endpoint, errors are mapped by grpc-gateway
. They
have the following format:
- returns:
{
"code": 3,
"message": "type mismatch, parameter: duration, error: strconv.ParseInt: parsing \"21asd\": invalid syntax"
}
Contributing
To build locally, ensure you have compiled the protocol schemas. You
will need the protoc
binary which can install by following
these instructions or if using Homebrew
brew install protobuf
You will also need to protoc go plugins for protofuf, grpc, and
grpc-gateway. go mod tidy
will fetch the versions specified in
go.mod
, and go install
will install that version.
go get -t -v -d ./...
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
make run
will compile the protocol
buffers, or you can run:
make protoc
To run the tests:
make test
To run the server locally:
make run
To test http:
http localhost:8888/
To test grpc, use your favourite grpc tool like evans:
echo '{}' | evans -r cli call infrabin.Infrabin.Root