mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-07-21 17:34:14 +00:00
Stats API: Return status "not found" instead of "unknown" (#4860)
This commit is contained in:
parent
cbcab89c7e
commit
ca8ef209a7
1 changed files with 5 additions and 3 deletions
|
@ -12,6 +12,8 @@ import (
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
feature_stats "github.com/xtls/xray-core/features/stats"
|
feature_stats "github.com/xtls/xray-core/features/stats"
|
||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
// statsServer is an implementation of StatsService.
|
// statsServer is an implementation of StatsService.
|
||||||
|
@ -30,7 +32,7 @@ func NewStatsServer(manager feature_stats.Manager) StatsServiceServer {
|
||||||
func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
||||||
c := s.stats.GetCounter(request.Name)
|
c := s.stats.GetCounter(request.Name)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return nil, errors.New(request.Name, " not found.")
|
return nil, status.Error(codes.NotFound, request.Name+" not found.")
|
||||||
}
|
}
|
||||||
var value int64
|
var value int64
|
||||||
if request.Reset_ {
|
if request.Reset_ {
|
||||||
|
@ -49,7 +51,7 @@ func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*
|
||||||
func (s *statsServer) GetStatsOnline(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
func (s *statsServer) GetStatsOnline(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
||||||
c := s.stats.GetOnlineMap(request.Name)
|
c := s.stats.GetOnlineMap(request.Name)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return nil, errors.New(request.Name, " not found.")
|
return nil, status.Error(codes.NotFound, request.Name+" not found.")
|
||||||
}
|
}
|
||||||
value := int64(c.Count())
|
value := int64(c.Count())
|
||||||
return &GetStatsResponse{
|
return &GetStatsResponse{
|
||||||
|
@ -64,7 +66,7 @@ func (s *statsServer) GetStatsOnlineIpList(ctx context.Context, request *GetStat
|
||||||
c := s.stats.GetOnlineMap(request.Name)
|
c := s.stats.GetOnlineMap(request.Name)
|
||||||
|
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return nil, errors.New(request.Name, " not found.")
|
return nil, status.Error(codes.NotFound, request.Name+" not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
ips := make(map[string]int64)
|
ips := make(map[string]int64)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue