-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function for check psql connection (#10)
* feat: add function for check psql connection * fix: fix swift lint * tests: try fix tests. Bug with date format * test: try fix test for date format * refactor: refactor test and add extension * refactor: delete print * style: delete space * docs: add documentation * refactor: change date format * tests: refactor mock data * refactor: refactor functions, rename and add tls parameter * refactor: change function checkConnection for result * refactor: change struct response * docs: change documentation * refactor: rename file * docs: add license documentation * refactor: refactor method for get psql connection * refactor: add test for func * refactor: refactotr test * refactor: rename func * refactor: add field to struct * refactor: rename func * refactor: delete not use init * refactor: refactor service * refactor: refactor funcs * docs: change documentation * tests: fix tests * tests: refactor tests * refactor: change funcs * tests: refactor tests * refactor: change function
- Loading branch information
1 parent
8a32cba
commit 4000843
Showing
19 changed files
with
613 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// FS App Health Checks | ||
// Copyright (C) 2024 FREEDOM SPACE, LLC | ||
|
||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// | ||
// ChecksProtocol.swift | ||
// | ||
// | ||
// Created by Mykola Buhaiov on 06.02.2024. | ||
// | ||
|
||
import Vapor | ||
|
||
/// Groups func for get health check | ||
public protocol ChecksProtocol { | ||
/// Check with setup options | ||
/// - Parameter options: array of `MeasurementType` | ||
/// - Returns: dictionary `[String: HealthCheckItem]` | ||
func checkHealth(for options: [MeasurementType]) async -> [String: HealthCheckItem] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// FS App Health Checks | ||
// Copyright (C) 2024 FREEDOM SPACE, LLC | ||
|
||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// | ||
// ComponentName.swift | ||
// | ||
// | ||
// Created by Mykola Buhaiov on 29.01.2024. | ||
// | ||
|
||
import Vapor | ||
|
||
/// Human-readable name for the component | ||
public enum ComponentName: String { | ||
/// The Central Processing Unit (CPU) is the primary component of a computer that acts as its "control center." | ||
case cpu | ||
/// Memory, also known as random access memory (RAM), is a PC component that stores data while the computer runs | ||
case memory | ||
/// Redis is an open-source in-memory storage, used as a distributed, in-memory key–value database | ||
case redis | ||
/// PostgreSQL also known as Postgres, is a free and open-source relational database management system (RDBMS) emphasizing extensibility | ||
case postgresql | ||
/// MongoDB is a source-available, cross-platform, document-oriented database program. | ||
case mongo | ||
/// Distributed messaging system between server applications in real time | ||
case kafka | ||
/// Consul is a service networking solution to automate network configurations, discover services, and enable secure connectivity across any cloud or runtime. | ||
case consul | ||
/// gRPC is a modern open source high performance Remote Procedure Call (RPC) framework that can run in any environment. | ||
case grpc | ||
} | ||
|
||
extension ComponentName: Content {} | ||
|
||
extension ComponentName: CaseIterable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
Sources/AppHealthChecks/Models/HealthCheckItem+Equatable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// FS App Health Checks | ||
// Copyright (C) 2024 FREEDOM SPACE, LLC | ||
|
||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// | ||
// HealthCheckItem+Equatable.swift | ||
// | ||
// | ||
// Created by Mykola Buhaiov on 06.02.2024. | ||
// | ||
|
||
import Vapor | ||
|
||
/// Equatable protocol implementation for `HealthCheckItem` struct. | ||
/// | ||
/// Two `HealthCheckItem` structs are considered equal if they have the same: | ||
/// | ||
/// - componentId | ||
/// - componentType | ||
/// - observedValue | ||
/// - observedUnit | ||
/// - status | ||
/// - affectedEndpoints | ||
/// - time | ||
/// - output | ||
/// - links | ||
/// - node | ||
extension HealthCheckItem: Equatable { | ||
/// Conform `HealthCheckItem` to `Equatable` protocol | ||
/// - Parameters: | ||
/// - lhs: `HealthCheckItem` | ||
/// - rhs: `HealthCheckItem` | ||
/// - Returns: `Bool` | ||
public static func == (lhs: HealthCheckItem, rhs: HealthCheckItem) -> Bool { | ||
return lhs.componentId == rhs.componentId && | ||
lhs.componentType == rhs.componentType && | ||
lhs.observedValue == rhs.observedValue && | ||
lhs.observedUnit == rhs.observedUnit && | ||
lhs.status == rhs.status && | ||
lhs.affectedEndpoints == rhs.affectedEndpoints && | ||
lhs.time == rhs.time && | ||
lhs.output == rhs.output && | ||
lhs.links == rhs.links && | ||
lhs.node == rhs.node | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/AppHealthChecks/PostgresHealthChecks/PostgresChecksProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// FS App Health Checks | ||
// Copyright (C) 2024 FREEDOM SPACE, LLC | ||
|
||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// | ||
// PostgresChecksProtocol.swift | ||
// | ||
// | ||
// Created by Mykola Buhaiov on 31.01.2024. | ||
// | ||
|
||
import Vapor | ||
|
||
/// Groups func for get psql health check | ||
public protocol PostgresChecksProtocol { | ||
/// Get Postgresql version | ||
/// - Returns: `HealthCheckItem` | ||
func connection() async -> HealthCheckItem | ||
|
||
/// Get response time from postgresql | ||
/// - Returns: `HealthCheckItem` | ||
func getResponseTime() async -> HealthCheckItem | ||
|
||
/// Get version from postgresql | ||
/// - Returns: `String` | ||
func getVersion() async -> String | ||
} |
Oops, something went wrong.