Skip to content

Commit

Permalink
add --status-addr flag for customizing status endpoints binding address
Browse files Browse the repository at this point in the history
  • Loading branch information
Qingping Hou committed Mar 3, 2020
1 parent c40ed4f commit 5ceb714
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ build-img:
docker build --rm -t objinsync:latest .

run:
DEBUG=1 AWS_REGION=us-east-2 go run main.go pull s3://cplat-dev-airflow-airflow-code/airflow_home/dags ./dags
DEBUG=1 AWS_REGION=us-east-2 go run main.go pull s3://airflow_bucket/airflow_home/dags ./dags
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@ Usage
-----

```bash
objinsync pull s3://bucket/objectpath ./localdir
objinsync pull s3://bucket/keyprefix ./localdir
```

When running in daemon mode (without `--once` flag), a healthcheck endpoint is
served at `:8087/health` and a prometheus metrics endponit is served at
`:8087/metrics`. You can use `--status-addr` to override the binding address.

Objinsync also comes with builtin Sentry integraiton. To enable it, set the
`SENTRY_DSN` environment variable.


Installation
------------

Simply download the prebuilt binary from [release page](https://github.com/scribd/objinsync/releases) or use `go get` command:

```bash
go get github.com/scribd/objinsync
```


Expand Down
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
var (
RunOnce bool
InitialRunFinished atomic.Bool
HealthCheckAddr = ":8087"
StatusAddr = ":8087"

metricsSyncTime = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "objinsync",
Expand All @@ -46,7 +46,7 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
func serveHealthCheckEndpoints() {
http.HandleFunc("/health", healthCheckHandler)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(HealthCheckAddr, nil))
log.Fatal(http.ListenAndServe(StatusAddr, nil))
}

func main() {
Expand Down Expand Up @@ -77,7 +77,7 @@ func main() {
}()
}
} else {
l.Warnf("SENTRY_DSN not found, skipped Sentry setup.")
l.Infof("SENTRY_DSN not found, sentry integration disabled.")
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -108,7 +108,8 @@ func main() {
if errMsg != "" {
sentry.CaptureMessage(errMsg)
sentry.Flush(time.Second * 5)
l.Fatalf(errMsg)
fmt.Println("ERROR: failed to pull objects from remote store:", errMsg)
os.Exit(1)
}

syncTime := time.Now().Sub(start)
Expand All @@ -122,7 +123,7 @@ func main() {
} else {
InitialRunFinished.Store(false)
go serveHealthCheckEndpoints()
l.Infof("Serving health check endpoints at: %s.", HealthCheckAddr)
l.Infof("Serving health check endpoints at: %s.", StatusAddr)
l.Infof("Pulling from %s to %s every %v...", remoteUri, localDir, interval)
ticker := time.NewTicker(interval)
pull()
Expand All @@ -137,6 +138,7 @@ func main() {
},
}
pullCmd.PersistentFlags().BoolVarP(&RunOnce, "once", "o", false, "run action once and then exit.")
pullCmd.PersistentFlags().StringVarP(&StatusAddr, "status-addr", "s", ":8087", "binding address for status endpoint.")

rootCmd.AddCommand(pullCmd)
rootCmd.Execute()
Expand Down

0 comments on commit 5ceb714

Please sign in to comment.