Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"blockscout-auth",
"blockscout-client/crate",
"blockscout-db",
"blockscout-service-health",
"blockscout-service-launcher",
"display-bytes",
"env-collector",
Expand Down
18 changes: 18 additions & 0 deletions libs/blockscout-service-health/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "blockscout-service-health"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-web = "4"
actix-prost = { git = "https://github.com/blockscout/actix-prost" }
actix-prost-macros = { git = "https://github.com/blockscout/actix-prost" }
prost = "0.11"
serde = { version = "1", features = ["derive"] }
serde_with = { version = "3", features = ["hex", "base64"] }
tonic = "0.8"

[build-dependencies]
actix-prost-build = { git = "https://github.com/blockscout/actix-prost" }
tonic-build = "0.8"
prost-build = "0.11"
44 changes: 44 additions & 0 deletions libs/blockscout-service-health/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use actix_prost_build::{ActixGenerator, GeneratorList};
use prost_build::{Config, ServiceGenerator};
use std::path::Path;

// custom function to include custom generator
fn compile(
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
generator: Box<dyn ServiceGenerator>,
) -> Result<(), Box<dyn std::error::Error>> {
let mut config = Config::new();
config
.service_generator(generator)
.compile_well_known_types()
.protoc_arg("--openapiv2_out=swagger")
.protoc_arg("--openapiv2_opt")
.protoc_arg("grpc_api_configuration=proto/api_config_http.yaml,output_format=yaml,allow_merge=true,merge_file_name=health")
.bytes(["."])
.type_attribute(".", "#[actix_prost_macros::serde]")
.field_attribute(
".grpc.health.v1.HealthCheckRequest.service",
"#[serde(default)]"
);
config.compile_protos(protos, includes)?;
Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// We need to rebuild proto lib only if any of proto definitions
// (or corresponding http mapping) has been changed.
println!("cargo:rerun-if-changed=proto/");

std::fs::create_dir_all("./swagger").unwrap();
let gens = Box::new(GeneratorList::new(vec![
tonic_build::configure().service_generator(),
Box::new(ActixGenerator::new("proto/api_config_http.yaml").unwrap()),
]));
compile(
&["../../proto/health/v1/health.proto"],
&["../../proto", "proto"],
gens,
)?;
Ok(())
}
7 changes: 7 additions & 0 deletions libs/blockscout-service-health/proto/api_config_http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: google.api.Service
config_version: 3

http:
rules:
- selector: grpc.health.v1.Health.Check
get: /health
7 changes: 7 additions & 0 deletions libs/blockscout-service-health/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod grpc {
pub mod health {
pub mod v1 {
include!(concat!(env!("OUT_DIR"), "/grpc.health.v1.rs"));
}
}
}
74 changes: 74 additions & 0 deletions libs/blockscout-service-health/swagger/health.swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
swagger: "2.0"
info:
title: health/v1/health.proto
version: version not set
tags:
- name: Health
consumes:
- application/json
produces:
- application/json
paths:
/health:
get:
summary: |-
Check gets the health of the specified service. If the requested service
is unknown, the call will fail with status NOT_FOUND. If the caller does
not specify a service name, the server should respond with its overall
health status.
description: |-
Clients should set a deadline when calling Check, and can declare the
server unhealthy if they do not receive a timely response.

Check implementations should be idempotent and side effect free.
operationId: Health_Check
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1HealthCheckResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/rpcStatus'
parameters:
- name: service
in: query
required: false
type: string
tags:
- Health
definitions:
HealthCheckResponseServingStatus:
type: string
enum:
- UNKNOWN
- SERVING
- NOT_SERVING
- SERVICE_UNKNOWN
default: UNKNOWN
description: ' - SERVICE_UNKNOWN: Used only by the Watch method.'
protobufAny:
type: object
properties:
'@type':
type: string
additionalProperties: {}
rpcStatus:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
$ref: '#/definitions/protobufAny'
v1HealthCheckResponse:
type: object
properties:
status:
$ref: '#/definitions/HealthCheckResponseServingStatus'
Loading