forked from TrueCloudLab/frostfs-api-go
initial
This commit is contained in:
commit
1cf33e5ffd
87 changed files with 29835 additions and 0 deletions
48
state/service.go
Normal file
48
state/service.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// MetricFamily is type alias for proto.Message generated
|
||||
// from github.com/prometheus/client_model/metrics.proto.
|
||||
type MetricFamily = dto.MetricFamily
|
||||
|
||||
// EncodeMetrics encodes metrics from gatherer into MetricsResponse message,
|
||||
// if something went wrong returns gRPC Status error (can be returned from service).
|
||||
func EncodeMetrics(g prometheus.Gatherer) (*MetricsResponse, error) {
|
||||
metrics, err := g.Gather()
|
||||
if err != nil {
|
||||
return nil, status.New(codes.Internal, err.Error()).Err()
|
||||
}
|
||||
|
||||
results := make([][]byte, 0, len(metrics))
|
||||
for _, mf := range metrics {
|
||||
item, err := proto.Marshal(mf)
|
||||
if err != nil {
|
||||
return nil, status.New(codes.Internal, err.Error()).Err()
|
||||
}
|
||||
|
||||
results = append(results, item)
|
||||
}
|
||||
|
||||
return &MetricsResponse{Metrics: results}, nil
|
||||
}
|
||||
|
||||
// DecodeMetrics decodes metrics from MetricsResponse to []MetricFamily,
|
||||
// if something went wrong returns error.
|
||||
func DecodeMetrics(r *MetricsResponse) ([]*MetricFamily, error) {
|
||||
metrics := make([]*dto.MetricFamily, 0, len(r.Metrics))
|
||||
for i := range r.Metrics {
|
||||
mf := new(MetricFamily)
|
||||
if err := proto.Unmarshal(r.Metrics[i], mf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return metrics, nil
|
||||
}
|
1111
state/service.pb.go
Normal file
1111
state/service.pb.go
Normal file
File diff suppressed because it is too large
Load diff
37
state/service.proto
Normal file
37
state/service.proto
Normal file
|
@ -0,0 +1,37 @@
|
|||
syntax = "proto3";
|
||||
package state;
|
||||
option go_package = "github.com/nspcc-dev/neofs-proto/state";
|
||||
|
||||
import "bootstrap/types.proto";
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.stable_marshaler_all) = true;
|
||||
|
||||
// The Status service definition.
|
||||
service Status {
|
||||
rpc Netmap(NetmapRequest) returns (bootstrap.SpreadMap);
|
||||
rpc Metrics(MetricsRequest) returns (MetricsResponse);
|
||||
rpc HealthCheck(HealthRequest) returns (HealthResponse);
|
||||
}
|
||||
|
||||
// NetmapRequest message to request current node netmap
|
||||
message NetmapRequest {}
|
||||
|
||||
// MetricsRequest message to request node metrics
|
||||
message MetricsRequest {}
|
||||
|
||||
// MetricsResponse contains [][]byte,
|
||||
// every []byte is marshaled MetricFamily proto message
|
||||
// from github.com/prometheus/client_model/metrics.proto
|
||||
message MetricsResponse {
|
||||
repeated bytes Metrics = 1;
|
||||
}
|
||||
|
||||
// HealthRequest message to check current state
|
||||
message HealthRequest {}
|
||||
|
||||
// HealthResponse message with current state
|
||||
message HealthResponse {
|
||||
bool Healthy = 1;
|
||||
string Status = 2;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue