Skip to content

Commit

Permalink
make prometheus optional (#19)
Browse files Browse the repository at this point in the history
* made stat collection and reporting optional
* minor package upgrades, bugfixes, and improvements
  • Loading branch information
sawall authored Mar 8, 2021
1 parent a1b24a2 commit 4f074c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ JITSI_TOKEN_KID=<key identifier for conference asap jwts>
JITSI_TOKEN_ISS=<issuer for conference asap jwts>
JITSI_TOKEN_AUD=<audience for conference asap jwts>
JITSI_CONFERENCE_HOST=<conference hosting service i.e. https://meet.jit.si>
HTTP_PORT=<port to run HTTP, default is 8080>
STATS_PORT<port to serve Prometheus stats, default is to prevent stats>
```

Note that `JITSI_TOKEN_SIGNING_KEY` is a dataurl that contains a
Expand Down
2 changes: 1 addition & 1 deletion build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -o pipefail
main() {
rm -f ./main
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main ./cmd/api/
docker build -t jitsi/slack-integration:$TAG .
docker build -t jitsi/jitsi-slack:$TAG .
}

main $@
28 changes: 22 additions & 6 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"time"

"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -37,7 +38,8 @@ type appCfg struct {
ServerCfgTable string `env:"SERVER_CFG_TABLE,required"`
DynamoRegion string `env:"DYNAMO_REGION,required"`
// application configuration
HTTPPort string `env:"HTTP_PORT" envDefault:"8080"`
HTTPPort string `env:"HTTP_PORT" envDefault:"8080"`
StatsPort string `env:"STATS_PORT" envDefault:"0"`
}

var (
Expand Down Expand Up @@ -150,6 +152,18 @@ func main() {
slackOAuth := stats.WrapHTTPHandler("slackOAuth", chain.ThenFunc(oauthHandler.Auth))
slackEvent := stats.WrapHTTPHandler("slackEvent", chain.ThenFunc(evHandle.Handle))

// wrap metrics collection and publish endpoint
statsPort, err := strconv.ParseInt(app.StatsPort, 10, 16)
if err != nil || statsPort > 65535 || statsPort < 0 {
log.Fatal().Err(err).Msg("bad port for stats server")
}
if statsPort > 0 {
slashJitsi = stats.WrapHTTPHandler("slashJitsi", slashJitsi)
slackOAuth = stats.WrapHTTPHandler("slackOAuth", slackOAuth)
slackEvent = stats.WrapHTTPHandler("slackEvent", slackEvent)
http.Handle("/metrics", promhttp.Handler())
}

// Add routes and wrapped handlers to mux.
handler.Handle("/slash/jitsi", slashJitsi) // slash command handler
handler.Handle("/slack/auth", slackOAuth) // handles "Add to Slack"
Expand All @@ -171,11 +185,13 @@ func main() {
log.Fatal().Err(err).Msg("shutting server down")
}()

// start stats server
go func() {
log.Info().Msg("stats listening on :2112")
log.Fatal().Err(http.ListenAndServe(":2112", nil)).Msg("shutting stat server down")
}()
// Start stats server
if statsPort > 0 {
go func() {
log.Info().Msgf("stats listening on :%s", app.StatsPort)
log.Fatal().Err(http.ListenAndServe(":"+app.StatsPort, nil)).Msg("shutting stat server down")
}()
}
<-stop
log.Info().Msg("shutting server down")
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
Expand Down

0 comments on commit 4f074c5

Please sign in to comment.