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

Fixes #18482: Move health check API in /system/ #3333

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/system/healthcheck?prettify=true'
6 changes: 2 additions & 4 deletions webapp/sources/api-doc/openapi.src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ tags:
description: Nodes management
- name: Inventories
description: Inventory processing service
- name: "Health check"
description: Internal health view
- name: Parameters
description: Global parameters
- name: Settings
Expand Down Expand Up @@ -93,8 +91,6 @@ tags:

Manage web interface customization.
paths:
"/healthcheck":
$ref: paths/healthcheck/all.yml
"/createnodes":
$ref: paths/create-node/all.yml
"/usermanagement/users":
Expand Down Expand Up @@ -153,6 +149,8 @@ paths:
$ref: paths/system/archives-restore.yml
"/system/archives/{archiveKind}/zip/{commitId}":
$ref: paths/system/archives-zip.yml
"/system/healthcheck":
$ref: paths/system/healthcheck.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to remove the "Health check" tag from the openapi.src.yml and healthcheck.yml files

"/settings":
$ref: paths/settings/list.yml
"/settings/{settingId}":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: CC-BY-SA-2.0
# SPDX-FileCopyrightText: 2013-2020 Normation SAS
get:
summary: Get all checks status
summary: Get healthcheck
description: Run and get the result of all checks
operationId: getHealthcheckResult
responses:
Expand Down Expand Up @@ -33,8 +33,8 @@ get:
$ref: ../../components/schemas/check.yml

tags:
- "Health check"
- System
x-code-samples:
- lang: curl
source:
$ref: ../../code_samples/curl/healthcheck/all.sh
$ref: ../../code_samples/curl/system/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@ object SystemApi extends ApiModuleProvider[SystemApi] {
val (action, path) = GET / "system" / "archives" / "full" / "zip" / "{commitId}"
}

// Health check endpoints

// This endpoint run all checks to return the result
final case object GetHealthcheckResult extends SystemApi with ZeroParam with StartsAtVersion13 with SortIndex { val z = implicitly[Line].value
val description = "Result of a health check run"
val (action, path) = GET / "system" / "healthcheck"
}

def endpoints = ca.mrvisser.sealerate.values[SystemApi].toList.sortBy( _.z )
}

Expand Down Expand Up @@ -730,19 +738,6 @@ object UserApi extends ApiModuleProvider[UserApi] {
def endpoints = ca.mrvisser.sealerate.values[UserApi].toList.sortBy( _.z )
}

sealed trait HealthcheckApi extends EndpointSchema with GeneralApi with SortIndex
object HealthcheckApi extends ApiModuleProvider[HealthcheckApi] {

// This endpoint run all checks to return the result
final case object GetHealthcheckResult extends HealthcheckApi with ZeroParam with StartsAtVersion12 with SortIndex { val z = implicitly[Line].value
val description = "Result of a health check run"
val (action, path) = GET / "healthcheck"
}

def endpoints = ca.mrvisser.sealerate.values[HealthcheckApi].toList.sortBy( _.z )

}

/*
* All API.
*/
Expand All @@ -760,7 +755,6 @@ object AllApi {
RuleApi.endpoints :::
InventoryApi.endpoints :::
InfoApi.endpoints :::
HealthcheckApi.endpoints :::
// UserApi is not declared here, it will be contributed by plugin
Nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final case object OnlyAdmin extends AuthorizationApiMapping {
SystemApi.ArchivesFullList.x :: SystemApi.ArchivesGroupsList.x :: SystemApi.ArchivesRulesList.x ::
SystemApi.GetAllZipArchive.x :: SystemApi.GetDirectivesZipArchive.x :: SystemApi.GetGroupsZipArchive.x ::
SystemApi.GetRulesZipArchive.x :: SystemApi.Info.x :: SystemApi.Status.x :: SystemApi.ArchivesParametersList.x ::
SystemApi.GetParametersZipArchive.x :: HealthcheckApi.GetHealthcheckResult.x :: Nil
SystemApi.GetParametersZipArchive.x :: SystemApi.GetHealthcheckResult.x :: Nil
case Administration.Write => SettingsApi.ModifySettings.x :: SettingsApi.ModifySetting.x :: SystemApi.endpoints.map(_.x)
case Administration.Edit => SettingsApi.ModifySettings.x :: SettingsApi.ModifySetting.x :: SystemApi.endpoints.map(_.x)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ import com.normation.rudder.rest.RestUtils.toJsonResponse
import com.normation.rudder.rest.ApiPath
import com.normation.rudder.rest.ApiVersion
import com.normation.rudder.rest.AuthzToken
import com.normation.rudder.rest.RestDataSerializer
import com.normation.rudder.rest.RestExtractorService
import com.normation.rudder.rest.RestUtils
import com.normation.rudder.rest.{SystemApi => API}
import com.normation.rudder.services.user.PersonIdentService
import com.normation.rudder.services.ClearCacheService
import com.normation.rudder.services.healthcheck.HealthcheckNotificationService
import com.normation.rudder.services.healthcheck.HealthcheckService
import com.normation.rudder.services.system.DebugInfoScriptResult
import com.normation.rudder.services.system.DebugInfoService
import com.normation.utils.StringUuidGenerator
Expand All @@ -81,10 +84,14 @@ import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatterBuilder
import zio._
import com.normation.zio._
import com.normation.box._

import net.liftweb.json.JsonAST.JArray

class SystemApi(
restExtractorService : RestExtractorService
, apiv11service : SystemApiService11
, apiv13service : SystemApiService13
, rudderMajorVersion : String
, rudderFullVerion : String
, rudderBuildTimestamp : String
Expand Down Expand Up @@ -133,6 +140,7 @@ class SystemApi(
case API.GetRulesZipArchive => GetRulesZipArchive
case API.GetParametersZipArchive => GetParametersZipArchive
case API.GetAllZipArchive => GetAllZipArchive
case API.GetHealthcheckResult => GetHealthcheckResult
})
}

Expand Down Expand Up @@ -496,7 +504,40 @@ class SystemApi(
}
}

object GetHealthcheckResult extends LiftApiModule0 {
val schema = API.GetHealthcheckResult
val restExtractor = restExtractorService

def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = {
apiv13service.getHealthcheck(params)
}
}
}

class SystemApiService13(
healthcheckService : HealthcheckService
, hcNotifService : HealthcheckNotificationService
, serializer : RestDataSerializer
) extends Loggable {

def getHealthcheck(params: DefaultParams): LiftResponse = {
implicit val action = "getHealthcheckResult"
implicit val prettify = params.prettify

val result = for {
checks <- healthcheckService.runAll
_ <- hcNotifService.updateCacheFromExt(checks)
} yield {
checks.map(serializer.serializeHealthcheckResult)
}
result.toBox match {
case Full(json) =>
RestUtils.toJsonResponse(None, JArray(json))
case eb: EmptyBox =>
val message = (eb ?~ s"Error when trying to run healthcheck").messageChain
RestUtils.toJsonError(None, message)("getHealthcheck",true)
}
}
}

class SystemApiService11(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ import com.normation.rudder.repository._
import com.normation.rudder.rest.lift.LiftApiProcessingLogger
import com.normation.rudder.rest.lift.LiftHandler
import com.normation.rudder.rest.lift.SystemApiService11
import com.normation.rudder.rest.lift.SystemApiService13
import com.normation.rudder.rest.v1.RestStatus
import com.normation.rudder.rest.v1.RestTechniqueReload
import com.normation.rudder.services.policies.TestNodeConfiguration
import com.normation.rudder.services.user.PersonIdentService
import com.normation.rudder.services.ClearCacheService
import com.normation.rudder.services.healthcheck.CheckCoreNumber
import com.normation.rudder.services.healthcheck.CheckFileDescriptorLimit
import com.normation.rudder.services.healthcheck.CheckFreeSpace
import com.normation.rudder.services.healthcheck.HealthcheckNotificationService
import com.normation.rudder.services.healthcheck.HealthcheckService
import com.normation.rudder.services.nodes.NodeInfoServiceCachedImpl
import com.normation.rudder.services.policies.TestNodeConfiguration
import com.normation.rudder.services.system.DebugInfoScriptResult
import com.normation.rudder.services.system.DebugInfoService
import com.normation.rudder.services.user.PersonIdentService
import com.normation.utils.StringUuidGenerator
import net.liftweb.common.Box
import net.liftweb.common.EmptyBox
Expand All @@ -78,6 +85,7 @@ import org.eclipse.jgit.lib.PersonIdent
import org.joda.time.DateTime
import org.specs2.matcher.MatchResult
import zio._
import zio.duration.durationInt
import zio.syntax._

/*
Expand Down Expand Up @@ -217,6 +225,25 @@ object RestTestSetUp {
val fakeScriptLauncher = new DebugInfoService {
override def launch() = DebugInfoScriptResult("test", new Array[Byte](42)).succeed
}
val nodeInfoService = new NodeInfoServiceCachedImpl(
null
, null
, null
, null
, null
, null
, null
, null
)

val fakeHealthcheckService = new HealthcheckService(
List(
CheckCoreNumber
, CheckFreeSpace
, new CheckFileDescriptorLimit(nodeInfoService) //should I create all services to get this one ?
)
)
val fakeHcNotifService = new HealthcheckNotificationService(fakeHealthcheckService, 5.minute)

val apiService11 = new SystemApiService11(
fakeUpdatePTLibService
Expand All @@ -230,15 +257,21 @@ object RestTestSetUp {
, fakeRepo
)

val systemApi = new com.normation.rudder.rest.lift.SystemApi(restExtractorService, apiService11, "5.0", "5.0.0", "some time")
val apiService13 = new SystemApiService13(
fakeHealthcheckService
, fakeHcNotifService
, restDataSerializer
)

val systemApi = new com.normation.rudder.rest.lift.SystemApi(restExtractorService, apiService11, apiService13,"5.0", "5.0.0", "some time")
val authzToken = AuthzToken(EventActor("fakeToken"))
val systemStatusPath = "api" + systemApi.Status.schema.path

val ApiVersions = ApiVersion(11 , false) :: Nil

val rudderApi = {
//append to list all new format api to test it
val modules = List(new com.normation.rudder.rest.lift.SystemApi(restExtractorService, apiService11, "5.0", "5.0.0", "some time"))
val modules = List(new com.normation.rudder.rest.lift.SystemApi(restExtractorService, apiService11, apiService13, "5.0", "5.0.0", "some time"))
val api = new LiftHandler(apiDispatcher, ApiVersions, new AclApiAuthorization(LiftApiProcessingLogger, userService, () => apiAuthorizationLevelService.aclEnabled), None)
modules.foreach { module =>
api.addModules(module.getLiftEndpoints())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import JsonDecoder exposing (decodeGetRoleApiResult)

getUrl: DataTypes.Model -> String -> String
getUrl m url =
m.contextPath ++ "/secure/api" ++ url
m.contextPath ++ "/secure/api/system" ++ url

getHealthCheck : Model -> Cmd Msg
getHealthCheck model =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,12 @@ object RudderConfig extends Loggable {
, gitRepo
)

val systemApiService13 = new SystemApiService13(
healthcheckService
, healthcheckNotificationService
, restDataSerializer
)

private[this] val complianceAPIService = new ComplianceAPIService(
roRuleRepository
, nodeInfoService
Expand Down Expand Up @@ -1151,9 +1157,9 @@ object RudderConfig extends Loggable {
, new SettingsApi(restExtractorService, configService, asyncDeploymentAgent, stringUuidGenerator, policyServerManagementService, nodeInfoService)
, new TechniqueApi(restExtractorService, techniqueApiService6)
, new RuleApi(restExtractorService, ruleApiService2, ruleApiService6, stringUuidGenerator)
, new SystemApi(restExtractorService, systemApiService11, rudderMajorVersion, rudderFullVersion, builtTimestamp)
, new SystemApi(restExtractorService,systemApiService11, systemApiService13, rudderMajorVersion, rudderFullVersion, builtTimestamp)
, new InventoryApi(restExtractorService, inventoryProcessor, inventoryWatcher)
, new HealthcheckApi(restExtractorService, restDataSerializer, healthcheckService, healthcheckNotificationService)
// , new HealthcheckApi(restExtractorService, restDataSerializer, healthcheckService, healthcheckNotificationService)
// info api must be resolved latter, because else it misses plugin apis !
)

Expand Down