This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from keptn/release-0.6.0
Release 0.6.0
- Loading branch information
Showing
10 changed files
with
283 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package utils | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/keptn/go-utils/pkg/configuration-service/models" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// SLIConfig represents the struct of a SLI file | ||
type SLIConfig struct { | ||
Indicators map[string]string `json:"indicators" yaml:"indicators"` | ||
} | ||
|
||
// GetSLIConfiguration retrieves the SLI configuration for a service considering SLI configuration on stage and project level. | ||
// First, the configuration of project-level is retrieved, which is then overridden by configuration on stage level, | ||
// overridden by configuration on service level. | ||
func (r *ResourceHandler) GetSLIConfiguration(project string, stage string, service string, resourceURI string) (map[string]string, error) { | ||
var res *models.Resource | ||
var err error | ||
SLIs := make(map[string]string) | ||
|
||
// get sli config from project | ||
if project != "" { | ||
res, err = r.GetProjectResource(project, resourceURI) | ||
if err != nil { | ||
// return error except "resource not found" type | ||
if !strings.Contains(err.Error(), "resource not found") { | ||
return nil, err | ||
} | ||
} | ||
SLIs, err = addResourceContentToSLIMap(SLIs, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// get sli config from stage | ||
if project != "" && stage != "" { | ||
res, err = r.GetStageResource(project, stage, resourceURI) | ||
if err != nil { | ||
// return error except "resource not found" type | ||
if !strings.Contains(err.Error(), "resource not found") { | ||
return nil, err | ||
} | ||
} | ||
SLIs, err = addResourceContentToSLIMap(SLIs, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// get sli config from service | ||
if project != "" && stage != "" && service != "" { | ||
res, err = r.GetServiceResource(project, stage, service, resourceURI) | ||
if err != nil { | ||
// return error except "resource not found" type | ||
if !strings.Contains(err.Error(), "resource not found") { | ||
return nil, err | ||
} | ||
} | ||
SLIs, err = addResourceContentToSLIMap(SLIs, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return SLIs, nil | ||
} | ||
|
||
func addResourceContentToSLIMap(SLIs map[string]string, resource *models.Resource) (map[string]string, error) { | ||
if resource != nil { | ||
sliConfig := SLIConfig{} | ||
err := yaml.Unmarshal([]byte(resource.ResourceContent), &sliConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range sliConfig.Indicators { | ||
SLIs[key] = value | ||
} | ||
} | ||
return SLIs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/keptn/go-utils/pkg/configuration-service/models" | ||
) | ||
|
||
// TestAddResourceContentToSLIMap | ||
func TestAddResourceContentToSLIMap(t *testing.T) { | ||
SLIs := make(map[string]string) | ||
resource := &models.Resource{} | ||
resourceURI := "provider/sli.yaml" | ||
resource.ResourceURI = &resourceURI | ||
resource.ResourceContent = `--- | ||
indicators: | ||
error_rate: "builtin:service.errors.total.count:merge(0):avg?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
response_time_p50: "builtin:service.response.time:merge(0):percentile(50)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
response_time_p90: "builtin:service.response.time:merge(0):percentile(90)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
response_time_p95: "builtin:service.response.time:merge(0):percentile(95)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
throughput: "builtin:service.requestCount.total:merge(0):count?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
` | ||
SLIs, _ = addResourceContentToSLIMap(SLIs, resource) | ||
|
||
if len(SLIs) != 5 { | ||
t.Errorf("Unexpected lenght of SLI map") | ||
} | ||
} | ||
|
||
// TestAddResourceContentToSLIMap | ||
func TestAddMultipleResourceContentToSLIMap(t *testing.T) { | ||
SLIs := make(map[string]string) | ||
resource := &models.Resource{} | ||
resourceURI := "provider/sli.yaml" | ||
resource.ResourceURI = &resourceURI | ||
resource.ResourceContent = `--- | ||
indicators: | ||
error_rate: "not defined" | ||
response_time_p50: "builtin:service.response.time:merge(0):percentile(50)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
response_time_p90: "builtin:service.response.time:merge(0):percentile(90)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
response_time_p95: "builtin:service.response.time:merge(0):percentile(95)?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
throughput: "builtin:service.requestCount.total:merge(0):count?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
` | ||
SLIs, _ = addResourceContentToSLIMap(SLIs, resource) | ||
|
||
resource.ResourceContent = `--- | ||
indicators: | ||
error_rate: "builtin:service.errors.total.count:merge(0):avg?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
failure_rate: "builtin:service.requestCount.total:merge(0):count?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" | ||
` | ||
SLIs, _ = addResourceContentToSLIMap(SLIs, resource) | ||
|
||
if len(SLIs) != 6 { | ||
t.Errorf("Unexpected length of SLI map") | ||
} | ||
|
||
if SLIs["error_rate"] != "builtin:service.errors.total.count:merge(0):avg?scope=tag(keptn_project:$PROJECT),tag(keptn_stage:$STAGE),tag(keptn_service:$SERVICE),tag(keptn_deployment:$DEPLOYMENT)" { | ||
t.Errorf("Unexpected value of error_rate SLI") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package utils | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// generateStringWithSpecialChars generates a string of the given length | ||
// and containing at least one special character and digit. | ||
func generateStringWithSpecialChars(length int) string { | ||
rand.Seed(time.Now().UnixNano()) | ||
|
||
digits := "0123456789" | ||
specials := "~=+%^*/()[]{}/!@#$?|" | ||
all := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + | ||
"abcdefghijklmnopqrstuvwxyz" + | ||
digits + specials | ||
|
||
buf := make([]byte, length) | ||
buf[0] = digits[rand.Intn(len(digits))] | ||
buf[1] = specials[rand.Intn(len(specials))] | ||
|
||
for i := 2; i < length; i++ { | ||
buf[i] = all[rand.Intn(len(all))] | ||
} | ||
|
||
rand.Shuffle(len(buf), func(i, j int) { | ||
buf[i], buf[j] = buf[j], buf[i] | ||
}) | ||
|
||
str := string(buf) | ||
|
||
return str | ||
} | ||
|
||
// TestInvalidKeptnEntityName tests whether a random string containing a special character or digit | ||
// does not pass the name validation. | ||
func TestInvalidKeptnEntityName(t *testing.T) { | ||
invalidName := generateStringWithSpecialChars(8) | ||
if ValidateKeptnEntityName(invalidName) { | ||
t.Fatalf("%s starts with upper case letter(s) or contains special character(s), but passed the name validation", invalidName) | ||
} | ||
} | ||
|
||
func TestInvalidKeptnEntityName2(t *testing.T) { | ||
if ValidateKeptnEntityName("sockshop-") { | ||
t.Fatalf("project name must not end with hyphen") | ||
} | ||
} | ||
|
||
func TestValidKeptnEntityName(t *testing.T) { | ||
if !ValidateKeptnEntityName("sockshop-test") { | ||
t.Fatalf("project should be valid") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Release Notes 0.6.0 | ||
|
||
## New Features | ||
- Added result property to `TestsFinishedEventData` [#542](https://github.com/keptn/keptn/issues/542) | ||
- Added method for validating Keptn entity name [#1261](https://github.com/keptn/keptn/issues/1261) | ||
- Added utility to create namespaces [#1231](https://github.com/keptn/keptn/issues/1231) | ||
- Added helper function to get SLI config for service considering stage and project configs [#1192](https://github.com/keptn/keptn/issues/1192) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.5.0 | ||
0.6.0 |