Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合入注册中心相关及健康检查相关的多个BUG修复及优化 #1403

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
22 changes: 10 additions & 12 deletions apiserver/grpcserver/discover/v1/client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ func (g *DiscoverServer) Discover(server apiservice.PolarisGRPC_DiscoverServer)
var out *apiservice.DiscoverResponse
var action string
startTime := commontime.CurrentMillisecond()
defer func() {
plugin.GetStatis().ReportDiscoverCall(metrics.ClientDiscoverMetric{
Action: action,
ClientIP: utils.ParseClientAddress(ctx),
Namespace: in.GetService().GetNamespace().GetValue(),
Resource: in.GetType().String() + ":" + in.GetService().GetName().GetValue(),
Timestamp: startTime,
CostTime: commontime.CurrentMillisecond() - startTime,
Revision: out.GetService().GetRevision().GetValue(),
Success: out.GetCode().GetValue() > uint32(apimodel.Code_DataNoChange),
})
}()

// 兼容。如果请求中带了token,优先使用该token
if in.GetService().GetToken().GetValue() != "" {
Expand Down Expand Up @@ -173,6 +161,16 @@ func (g *DiscoverServer) Discover(server apiservice.PolarisGRPC_DiscoverServer)
}

err = server.Send(out)
plugin.GetStatis().ReportDiscoverCall(metrics.ClientDiscoverMetric{
Action: action,
ClientIP: utils.ParseClientAddress(ctx),
Namespace: in.GetService().GetNamespace().GetValue(),
Resource: in.GetType().String() + ":" + in.GetService().GetName().GetValue(),
Timestamp: startTime,
CostTime: commontime.CurrentMillisecond() - startTime,
Revision: out.GetService().GetRevision().GetValue(),
Success: out.GetCode().GetValue() > uint32(apimodel.Code_DataNoChange),
})
if err != nil {
return err
}
Expand Down
53 changes: 53 additions & 0 deletions cache/api/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 api

import "time"

func NewExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
return &ExpireEntry[T]{
data: t,
maxAlive: maxAlive,
}
}

func EmptyExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
return &ExpireEntry[T]{
empty: true,
maxAlive: maxAlive,
}
}

type ExpireEntry[T any] struct {
empty bool
data T
lastAccess time.Time
maxAlive time.Duration
}

func (e *ExpireEntry[T]) Get() T {
if e.empty {
return e.data
}
e.lastAccess = time.Now()
return e.data
}

func (e *ExpireEntry[T]) IsExpire() bool {
return time.Since(e.lastAccess) > e.maxAlive
}
39 changes: 4 additions & 35 deletions cache/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ type (
GetAliasFor(name string, namespace string) *model.Service
// GetRevisionWorker .
GetRevisionWorker() ServiceRevisionWorker
// GetVisibleServicesInOtherNamespace get same service in other namespace and it's visible
GetVisibleServicesInOtherNamespace(name string, namespace string) []*model.Service
// GetVisibleSameNameServices get same service in other namespace and it's visible
GetVisibleSameNameServices(name string, namespace string) []*model.Service
// GetVisibleServices get all services in other namespace and it's visible
GetVisibleServices(ctx context.Context, namespace string) []*model.Service
}

// ServiceRevisionWorker
Expand Down Expand Up @@ -881,36 +883,3 @@ type (
HitGrayRule(name string, labels map[string]string) bool
}
)

func NewExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
return &ExpireEntry[T]{
data: t,
maxAlive: maxAlive,
}
}

func EmptyExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
return &ExpireEntry[T]{
empty: true,
maxAlive: maxAlive,
}
}

type ExpireEntry[T any] struct {
empty bool
data T
lastAccess time.Time
maxAlive time.Duration
}

func (e *ExpireEntry[T]) Get() T {
if e.empty {
return e.data
}
e.lastAccess = time.Now()
return e.data
}

func (e *ExpireEntry[T]) IsExpire() bool {
return time.Since(e.lastAccess) > e.maxAlive
}
Loading
Loading