This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch api-version in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
commit ffe0eb78c2390fecc13654554c9ee304a018a844 Author: Gao Hongtao <[email protected]> AuthorDate: Sat Jan 11 08:06:55 2025 +0800 Add api-version service Signed-off-by: Gao Hongtao <[email protected]> --- CHANGES.md | 1 + api/proto/banyandb/common/v1/rpc.proto | 52 ++++++++++++++++++++++ api/proto/banyandb/version.go | 30 +++++++++++++ banyand/liaison/grpc/api_version.go | 38 +++++++++++++++++ banyand/liaison/grpc/server.go | 2 + banyand/liaison/http/server.go | 2 + banyand/observability/metrics_system.go | 6 +++ docs/api-reference.md | 76 +++++++++++++++++++++++++++++++++ scripts/build/base.mk | 6 +++ 9 files changed, 213 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 863bb217..0b01cde5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ Release Notes. - Read cpu quota and limit from the cgroup file system to set gomaxprocs. - Property: Add native storage layer for property. - Add the max disk usage threshold for the `Measure`, `Stream`, and `Property` to control the disk usage. +- Add the "api version" service to gRPC and HTTP server. ### Bug Fixes diff --git a/api/proto/banyandb/common/v1/rpc.proto b/api/proto/banyandb/common/v1/rpc.proto new file mode 100644 index 00000000..6f1ebf04 --- /dev/null +++ b/api/proto/banyandb/common/v1/rpc.proto @@ -0,0 +1,52 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you 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 = "proto3"; + +package banyandb.common.v1; + +import "google/api/annotations.proto"; + +option go_package = "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"; +option java_package = "org.apache.skywalking.banyandb.common.v1"; + +// APIVersion is the version of the API +message APIVersion { + // version is the version of the API + string version = 1; + // revision is the commit hash of the API + string revision = 2; +} + +// GetAPIVersionRequest is the request for GetAPIVersion +message GetAPIVersionRequest { + // empty +} + +// GetAPIVersionResponse is the response for GetAPIVersion +message GetAPIVersionResponse { + // version is the version of the API + APIVersion version = 1; +} + +// Service is the service for the API +service Service { + // GetAPIVersion returns the version of the API + rpc GetAPIVersion(GetAPIVersionRequest) returns (GetAPIVersionResponse) { + option (google.api.http) = {get: "/v1/common/api/version"}; + } +} diff --git a/api/proto/banyandb/version.go b/api/proto/banyandb/version.go new file mode 100644 index 00000000..7b89d508 --- /dev/null +++ b/api/proto/banyandb/version.go @@ -0,0 +1,30 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you 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. + +// Package apiversion contains the version of the API. +package apiversion + +// Version is the version of the API. +const Version = "0.8" + +// Revision is the revision of the API. Building with -ldflags -X. +var revision string + +// GetRevision returns the revision of the API. +func GetRevision() string { + return revision +} diff --git a/banyand/liaison/grpc/api_version.go b/banyand/liaison/grpc/api_version.go new file mode 100644 index 00000000..56f1c4f9 --- /dev/null +++ b/banyand/liaison/grpc/api_version.go @@ -0,0 +1,38 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you 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. + +package grpc + +import ( + "context" + + apiversion "github.com/apache/skywalking-banyandb/api/proto/banyandb" + commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1" +) + +type apiVersionService struct { + commonv1.UnimplementedServiceServer +} + +func (s *apiVersionService) GetAPIVersion(context.Context, *commonv1.GetAPIVersionRequest) (*commonv1.GetAPIVersionResponse, error) { + return &commonv1.GetAPIVersionResponse{ + Version: &commonv1.APIVersion{ + Version: apiversion.Version, + Revision: apiversion.GetRevision(), + }, + }, nil +} diff --git a/banyand/liaison/grpc/server.go b/banyand/liaison/grpc/server.go index 20e8c2f1..1f540575 100644 --- a/banyand/liaison/grpc/server.go +++ b/banyand/liaison/grpc/server.go @@ -35,6 +35,7 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/status" + commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1" databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1" measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1" propertyv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/property/v1" @@ -259,6 +260,7 @@ func (s *server) Serve() run.StopNotify { ) s.ser = grpclib.NewServer(opts...) + commonv1.RegisterServiceServer(s.ser, &apiVersionService{}) streamv1.RegisterStreamServiceServer(s.ser, s.streamSVC) measurev1.RegisterMeasureServiceServer(s.ser, s.measureSVC) // register *Registry diff --git a/banyand/liaison/http/server.go b/banyand/liaison/http/server.go index 576b8289..14b1d5d7 100644 --- a/banyand/liaison/http/server.go +++ b/banyand/liaison/http/server.go @@ -35,6 +35,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" + commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1" databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1" measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1" propertyv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/property/v1" @@ -163,6 +164,7 @@ func (p *server) Serve() run.StopNotify { } gwMux := runtime.NewServeMux(runtime.WithHealthzEndpoint(client)) err = multierr.Combine( + commonv1.RegisterServiceHandlerFromEndpoint(ctx, gwMux, p.grpcAddr, opts), databasev1.RegisterStreamRegistryServiceHandlerFromEndpoint(ctx, gwMux, p.grpcAddr, opts), databasev1.RegisterMeasureRegistryServiceHandlerFromEndpoint(ctx, gwMux, p.grpcAddr, opts), databasev1.RegisterIndexRuleRegistryServiceHandlerFromEndpoint(ctx, gwMux, p.grpcAddr, opts), diff --git a/banyand/observability/metrics_system.go b/banyand/observability/metrics_system.go index b1749b08..92c346db 100644 --- a/banyand/observability/metrics_system.go +++ b/banyand/observability/metrics_system.go @@ -108,9 +108,11 @@ func collectCPU() { s, err := cpuTimesFunc(false) if err != nil { log.Error().Err(err).Msg("cannot get cpu stat") + return } if len(s) == 0 { log.Error().Msg("cannot get cpu stat") + return } allStat := s[0] total := allStat.User + allStat.System + allStat.Idle + allStat.Nice + allStat.Iowait + allStat.Irq + @@ -128,10 +130,12 @@ func collectCPU() { func collectMemory() { if memoryStateGauge == nil { log.Error().Msg("memoryStateGauge is not registered") + return } m, err := mem.VirtualMemory() if err != nil { log.Error().Err(err).Msg("cannot get memory stat") + return } memoryStateGauge.Set(m.UsedPercent/100, "used_percent") memoryStateGauge.Set(float64(m.Used), "used") @@ -141,10 +145,12 @@ func collectMemory() { func collectNet() { if netStateGauge == nil { log.Error().Msg("netStateGauge is not registered") + return } stats, err := getNetStat(context.Background()) if err != nil { log.Error().Err(err).Msg("cannot get net stat") + return } for _, stat := range stats { netStateGauge.Set(float64(stat.BytesRecv), "bytes_recv", stat.Name) diff --git a/docs/api-reference.md b/docs/api-reference.md index 3bd27bfc..09cf839c 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -23,6 +23,13 @@ - [Catalog](#banyandb-common-v1-Catalog) - [IntervalRule.Unit](#banyandb-common-v1-IntervalRule-Unit) +- [banyandb/common/v1/rpc.proto](#banyandb_common_v1_rpc-proto) + - [APIVersion](#banyandb-common-v1-APIVersion) + - [GetAPIVersionRequest](#banyandb-common-v1-GetAPIVersionRequest) + - [GetAPIVersionResponse](#banyandb-common-v1-GetAPIVersionResponse) + + - [Service](#banyandb-common-v1-Service) + - [banyandb/common/v1/trace.proto](#banyandb_common_v1_trace-proto) - [Span](#banyandb-common-v1-Span) - [Tag](#banyandb-common-v1-Tag) @@ -467,6 +474,75 @@ Metadata is for multi-tenant, multi-model use +<a name="banyandb_common_v1_rpc-proto"></a> +<p align="right"><a href="#top">Top</a></p> + +## banyandb/common/v1/rpc.proto + + + +<a name="banyandb-common-v1-APIVersion"></a> + +### APIVersion +APIVersion is the version of the API + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| version | [string](#string) | | version is the version of the API | +| revision | [string](#string) | | revision is the commit hash of the API | + + + + + + +<a name="banyandb-common-v1-GetAPIVersionRequest"></a> + +### GetAPIVersionRequest +GetAPIVersionRequest is the request for GetAPIVersion + +empty + + + + + + +<a name="banyandb-common-v1-GetAPIVersionResponse"></a> + +### GetAPIVersionResponse +GetAPIVersionResponse is the response for GetAPIVersion + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| version | [APIVersion](#banyandb-common-v1-APIVersion) | | version is the version of the API | + + + + + + + + + + + + +<a name="banyandb-common-v1-Service"></a> + +### Service +Service is the service for the API + +| Method Name | Request Type | Response Type | Description | +| ----------- | ------------ | ------------- | ------------| +| GetAPIVersion | [GetAPIVersionRequest](#banyandb-common-v1-GetAPIVersionRequest) | [GetAPIVersionResponse](#banyandb-common-v1-GetAPIVersionResponse) | GetAPIVersion returns the version of the API | + + + + + <a name="banyandb_common_v1_trace-proto"></a> <p align="right"><a href="#top">Top</a></p> diff --git a/scripts/build/base.mk b/scripts/build/base.mk index d8010355..f37edccd 100644 --- a/scripts/build/base.mk +++ b/scripts/build/base.mk @@ -41,6 +41,12 @@ endif GO_LINK_VERSION := -X ${VERSION_PATH}.build=${VERSION_STRING}-${GIT_BRANCH_NAME} +API_VERSION_PATH := github.com/apache/skywalking-banyandb/api/proto/banyandb +PROTO_REVISION := $(shell git log -1 --pretty=format:%h -- ${root_dir}/api/proto/banyandb) + +GO_LINK_VERSION := ${GO_LINK_VERSION} -X ${API_VERSION_PATH}.revision=${PROTO_REVISION} + + # Operating system name, such as 'Darwin' OS := $(shell uname)
