From cb6c188e96f025606d6392bcda591ee51c6ba196 Mon Sep 17 00:00:00 2001 From: Dave Verwer Date: Wed, 15 Jan 2025 16:06:38 +0000 Subject: [PATCH 1/2] Added a very basic uptime check page. --- .../Controllers/UptimeCheckController.swift | 30 +++++++++++++++++++ Sources/App/Core/SiteURL.swift | 5 ++++ Sources/App/routes.swift | 4 +++ 3 files changed, 39 insertions(+) create mode 100644 Sources/App/Controllers/UptimeCheckController.swift diff --git a/Sources/App/Controllers/UptimeCheckController.swift b/Sources/App/Controllers/UptimeCheckController.swift new file mode 100644 index 000000000..33785a8bd --- /dev/null +++ b/Sources/App/Controllers/UptimeCheckController.swift @@ -0,0 +1,30 @@ +// Copyright Dave Verwer, Sven A. Schmidt, and other contributors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Fluent +import Plot +import Vapor + +enum UptimeCheckController { + + @Sendable + static func show(req: Request) async throws -> String { + // A package page query is a good test of whether the site is healthy. + let (_, _) = try await API.PackageController.GetRoute + .query(on: req.db, + owner: "SwiftPackageIndex", + repository: "SemanticVersion") + return "Success" + } +} diff --git a/Sources/App/Core/SiteURL.swift b/Sources/App/Core/SiteURL.swift index a70ad8323..c10c83838 100644 --- a/Sources/App/Core/SiteURL.swift +++ b/Sources/App/Core/SiteURL.swift @@ -134,6 +134,7 @@ enum SiteURL: Resourceable, Sendable { case stylesheets(String) case supporters case tryInPlayground + case uptimeCheck case validateSPIManifest var path: String { @@ -254,6 +255,9 @@ enum SiteURL: Resourceable, Sendable { case .tryInPlayground: return "try-in-a-playground" + case .uptimeCheck: + return "uptime-check" + case .validateSPIManifest: return "validate-spi-manifest" } @@ -276,6 +280,7 @@ enum SiteURL: Resourceable, Sendable { .siteMapStaticPages, .supporters, .tryInPlayground, + .uptimeCheck, .validateSPIManifest: return [.init(stringLiteral: path)] diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index aafa25a1d..aea7875ef 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -128,6 +128,10 @@ func routes(_ app: Application) throws { app.get(SiteURL.supporters.pathComponents, use: SupportersController.show).excludeFromOpenAPI() } + do { // Uptime check + app.get(SiteURL.uptimeCheck.pathComponents, use: UptimeCheckController.show).excludeFromOpenAPI() + } + do { // spi.yml validation page app.get(SiteURL.validateSPIManifest.pathComponents, use: ValidateSPIManifestController.show) .excludeFromOpenAPI() From 6e34490c000b31d94417cd1f117bf975aabab1cf Mon Sep 17 00:00:00 2001 From: Dave Verwer Date: Thu, 16 Jan 2025 10:52:09 +0000 Subject: [PATCH 2/2] Renamed uptime to health. --- ...eCheckController.swift => HealthCheckController.swift} | 2 +- Sources/App/Core/SiteURL.swift | 8 ++++---- Sources/App/routes.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename Sources/App/Controllers/{UptimeCheckController.swift => HealthCheckController.swift} (97%) diff --git a/Sources/App/Controllers/UptimeCheckController.swift b/Sources/App/Controllers/HealthCheckController.swift similarity index 97% rename from Sources/App/Controllers/UptimeCheckController.swift rename to Sources/App/Controllers/HealthCheckController.swift index 33785a8bd..218b4dc65 100644 --- a/Sources/App/Controllers/UptimeCheckController.swift +++ b/Sources/App/Controllers/HealthCheckController.swift @@ -16,7 +16,7 @@ import Fluent import Plot import Vapor -enum UptimeCheckController { +enum HealthCheckController { @Sendable static func show(req: Request) async throws -> String { diff --git a/Sources/App/Core/SiteURL.swift b/Sources/App/Core/SiteURL.swift index c10c83838..733d683c3 100644 --- a/Sources/App/Core/SiteURL.swift +++ b/Sources/App/Core/SiteURL.swift @@ -134,7 +134,7 @@ enum SiteURL: Resourceable, Sendable { case stylesheets(String) case supporters case tryInPlayground - case uptimeCheck + case healthCheck case validateSPIManifest var path: String { @@ -255,8 +255,8 @@ enum SiteURL: Resourceable, Sendable { case .tryInPlayground: return "try-in-a-playground" - case .uptimeCheck: - return "uptime-check" + case .healthCheck: + return "health-check" case .validateSPIManifest: return "validate-spi-manifest" @@ -280,7 +280,7 @@ enum SiteURL: Resourceable, Sendable { .siteMapStaticPages, .supporters, .tryInPlayground, - .uptimeCheck, + .healthCheck, .validateSPIManifest: return [.init(stringLiteral: path)] diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index aea7875ef..62266338a 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -129,7 +129,7 @@ func routes(_ app: Application) throws { } do { // Uptime check - app.get(SiteURL.uptimeCheck.pathComponents, use: UptimeCheckController.show).excludeFromOpenAPI() + app.get(SiteURL.healthCheck.pathComponents, use: HealthCheckController.show).excludeFromOpenAPI() } do { // spi.yml validation page