Skip to content

Commit

Permalink
Merge pull request #16486 from lenguyenthanh/expose-kamon-prometheus-…
Browse files Browse the repository at this point in the history
…manually

Expose kamon's prometheus metrics manually
  • Loading branch information
ornicar authored Nov 26, 2024
2 parents ba06a50 + d8cf11f commit 4853a7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ final class Main(
env.security.lilaCookie.withSession(remember = true): s =>
s + ("theme" -> "ic") + ("pieceSet" -> "icpieces")

def prometheusMetrics(key: String) = Action:
if key == env.web.config.prometheusKey
then kamon.prometheus.PrometheusReporter.latestScrapeData().fold(NotFound("No metrics found"))(Ok(_))
else NotFound("Invalid prometheus key")

def legacyQaQuestion(id: Int, _slug: String) = Open:
MovedPermanently:
StaticContent.legacyQaQuestion(id)
Expand Down
1 change: 1 addition & 0 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ kamon {
}
}
prometheus {
lilaKey = ""
buckets {
default-buckets = [10, 100, 1000, 10000, 100000]
time-buckets = [0.01, 0.05, 0.1, 0.5, 1, 5, 10]
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ POST /dev/cli controllers.Dev.cliPost
GET /dev/settings controllers.Dev.settings
POST /dev/settings/:id controllers.Dev.settingsPost(id)

GET /prometheus-metrics/:key controllers.Main.prometheusMetrics(key: String)
POST /dev/socket-test controllers.Dev.socketTestResult

# Push
Expand Down
2 changes: 2 additions & 0 deletions modules/web/src/main/WebConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final class WebConfig(
val apiToken: Secret,
val influxEventEndpoint: String,
val influxEventEnv: String,
val prometheusKey: String,
val pagerDuty: WebConfig.PagerDuty
)

Expand All @@ -32,6 +33,7 @@ object WebConfig:
c.get[Secret]("api.token"),
c.get[String]("api.influx_event.endpoint"),
c.get[String]("api.influx_event.env"),
c.get[String]("kamon.prometheus.lilaKey"),
new PagerDuty(
c.get[String]("pagerDuty.serviceId"),
c.get[Secret]("pagerDuty.apiKey")
Expand Down

0 comments on commit 4853a7c

Please sign in to comment.