Skip to content

Commit 5ceb714

Browse files
author
Qingping Hou
committed
add --status-addr flag for customizing status endpoints binding address
1 parent c40ed4f commit 5ceb714

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ build-img:
55
docker build --rm -t objinsync:latest .
66

77
run:
8-
DEBUG=1 AWS_REGION=us-east-2 go run main.go pull s3://cplat-dev-airflow-airflow-code/airflow_home/dags ./dags
8+
DEBUG=1 AWS_REGION=us-east-2 go run main.go pull s3://airflow_bucket/airflow_home/dags ./dags

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ Usage
1212
-----
1313

1414
```bash
15-
objinsync pull s3://bucket/objectpath ./localdir
15+
objinsync pull s3://bucket/keyprefix ./localdir
16+
```
17+
18+
When running in daemon mode (without `--once` flag), a healthcheck endpoint is
19+
served at `:8087/health` and a prometheus metrics endponit is served at
20+
`:8087/metrics`. You can use `--status-addr` to override the binding address.
21+
22+
Objinsync also comes with builtin Sentry integraiton. To enable it, set the
23+
`SENTRY_DSN` environment variable.
24+
25+
26+
Installation
27+
------------
28+
29+
Simply download the prebuilt binary from [release page](https://github.com/scribd/objinsync/releases) or use `go get` command:
30+
31+
```bash
32+
go get github.com/scribd/objinsync
1633
```
1734

1835

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
var (
2222
RunOnce bool
2323
InitialRunFinished atomic.Bool
24-
HealthCheckAddr = ":8087"
24+
StatusAddr = ":8087"
2525

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

5252
func main() {
@@ -77,7 +77,7 @@ func main() {
7777
}()
7878
}
7979
} else {
80-
l.Warnf("SENTRY_DSN not found, skipped Sentry setup.")
80+
l.Infof("SENTRY_DSN not found, sentry integration disabled.")
8181
}
8282

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

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

141143
rootCmd.AddCommand(pullCmd)
142144
rootCmd.Execute()

0 commit comments

Comments
 (0)