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

add templaterender timeout #476

Merged
merged 1 commit into from
Aug 16, 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
15 changes: 15 additions & 0 deletions config/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const (

// BuildMRCheckTimeoutKey represent build merge request status check timeout key
BuildMRCheckTimeoutKey = "build.mergerequest.checkTimeout"

// TemplateRenderCheckTimeoutKey represent templatrender timeout key
TemplateRenderCheckTimeoutKey = "templateRender.checkTimeout"

// TemplateRenderRetentionTimeKey represent the config key for how long templatrender will remain
// retentionTime seems like a better name than delayAfterCompleted so that we use rententionTime here
TemplateRenderRetentionTimeKey = "templateRender.retentionTime"
)

const (
Expand All @@ -62,6 +69,12 @@ const (

// DefaultMRCheckTimeout represent default timeout for merge request status check
DefaultMRCheckTimeout FeatureValue = "10m"

// DefaultTemplateRenderCheckTimeout represent default timeout for templaterender check
DefaultTemplateRenderCheckTimeout FeatureValue = "30s"

// DefaultTemplateRenderRetentionTime represents default duration how long the templatrender will remain
DefaultTemplateRenderRetentionTime FeatureValue = "30m"
)

// defaultFeatureValue defines the default value for the feature switch.
Expand All @@ -72,6 +85,8 @@ var defaultFeatureValue = map[string]FeatureValue{
PrunerDelayAfterCompletedFeatureKey: DefaultPrunerDelayAfterCompleted,
PrunerKeepFeatureKey: DefaultPrunerKeep,
BuildMRCheckTimeoutKey: DefaultMRCheckTimeout,
TemplateRenderCheckTimeoutKey: DefaultTemplateRenderCheckTimeout,
TemplateRenderRetentionTimeKey: DefaultTemplateRenderRetentionTime,
}

// FeatureFlags holds the features configurations
Expand Down
23 changes: 23 additions & 0 deletions config/feature_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ limitations under the License.
package config

import (
"context"
"fmt"
"strconv"
"time"

"knative.dev/pkg/logging"
)

// FeatureValue definition of FeatureValue feature value
Expand Down Expand Up @@ -56,3 +59,23 @@ func (f FeatureValue) AsBool() (bool, error) {
}
return v, nil
}

// GetDurationConfig return duration configuration store in manager and return default if not exist
func GetDurationConfig(ctx context.Context, key string, defaultDuration time.Duration) time.Duration {
log := logging.FromContext(ctx)

var retention time.Duration
var err error

manager := KatanomiConfigManager(ctx)
if manager != nil {
retention, err = manager.GetFeatureFlag(key).AsDuration()
if err != nil {
log.Errorw("failed to get duration time", "key", key, "error", err)
retention = defaultDuration
}
} else {
retention = defaultDuration
}
return retention
}
35 changes: 35 additions & 0 deletions config/feature_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ limitations under the License.
package config

import (
"context"
"testing"
"time"

. "github.com/onsi/gomega"
)

func TestFeatureValue_AsInt(t *testing.T) {
Expand Down Expand Up @@ -89,3 +92,35 @@ func TestFeatureValue_AsBool(t *testing.T) {
})
}
}

func Test_GetDurationConfig(t *testing.T) {
RegisterTestingT(t)

for _, c := range []struct {
description string
context context.Context
key string
defaultTime time.Duration
expect time.Duration
}{
{
description: "return default duration",
context: context.Background(),
key: "not exist",
defaultTime: time.Hour,
expect: time.Hour,
},
{
description: "return default config duration",
context: WithKatanomiConfigManager(context.Background(), &Manager{}),
key: TemplateRenderRetentionTimeKey,
defaultTime: time.Hour,
expect: 30 * time.Minute,
},
} {
t.Logf("<=== starting %s...", c.description)
Expect(GetDurationConfig(c.context, c.key, c.defaultTime)).To(Equal(c.expect))
t.Logf("===> passed %s...", c.description)
}

}