Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /quitquitquit handler to otel-col #35

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions otel-collector/cmd/otel-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package main

import (
"context"
"log"
"net/http"
"os"
"os/exec"
)
Expand All @@ -18,11 +20,30 @@
log.Fatalf("error checking config.yaml: %v", err)
}

log.Printf("config.yaml found at %s", configPath)

ctx, cancel := context.WithCancel(context.Background())

// run /otel-collector binary with --config config.yaml
cmd := exec.Command("otelcol-contrib", "--config", configPath)
cmd := exec.CommandContext(ctx, "otelcol-contrib", "--config", configPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {

// Start the command but don't wait.
if err := cmd.Start(); err != nil {
log.Fatalf("failed to start otel-collector: %v", err)
}

// Start a server that serves /quitquitquit on port 31415
mux := http.NewServeMux()
srv := &http.Server{Addr: ":31415", Handler: mux}

Check failure on line 39 in otel-collector/cmd/otel-collector/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)
mux.HandleFunc("/quitquitquit", func(w http.ResponseWriter, r *http.Request) {
go srv.Shutdown(ctx)

Check failure on line 41 in otel-collector/cmd/otel-collector/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `srv.Shutdown` is not checked (errcheck)
cancel()
})
go srv.ListenAndServe()

Check failure on line 44 in otel-collector/cmd/otel-collector/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `srv.ListenAndServe` is not checked (errcheck)

if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
}
Loading