Skip to content

Commit

Permalink
Rkuris/grpc make process server (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Dec 6, 2023
1 parent 68e62de commit 068beda
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 1 deletion.
3 changes: 2 additions & 1 deletion grpc-testtool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "server"
name = "process-server"
test = false
bench = false

Expand All @@ -21,6 +21,7 @@ prost = "0.12.0"
thiserror = "1.0.47"
tokio = { version = "1.32.0", features = ["sync", "rt-multi-thread"] }
tonic = { version = "0.10.0", features = ["tls"] }
prost-types = "0.12.0"

[build-dependencies]
tonic-build = "0.10.0"
Expand Down
6 changes: 6 additions & 0 deletions grpc-testtool/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/sync/sync.proto")?;
tonic_build::compile_protos("proto/rpcdb/rpcdb.proto")?;
tonic_build::compile_protos("proto/io/prometheus/client/metrics.proto")?;

tonic_build::configure().compile(
&["proto/process-server/process-server.proto"], // protos
&["proto"], // includes
)?;

Ok(())
}
154 changes: 154 additions & 0 deletions grpc-testtool/proto/io/prometheus/client/metrics.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2013 Prometheus Team
// 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.

syntax = "proto2";

package io.prometheus.client;
option java_package = "io.prometheus.client";
option go_package = "github.com/prometheus/client_model/go;io_prometheus_client";

import "google/protobuf/timestamp.proto";

message LabelPair {
optional string name = 1;
optional string value = 2;
}

enum MetricType {
// COUNTER must use the Metric field "counter".
COUNTER = 0;
// GAUGE must use the Metric field "gauge".
GAUGE = 1;
// SUMMARY must use the Metric field "summary".
SUMMARY = 2;
// UNTYPED must use the Metric field "untyped".
UNTYPED = 3;
// HISTOGRAM must use the Metric field "histogram".
HISTOGRAM = 4;
// GAUGE_HISTOGRAM must use the Metric field "histogram".
GAUGE_HISTOGRAM = 5;
}

message Gauge {
optional double value = 1;
}

message Counter {
optional double value = 1;
optional Exemplar exemplar = 2;

optional google.protobuf.Timestamp created_timestamp = 3;
}

message Quantile {
optional double quantile = 1;
optional double value = 2;
}

message Summary {
optional uint64 sample_count = 1;
optional double sample_sum = 2;
repeated Quantile quantile = 3;

optional google.protobuf.Timestamp created_timestamp = 4;
}

message Untyped {
optional double value = 1;
}

message Histogram {
optional uint64 sample_count = 1;
optional double sample_count_float = 4; // Overrides sample_count if > 0.
optional double sample_sum = 2;
// Buckets for the conventional histogram.
repeated Bucket bucket = 3; // Ordered in increasing order of upper_bound, +Inf bucket is optional.

optional google.protobuf.Timestamp created_timestamp = 15;

// Everything below here is for native histograms (also known as sparse histograms).
// Native histograms are an experimental feature without stability guarantees.

// schema defines the bucket schema. Currently, valid numbers are -4 <= n <= 8.
// They are all for base-2 bucket schemas, where 1 is a bucket boundary in each case, and
// then each power of two is divided into 2^n logarithmic buckets.
// Or in other words, each bucket boundary is the previous boundary times 2^(2^-n).
// In the future, more bucket schemas may be added using numbers < -4 or > 8.
optional sint32 schema = 5;
optional double zero_threshold = 6; // Breadth of the zero bucket.
optional uint64 zero_count = 7; // Count in zero bucket.
optional double zero_count_float = 8; // Overrides sb_zero_count if > 0.

// Negative buckets for the native histogram.
repeated BucketSpan negative_span = 9;
// Use either "negative_delta" or "negative_count", the former for
// regular histograms with integer counts, the latter for float
// histograms.
repeated sint64 negative_delta = 10; // Count delta of each bucket compared to previous one (or to zero for 1st bucket).
repeated double negative_count = 11; // Absolute count of each bucket.

// Positive buckets for the native histogram.
// Use a no-op span (offset 0, length 0) for a native histogram without any
// observations yet and with a zero_threshold of 0. Otherwise, it would be
// indistinguishable from a classic histogram.
repeated BucketSpan positive_span = 12;
// Use either "positive_delta" or "positive_count", the former for
// regular histograms with integer counts, the latter for float
// histograms.
repeated sint64 positive_delta = 13; // Count delta of each bucket compared to previous one (or to zero for 1st bucket).
repeated double positive_count = 14; // Absolute count of each bucket.
}

// A Bucket of a conventional histogram, each of which is treated as
// an individual counter-like time series by Prometheus.
message Bucket {
optional uint64 cumulative_count = 1; // Cumulative in increasing order.
optional double cumulative_count_float = 4; // Overrides cumulative_count if > 0.
optional double upper_bound = 2; // Inclusive.
optional Exemplar exemplar = 3;
}

// A BucketSpan defines a number of consecutive buckets in a native
// histogram with their offset. Logically, it would be more
// straightforward to include the bucket counts in the Span. However,
// the protobuf representation is more compact in the way the data is
// structured here (with all the buckets in a single array separate
// from the Spans).
message BucketSpan {
optional sint32 offset = 1; // Gap to previous span, or starting point for 1st span (which can be negative).
optional uint32 length = 2; // Length of consecutive buckets.
}

message Exemplar {
repeated LabelPair label = 1;
optional double value = 2;
optional google.protobuf.Timestamp timestamp = 3; // OpenMetrics-style.
}

message Metric {
repeated LabelPair label = 1;
optional Gauge gauge = 2;
optional Counter counter = 3;
optional Summary summary = 4;
optional Untyped untyped = 5;
optional Histogram histogram = 7;
optional int64 timestamp_ms = 6;
}

message MetricFamily {
optional string name = 1;
optional string help = 2;
optional MetricType type = 3;
repeated Metric metric = 4;
optional string unit = 5;
}
16 changes: 16 additions & 0 deletions grpc-testtool/proto/process-server/process-server.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package process;

import "google/protobuf/empty.proto";
import "io/prometheus/client/metrics.proto";

option go_package = "github.com/ava-labs/merkledb-tester/proto/pb/process";

service ProcessServerService {
rpc Metrics(google.protobuf.Empty) returns (MetricsResponse);
}

message MetricsResponse {
repeated io.prometheus.client.MetricFamily metric_families = 1;
}
File renamed without changes.
16 changes: 16 additions & 0 deletions grpc-testtool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

pub mod io {
pub mod prometheus {
pub mod client {
#![allow(clippy::unwrap_used)]
#![allow(clippy::missing_const_for_fn)]
tonic::include_proto!("io.prometheus.client");
}
}
}

pub mod sync {
#![allow(clippy::unwrap_used)]
#![allow(clippy::missing_const_for_fn)]
Expand All @@ -13,6 +23,12 @@ pub mod rpcdb {
tonic::include_proto!("rpcdb");
}

pub mod process_server {
#![allow(clippy::unwrap_used)]
#![allow(clippy::missing_const_for_fn)]
tonic::include_proto!("process");
}

pub mod service;

pub use service::Database as DatabaseService;

0 comments on commit 068beda

Please sign in to comment.