From 5ceb7147ea06e21827886341f50c5030f5a02950 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 2 Mar 2020 16:49:31 -0800 Subject: [PATCH] add --status-addr flag for customizing status endpoints binding address --- Makefile | 2 +- README.md | 19 ++++++++++++++++++- main.go | 12 +++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 981f1d7..1e36e04 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 8319686..c935959 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/main.go b/main.go index 466b0ac..6c70b85 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( var ( RunOnce bool InitialRunFinished atomic.Bool - HealthCheckAddr = ":8087" + StatusAddr = ":8087" metricsSyncTime = prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: "objinsync", @@ -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() { @@ -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{ @@ -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) @@ -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() @@ -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()