Skip to content

Commit

Permalink
changed the initialization data of stat dashboard and update authz (k…
Browse files Browse the repository at this point in the history
…oderover#2532)

* changed the initialization data of stat dashboard and update authorization info

Signed-off-by: Min Min <[email protected]>

* debug

Signed-off-by: Min Min <[email protected]>

* debug

Signed-off-by: Min Min <[email protected]>

* debug

Signed-off-by: Min Min <[email protected]>

* minor fix

Signed-off-by: Min Min <[email protected]>

---------

Signed-off-by: Min Min <[email protected]>
Co-authored-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 and Min Min authored Apr 18, 2023
1 parent c369d57 commit 825c4d0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/microservice/aslan/config/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,11 @@ const (
DashboardDataTypeReleaseSuccessRate = "release_success_rate"
DashboardDataTypeReleaseAverageDuration = "release_average_duration"
DashboardDataTypeReleaseFrequency = "release_frequency"

DashboardDataSourceZadig = "zadig"
DashboardDataSourceApi = "api"

DashboardDataCategoryQuality = "quality"
DashboardDataCategoryEfficiency = "efficiency"
DashboardDataCategorySchedule = "schedule"
)
10 changes: 8 additions & 2 deletions pkg/microservice/aslan/core/stat/service/stat_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service

import (
"fmt"
"strconv"
"strings"

"github.com/Knetic/govaluate"
Expand Down Expand Up @@ -127,13 +128,18 @@ func (c *GeneralCalculator) GetWeightedScore(fact float64) (float64, error) {
}

func (c *GeneralCalculator) GetFact(startTime, endTime int64, project string) (float64, bool, error) {
var fact float64
var fact struct {
Data float64 `json:"data"`
}
host := strings.TrimSuffix(c.Host, "/")
url := fmt.Sprintf("%s/%s", host, c.Path)
queryMap := make(map[string]string)
for _, query := range c.Queries {
queryMap[query.Key] = query.Value.(string)
}
queryMap["start_time"] = strconv.FormatInt(startTime, 10)
queryMap["end_time"] = strconv.FormatInt(endTime, 10)
queryMap["project_name"] = project
headerMap := make(map[string]string)
for _, header := range c.Headers {
headerMap[header.Key] = header.Value.(string)
Expand All @@ -142,7 +148,7 @@ func (c *GeneralCalculator) GetFact(startTime, endTime int64, project string) (f
if err != nil {
return 0, false, err
}
return fact, true, nil
return fact.Data, true, nil
}

// TestPassRateCalculator is used when the data ID is "test_pass_rate" and the data source is "zadig"
Expand Down
60 changes: 59 additions & 1 deletion pkg/microservice/aslan/core/stat/service/stat_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"go.uber.org/zap"

"github.com/koderover/zadig/pkg/microservice/aslan/config"
commonmodels "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/models"
commonrepo "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb"
templaterepo "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb/template"
Expand Down Expand Up @@ -238,7 +239,64 @@ func GetStatsDashboard(startTime, endTime int64, logger *zap.SugaredLogger) ([]*
return resp, nil
}

var defaultStatDashboardConfigMap map[string]*commonmodels.StatDashboardConfig
var defaultStatDashboardConfigMap = map[string]*commonmodels.StatDashboardConfig{
config.DashboardDataTypeBuildAverageDuration: {
Type: config.DashboardDataCategoryEfficiency,
Name: "构建平均耗时",
ItemKey: config.DashboardDataTypeBuildAverageDuration,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 100,
},
config.DashboardDataTypeBuildSuccessRate: {
Type: config.DashboardDataCategoryEfficiency,
Name: "构建成功率",
ItemKey: config.DashboardDataTypeBuildSuccessRate,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
config.DashboardDataTypeDeploySuccessRate: {
Type: config.DashboardDataCategoryEfficiency,
Name: "部署成功率",
ItemKey: config.DashboardDataTypeDeploySuccessRate,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
config.DashboardDataTypeDeployFrequency: {
Type: config.DashboardDataCategoryEfficiency,
Name: "部署频次(周)",
ItemKey: config.DashboardDataTypeDeployFrequency,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
config.DashboardDataTypeTestPassRate: {
Type: config.DashboardDataCategoryQuality,
Name: "测试通过率",
ItemKey: config.DashboardDataTypeTestPassRate,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
config.DashboardDataTypeTestAverageDuration: {
Type: config.DashboardDataCategoryEfficiency,
Name: "测试平均耗时",
ItemKey: config.DashboardDataTypeTestAverageDuration,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
config.DashboardDataTypeReleaseFrequency: {
Type: config.DashboardDataCategoryEfficiency,
Name: "发布频次(周)",
ItemKey: config.DashboardDataTypeReleaseFrequency,
Source: config.DashboardDataSourceZadig,
Function: "x",
Weight: 0,
},
}

func createDefaultStatDashboardConfig() []*commonmodels.StatDashboardConfig {
ret := make([]*commonmodels.StatDashboardConfig, 0)
Expand Down
4 changes: 4 additions & 0 deletions pkg/microservice/policy/core/yamlconfig/urls.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
description: "public urls: url not need to authentication ; system_admin urls: urls that only system admin has permission ; project_admin: urls that project admin has permission"
exemption_urls:
public:
- endpoint: /api/plutus/license
methods:
- GET
- POST
- endpoint: api/plutus/health
methods:
- GET
Expand Down
2 changes: 2 additions & 0 deletions pkg/middleware/gin/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func ProcessLicense() gin.HandlerFunc {
c.Request.URL.Path == "/api/system/concurrency/workflow" ||
c.Request.URL.Path == "/api/workflow/plugin/enterprise" ||
strings.HasPrefix(c.Request.URL.Path, "/api/v1/bundles") ||
strings.HasPrefix(c.Request.URL.Path, "/api/v1/callback") ||
strings.HasPrefix(c.Request.URL.Path, "/api/callback") ||
strings.HasPrefix(c.Request.URL.Path, "/api/v1/system-rolebindings") ||
strings.HasPrefix(c.Request.URL.Path, "/api/cluster/clusters") {
c.Next()
Expand Down

0 comments on commit 825c4d0

Please sign in to comment.