Unverified Commit 458eeb63 authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

Health check in Pokemon service (#1608)



Health check operation in Pokemon service

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent a2ccdf70
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ use aws.protocols#restJson1
service PokemonService {
    version: "2021-12-01",
    resources: [PokemonSpecies, Storage],
    operations: [GetServerStatistics, EmptyOperation, CapturePokemonOperation],
    operations: [GetServerStatistics, EmptyOperation, CapturePokemonOperation, HealthCheckOperation],
}

/// A Pokémon species forms the basis for at least one Pokémon.
@@ -241,6 +241,13 @@ structure EmptyOperationInput { }
@output
structure EmptyOperationOutput { }

/// Health check operation, to check the service is up
/// Not yet a deep check
@readonly
@http(uri: "/ping", method: "GET")
operation HealthCheckOperation {
}

@error("client")
@httpError(404)
structure ResourceNotFoundException {
+8 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ use aws.protocols#restJson1
service PokemonService {
    version: "2021-12-01",
    resources: [PokemonSpecies],
    operations: [GetServerStatistics, EmptyOperation],
    operations: [GetServerStatistics, EmptyOperation, HealthCheckOperation],
}

/// A Pokémon species forms the basis for at least one Pokémon.
@@ -123,6 +123,13 @@ structure EmptyOperationInput { }
@output
structure EmptyOperationOutput { }

/// Health check operation, to check the service is up
/// Not yet a deep check
@readonly
@http(uri: "/ping", method: "GET")
operation HealthCheckOperation {
}

@error("client")
@httpError(404)
structure ResourceNotFoundException {
+2 −0
Original line number Diff line number Diff line
@@ -47,4 +47,6 @@ async fn simple_integration_test() {

    let service_statistics_out = client().get_server_statistics().send().await.unwrap();
    assert_eq!(2, service_statistics_out.calls_count.unwrap());

    let _health_check = client().health_check_operation().send().await.unwrap();
}
+6 −2
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@ import threading
from libpokemon_service_server_sdk.error import \
    ResourceNotFoundException
from libpokemon_service_server_sdk.input import (
    EmptyOperationInput, GetPokemonSpeciesInput, GetServerStatisticsInput)
    EmptyOperationInput, GetPokemonSpeciesInput, GetServerStatisticsInput, HealthCheckOperationInput)
from libpokemon_service_server_sdk.model import FlavorText, Language
from libpokemon_service_server_sdk.output import (
    EmptyOperationOutput, GetPokemonSpeciesOutput, GetServerStatisticsOutput)
    EmptyOperationOutput, GetPokemonSpeciesOutput, GetServerStatisticsOutput, HealthCheckOperationOutput)
from libpokemon_service_server_sdk import App


@@ -136,6 +136,10 @@ def get_server_statistics(
    logging.debug("The service handled %d requests", calls_count)
    return GetServerStatisticsOutput(calls_count=calls_count)

@app.health_check_operation
def health_check_operation(_: HealthCheckOperationInput) -> HealthCheckOperationOutput:
    return HealthCheckOperationOutput()

###########################################################
# Run the server.
###########################################################
+5 −0
Original line number Diff line number Diff line
@@ -277,6 +277,11 @@ pub async fn empty_operation(_input: input::EmptyOperationInput) -> output::Empt
    output::EmptyOperationOutput {}
}

/// Operation used to show the service is running.
pub async fn health_check_operation(_input: input::HealthCheckOperationInput) -> output::HealthCheckOperationOutput {
    output::HealthCheckOperationOutput {}
}

#[cfg(test)]
mod tests {
    use super::*;
Loading