Skip to content

Commit

Permalink
fix #2039, fix #2040, fix #2041, fix #2042, fix #2043
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Dec 11, 2024
1 parent e8b60b6 commit f353392
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions otoroshi/app/api/api.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package otoroshi.api

import akka.http.scaladsl.util.FastFuture
import akka.stream.scaladsl.{Framing, Source}
import akka.util.ByteString
import org.apache.commons.lang3.math.NumberUtils
import org.joda.time.DateTime
import otoroshi.actions.{ApiAction, ApiActionContext}
import otoroshi.auth.AuthModuleConfig
import otoroshi.controllers.HealthController
import otoroshi.env.Env
import otoroshi.events.{AdminApiEvent, Alerts, Audit}
import otoroshi.jobs.updates.SoftwareUpdatesJobs
import otoroshi.models._
import otoroshi.next.models.{NgRoute, NgRouteComposition, StoredNgBackend}
import otoroshi.script.Script
Expand Down Expand Up @@ -870,6 +873,8 @@ class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(impli

private implicit val mat = env.otoroshiMaterializer

private lazy val commitVersion = Option(System.getenv("COMMIT_ID")).getOrElse(env.otoroshiVersion)

private def filterPrefix: Option[String] = "filter.".some

private def adminApiEvent(
Expand Down Expand Up @@ -1456,6 +1461,27 @@ class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(impli
}
}

// GET /apis/health
def health() = ApiAction.async {
HealthController.fetchHealth().map {
case Left(payload) => ServiceUnavailable(payload)
case Right(payload) => Ok(payload)
}
}

// GET /apis/metrics
def metrics() = ApiAction { ctx =>
val format = ctx.request.getQueryString("format")
val filter = ctx.request.getQueryString("filter")
val acceptsJson = ctx.request.accepts("application/json")
val acceptsProm = ctx.request.accepts("application/prometheus")
if (env.metricsEnabled) {
HealthController.fetchMetrics(format, acceptsJson, acceptsProm, filter)
} else {
NotFound(Json.obj("error" -> "metrics not enabled"))
}
}

// GET /apis/entities
def entities() = ApiAction { ctx =>
if (ctx.request.getQueryString("schema").contains("false")) {
Expand Down
8 changes: 8 additions & 0 deletions otoroshi/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GET /robots.txt otoroshi.controlle
GET /robot.txt otoroshi.controllers.BackOfficeController.robotTxt
GET /error otoroshi.controllers.BackOfficeController.error(message: Option[String])
GET /auth0error otoroshi.controllers.AuthController.auth0error(error: Option[String], error_description: Option[String])

GET /health otoroshi.controllers.HealthController.health()
GET /metrics otoroshi.controllers.HealthController.processMetrics()
GET /live otoroshi.controllers.HealthController.live()
Expand Down Expand Up @@ -605,6 +606,13 @@ DELETE /api/admins/webauthn/:username/:id otoroshi.controlle
GET /api/openapi.json otoroshi.controllers.SwaggerController.openapi()
GET /api/openapi/ui otoroshi.controllers.SwaggerController.openapiUi()

## New admin API
GET /apis/cluster/node/infos otoroshi.controllers.adminapi.InfosApiController.infos()
GET /apis/cluster/node/version otoroshi.controllers.adminapi.InfosApiController.version()
GET /apis/cluster/node/health otoroshi.api.GenericApiController.health()
GET /apis/cluster/node/metrics otoroshi.api.GenericApiController.metrics()
GET /apis/cluster otoroshi.controllers.adminapi.ClusterController.getClusterMembers()

# generic apis
POST /apis/:group/:version/:entity/_bulk otoroshi.api.GenericApiController.bulkCreate(group, version, entity)
PUT /apis/:group/:version/:entity/_bulk otoroshi.api.GenericApiController.bulkUpdate(group, version, entity)
Expand Down

0 comments on commit f353392

Please sign in to comment.