Skip to content

Commit

Permalink
Merge pull request #62 from mrpalide/fix/move-ut-back-here
Browse files Browse the repository at this point in the history
Move back UT
  • Loading branch information
mrpalide authored Mar 26, 2024
2 parents caaa6f3 + 724b119 commit 58b8010
Show file tree
Hide file tree
Showing 121 changed files with 13,178 additions and 418 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ build: dep ## Build binaries
${OPTS} go build ${BUILD_OPTS} -o ./bin/skysocks-monitor ./cmd/skysocks-monitor
${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks-client ./cmd/skysocks-lite-client
${OPTS} go build ${BUILD_OPTS} -o ./bin/public-visor-monitor ./cmd/public-visor-monitor
${OPTS} go build ${BUILD_OPTS} -o ./bin/uptime-tracker ./cmd/uptime-tracker
# yarn --cwd ./pkg/node-visualizer/web build
# rm -rf ./pkg/node-visualizer/api/build/static
# mv ./pkg/node-visualizer/web/build/* ./pkg/node-visualizer/api/build
Expand All @@ -95,6 +96,7 @@ build-deploy: ## Build for deployment Docker images
${DOCKER_OPTS} go build ${BUILD_OPTS_DEPLOY} -mod=vendor -o /release/skysocks-monitor ./cmd/skysocks-monitor
${DOCKER_OPTS} go build ${BUILD_OPTS_DEPLOY} -mod=vendor -o /release/skysocks-client ./cmd/skysocks-lite-client
${DOCKER_OPTS} go build ${BUILD_OPTS_DEPLOY} -mod=vendor -o ./release/public-visor-monitor ./cmd/public-visor-monitor
${DOCKER_OPTS} go build ${BUILD_OPTS_DEPLOY} -mod=vendor -o /release/uptime-tracker ./cmd/uptime-tracker

build-race: dep ## Build binaries
${OPTS} go build ${BUILD_OPTS} -race -o ./bin/route-finder ./cmd/route-finder
Expand All @@ -113,6 +115,7 @@ build-race: dep ## Build binaries
${OPTS} go build ${BUILD_OPTS} -race -o ./bin/skysocks-monitor ./cmd/skysocks-monitor
${OPTS} go build ${BUILD_OPTS} -race -o ./bin/skysocks-client ./cmd/skysocks-lite-client
${OPTS} go build ${BUILD_OPTS} -race -o ./bin/public-visor-monitor ./cmd/public-visor-monitor
${OPTS} go build ${BUILD_OPTS} -race -o ./bin/uptime-tracker ./cmd/uptime-tracker

install: ## Install route-finder, transport-discovery, address-resolver, sw-env, keys-gen, network-monitor, node-visualizer
${OPTS} go install ${BUILD_OPTS} \
Expand All @@ -122,6 +125,7 @@ install: ## Install route-finder, transport-discovery, address-resolver, sw-env,
./cmd/sw-env \
./cmd/keys-gen \
./cmd/network-monitor \
./cmd/uptime-tracker \
./cmd/node-visualizer

clean: ## Clean compiled binaries
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Setup Node (SN)
- Service Discovery (SD)
- Address Resolver (AR)
- Uptime Tracker (UT)

## Running the services locally

Expand Down Expand Up @@ -71,3 +72,4 @@ Check the [docs](docs/Deployments.md) for more documentation on the deployments.
- [Dmsg Discovery](https://github.com/skycoin/dmsg/blob/develop/cmd/dmsg-discovery/README.md)
- [Dmsg Server](https://github.com/skycoin/dmsg/blob/develop/cmd/dmsg-server/README.md)
- [Service Discovery](https://github.com/skycoin/skycoin-service-discovery/blob/master/README.md#http-api)
- [Uptime Tracker](cmd/uptime-tracker/README.md)
24 changes: 13 additions & 11 deletions cmd/route-finder/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ import (
)

var (
addr string
metricsAddr string
pgHost string
pgPort string
logLvl string
tag string
testing bool
dmsgDisc string
sk cipher.SecKey
dmsgPort uint16
addr string
metricsAddr string
pgHost string
pgPort string
logLvl string
tag string
testing bool
dmsgDisc string
sk cipher.SecKey
dmsgPort uint16
pgMaxOpenConn int
)

func init() {
RootCmd.Flags().StringVarP(&addr, "addr", "a", ":9092", "address to bind to\033[0m")
RootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to\033[0m")
RootCmd.Flags().StringVar(&pgHost, "pg-host", "localhost", "host of postgres\033[0m")
RootCmd.Flags().StringVar(&pgPort, "pg-port", "5432", "port of postgres\033[0m")
RootCmd.Flags().IntVar(&pgMaxOpenConn, "pg-max-open-conn", 60, "maximum open connection of db")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
RootCmd.Flags().StringVar(&tag, "tag", "route_finder", "logging tag\033[0m")
RootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
Expand Down Expand Up @@ -99,7 +101,7 @@ PG_USER="postgres" PG_DATABASE="rf" PG_PASSWORD="" route-finder --addr ":9092"
pgPassword,
pgDatabase)

gormDB, err = pg.Init(dsn)
gormDB, err = pg.Init(dsn, pgMaxOpenConn)
if err != nil {
logger.Fatalf("Failed to connect to database %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/transport-discovery/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
testEnvironment bool
sk cipher.SecKey
dmsgPort uint16
pgMaxOpenConn int
)

func init() {
Expand All @@ -60,6 +61,7 @@ func init() {
RootCmd.Flags().IntVar(&redisPoolSize, "redis-pool-size", 10, "redis connection pool size\033[0m")
RootCmd.Flags().StringVar(&pgHost, "pg-host", "localhost", "host of postgres\033[0m")
RootCmd.Flags().StringVar(&pgPort, "pg-port", "5432", "port of postgres\033[0m")
RootCmd.Flags().IntVar(&pgMaxOpenConn, "pg-max-open-conn", 60, "maximum open connection of db")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
RootCmd.Flags().StringVar(&tag, "tag", "transport_discovery", "logging tag\033[0m")
RootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
Expand Down Expand Up @@ -139,7 +141,7 @@ PG_USER="postgres" PG_DATABASE="tpd" PG_PASSWORD="" transport-discovery --sk $(t
pgPassword,
pgDatabase)

gormDB, err = pg.Init(dsn)
gormDB, err = pg.Init(dsn, pgMaxOpenConn)
if err != nil {
logger.Fatalf("Failed to connect to database %v", err)
}
Expand Down
66 changes: 66 additions & 0 deletions cmd/uptime-tracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Uptime Tracker

## Purpose

Uptime tracker is used to track uptime of all the visors in the network.
We define uptime as a total amount of seconds which visor had been online within
a time interval.

## Algorithm
Visors perform a request to the uptime tracker each second. So, on each visor request
we simply increment number of seconds it's been online. Uptimes are distributed by month
and year. This means that for each visor we have a key in Redis hash set which consists
of year and month. And we increment uptime value associated with that key.

## API

### GET `/v4/update`
Increments visors uptime

Required headers:
- `SW-Public` - visor's public key;
- `SW-Sig` - request body signature;
- `SW-Nonce` - security nonce.

### GET `/visors`
Gets lat and longs of all the visors.

### GET `/uptimes[?visors=pk1,pk2&month=1&year=2020]`
Gets uptimes for given visors for the specified month and year which is rate limited.

Query parameters:
- `visors` - list of visors' pub keys to get uptimes for. Pub keys are comma separated list. May be omitted, in this case uptimes for all the known visors will be returned;
- `month` - month to request uptimes for. If either month or year are omitted, uptimes will be fetched for the current year and month;
- `year` - year to request uptimes for. If either month or year are omitted, uptimes will be fetched for the current year and month.

### GET `/uptime/{pk}[?month=1&year=2020]`
Gets uptime for given visor for the specified month and year which is not rate limited.

Query parameters:
- `month` - month to request uptimes for. If either month or year are omitted, uptimes will be fetched for the current year and month;
- `year` - year to request uptimes for. If either month or year are omitted, uptimes will be fetched for the current year and month.

### GET `/health`
Gets the health info of the service. e.g.
```
{
"build_info": {
"version": "v1.0.1-267-ge1617c5b",
"commit": "e1617c5b0121182cfd2b610dc518e4753e56440e",
"date": "2022-10-25T11:01:52Z"
},
"started_at": "2022-10-25T11:10:45.152629597Z"
}
```

### GET `/dashboard`
Gets a uptime tracker bar graph.

### GET `/security/nonces/{pk}`
Gets the nonce for a particular PK. Used by the nonce store.

## Private API
There is only one endpoint on port :9086. :9086 is the default port for the httpserver and can be changed with the flag -p.

### GET `/visor-ips`
Gets all the IP's of the registered visors.
Loading

0 comments on commit 58b8010

Please sign in to comment.