Skip to content

Commit

Permalink
[cloudflare] Add health check to mock service (#11313)
Browse files Browse the repository at this point in the history
Adds a health check to the mock service used in the `logpull` system
test. This will let docker check when the mock service is ready and
avoid starting the test too early.

The system test `interval` setting is lowered from `1h` to `2m`, which
may also help avoid test failures.
  • Loading branch information
chrisberkhout authored Oct 4, 2024
1 parent 94c228d commit 7f6e863
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/cloudflare/_dev/deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ services:
- ./logpull-mock-service:/app
ports:
- "3000:3000"
healthcheck:
test: "wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1"
interval: 10s
timeout: 5s
command: ["go", "run", "main.go"]
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
// Ref: https://developers.cloudflare.com/logs/logpull/requesting-logs/
func main() {
router := mux.NewRouter()
router.Path("/health").HandlerFunc(healthHandler).Methods("GET").Schemes("http")
router.Path("/client/v4/zones/aaabbbccc/logs/received").HandlerFunc(logpullHandler).Methods("GET").Schemes("http")

port := 3000
Expand All @@ -41,6 +42,10 @@ func main() {
http.ListenAndServe(fmt.Sprintf(":%d", port), h)
}

func healthHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK")
}

func logpullHandler(w http.ResponseWriter, r *http.Request) {
// Set response headers to indicate rolling response
w.Header().Set("Content-Type", "text/event-stream")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vars:
enable_request_tracer: true
data_stream:
vars:
interval: 1h
interval: 2m
preserve_original_event: true
auth_email: [email protected]
auth_key: xxxxxxxxxx
Expand Down

0 comments on commit 7f6e863

Please sign in to comment.