8000 Refactor test dir by chuntaojun · Pull Request #995 · polarismesh/polaris · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor test dir #995

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

Merged
merged 21 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apiserver/eurekaserver/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
"github.com/stretchr/testify/assert"

api "github.com/polarismesh/polaris/common/api/v1"
"github.com/polarismesh/polaris/service"
testsuit "github.com/polarismesh/polaris/test/suit"
)

func createEurekaServerForTest(
discoverSuit *service.DiscoverTestSuit, options map[string]interface{}) (*EurekaServer, error) {
discoverSuit *testsuit.DiscoverTestSuit, options map[string]interface{}) (*EurekaServer, error) {
eurekaSrv := &EurekaServer{
namingServer: discoverSuit.DiscoverServer(),
healthCheckServer: discoverSuit.HealthCheckServer(),
Expand Down Expand Up @@ -142,7 +142,7 @@ func checkInstanceAction(t *testing.T, applications *Applications, appName strin

// 测试新建实例
func TestCreateInstance(t *test 10000 ing.T) {
discoverSuit := &service.DiscoverTestSuit{}
discoverSuit := &testsuit.DiscoverTestSuit{}
if err := discoverSuit.Initialize(); err != nil {
t.Fatal(err)
}
Expand Down
66 changes: 65 additions & 1 deletion cache/config_file_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/polarismesh/polaris/common/metrics"
Expand All @@ -30,9 +31,14 @@ import (
func (fc *fileCache) reportMetricsInfo(ctx context.Context) {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()

var preGroup map[string]map[string]struct{}

for {
select {
case <-ticker.C:
tmpGroup := map[string]map[string]struct{}{}

configGroups, err := fc.storage.CountGroupEachNamespace()
if err != nil {
log.Error("[Cache][ConfigFile] report metrics for config_group each namespace", zap.Error(err))
Expand All @@ -50,6 +56,14 @@ func (fc *fileCache) reportMetricsInfo(ctx context.Context) {
log.Error("[Cache][ConfigFile] report metrics for release config_file each group", zap.Error(err))
continue
}
for ns, groups := range configFiles {
if _, ok := tmpGroup[ns]; !ok {
tmpGroup[ns] = map[string]struct{}{}
}
for group := range groups {
tmpGroup[ns][group] = struct{}{}
}
}

metricValues := make([]metrics.ConfigMetrics, 0, 64)

Expand Down Expand Up @@ -89,10 +103,60 @@ func (fc *fileCache) reportMetricsInfo(ctx context.Context) {
})
}
}

cleanExpireConfigFileMetricLabel(preGroup, tmpGroup)
preGroup = tmpGroup
plugin.GetStatis().ReportConfigMetrics(metricValues...)
case <-ctx.Done():
return
}
}
}

func cleanExpireConfigFileMetricLabel(pre, curr map[string]map[string]struct{}) {
if len(pre) == 0 {
return
}

var (
removeNs = map[string]struct{}{}
remove = map[string]map[string]struct{}{}
)

for ns, groups := range pre {
if _, ok := curr[ns]; !ok {
removeNs[ns] = struct{}{}
}
if _, ok := remove[ns]; !ok {
remove[ns] = map[string]struct{}{}
}
for group := range groups {
if _, ok := curr[ns][group]; !ok {
remove[ns][group] = struct{}{}
}
}
}

for ns := range removeNs {
metrics.GetConfigGroupTotal().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
})
}

for ns, groups := range remove {
for group := range groups {
metrics.GetConfigFileTotal().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelGroup: group,
})
metrics.GetReleaseConfigFileTotal().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelGroup: group,
})
metrics.GetConfigFileTotal().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelGroup: group,
})
}
}

}
75 changes: 75 additions & 0 deletions cache/instance_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@
package cache

import (
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/polarismesh/polaris/common/metrics"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/plugin"
)

var preServiceInfos = map[string]map[string]struct{}{}

func (ic *instanceCache) reportMetricsInfo() {
cacheMgr, err := GetCacheManager()
if err != nil {
log.Warn("[Cache][Instance] report metrics get cache manager, but impossible", zap.Error(err))
return
}

tmpServiceInfos := map[string]map[string]struct{}{}

allServices := map[string]map[string]struct{}{}
onlineService := map[string]map[string]struct{}{}
offlineService := map[string]map[string]struct{}{}
Expand All @@ -49,6 +54,12 @@ func (ic *instanceCache) reportMetricsInfo() {
log.Debug("[Cache][Instance] report metrics get service not found", zap.String("svc-id", serviceID))
return true
}

if _, ok := tmpServiceInfos[svc.Namespace]; !ok {
tmpServiceInfos[svc.Namespace] = map[string]struct{}{}
}
tmpServiceInfos[svc.Namespace][svc.Name] = struct{}{}

if _, ok := allServices[svc.Namespace]; !ok {
allServices[svc.Namespace] = map[string]struct{}{}
}
Expand Down 9E12 Expand Up @@ -101,5 +112,69 @@ func (ic *instanceCache) reportMetricsInfo() {
})
}

cleanExpireServiceMetricLabel(preServiceInfos, tmpServiceInfos)
preServiceInfos = tmpServiceInfos
plugin.GetStatis().ReportDiscoveryMetrics(metricValues...)
}

func cleanExpireServiceMetricLabel(pre, curr map[string]map[string]struct{}) {
if len(pre) == 0 {
return
}

var (
removeNs = map[string]struct{}{}
remove = map[string]map[string]struct{}{}
)

for ns, services := range pre {
if _, ok := curr[ns]; !ok {
removeNs[ns] = struct{}{}
}
if _, ok := remove[ns]; !ok {
remove[ns] = map[string]struct{}{}
}
for service := range services {
if _, ok := curr[ns][service]; !ok {
remove[ns][service] = struct{}{}
}
}
}

for ns := range removeNs {
metrics.GetServiceCount().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
})
metrics.GetServiceOfflineCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
})
metrics.GetServiceOnlineCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
})
metrics.GetServiceAbnormalCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
})
}

for ns, services := range remove {
for service := range services {
metrics.GetInstanceCount().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelService: service,
})
metrics.GetInstanceAbnormalCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelService: service,
})
metrics.GetInstanceIsolateCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelService: service,
})
metrics.GetInstanceOnlineCountl().Delete(prometheus.Labels{
metrics.LabelNamespace: ns,
metrics.LabelService: service,
})
}
}

}
70 changes: 70 additions & 0 deletions common/metrics/config_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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 metrics

import (
"github.com/prometheus/client_golang/prometheus"

"github.com/polarismesh/polaris/common/utils"
)

func registerConfigFileMetrics() {
GetRegistry().MustRegister(
configGroupTotal,
configFileTotal,
releaseConfigFileTotal,
)
}

var (
configGroupTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "config_group_count",
Help: "polaris config group total number",
ConstLabels: map[string]string{
LabelServerNode: utils.LocalHost,
},
}, []string{LabelNamespace})

configFileTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "config_file_count",
Help: "total number of config_file each config group",
ConstLabels: map[string]string{
LabelServerNode: utils.LocalHost,
},
}, []string{LabelNamespace, LabelGroup})

releaseConfigFileTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "config_release_file_count",
Help: "total number of config_release_file each config group",
ConstLabels: map[string]string{
LabelServerNode: utils.LocalHost,
},
}, []string{LabelNamespace, LabelGroup})
)

func GetConfigGroupTotal() *prometheus.GaugeVec {
return configGroupTotal
}

func GetConfigFileTotal() *prometheus.GaugeVec {
return configFileTotal
}

func GetReleaseConfigFileTotal() *prometheus.GaugeVec {
return releaseConfigFileTotal
}
2 changes: 2 additions & 0 deletions common/metrics/default.go
Original file line number Diff line number Di 5841 ff line change
Expand Up @@ -47,4 +47,6 @@ func GetHttpHandler() http.Handler {
func InitMetrics() {
registerSysMetrics()
registerClientMetrics()
registerConfigFileMetrics()
registerDiscoveryMetrics()
}
Loading
0