Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add --experiments flag#5767

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 17 commits intomainfromcj/config-experimental-multiple-values
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
76c7b91
feat: support multiple values for --experimental
johnstcnJan 16, 2023
626d81b
develop.sh: allow passing additional args to backend API via -- arg1=…
johnstcnJan 18, 2023
d93a373
fix swaggerparser test
johnstcnJan 18, 2023
e82c306
make fmt
johnstcnJan 18, 2023
047771c
require AuthN on /api/v2/experiments
johnstcnJan 18, 2023
3ba27ea
fixup! require AuthN on /api/v2/experiments
johnstcnJan 18, 2023
3ebb778
fix nits
johnstcnJan 18, 2023
2aeb93e
add type alias for codersdk.Experiment
johnstcnJan 18, 2023
53d92d7
make it clear that Entitlements.Experimental is deprecated
johnstcnJan 18, 2023
ef0cbc3
remove unnecessary types as they are now autogenerated
johnstcnJan 18, 2023
8fdb21b
apply suggestions from code review
johnstcnJan 18, 2023
0cb9a6a
fixup! apply suggestions from code review
johnstcnJan 18, 2023
44e9638
warn about dragons
johnstcnJan 18, 2023
6c32aa5
fix apidoc type
johnstcnJan 18, 2023
1cbaaf7
codersdk.Experiments no longer needs be flaggable or special-cased in…
johnstcnJan 18, 2023
67d07f3
lower-case when ingesting and comparing experiments
johnstcnJan 18, 2023
196b263
update apitypings unit tests
johnstcnJan 18, 2023
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
21 changes: 15 additions & 6 deletionscli/deployment/config.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -446,10 +446,19 @@ func newConfig() *codersdk.DeploymentConfig {
Default: 512,
},
},
// DEPRECATED: use Experiments instead.
Experimental: &codersdk.DeploymentConfigField[bool]{
Name: "Experimental",
Usage: "Enable experimental features. Experimental features are not ready for production.",
Flag: "experimental",
Name: "Experimental",
Usage: "Enable experimental features. Experimental features are not ready for production.",
Flag: "experimental",
Default: false,
Hidden: true,
},
Comment on lines 450 to +456
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should print a deprecation notice at the top of server.go. Or we could implement it as a "Deprecated string" on DeploymentConfigField

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's hidden. So it should not matter right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well to notify old deployments that still have the variable set that they need to unset it or it won't work soon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I mean printing a notice if the flag or env var is present

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

warning gets printed ininitExperiments at the bottom ofcoderd.go; folks may or may not be looking for it though

Experiments: &codersdk.DeploymentConfigField[[]string]{
Name: "Experiments",
Usage: "Enable one or more experiments. These are not ready for production. Separate multiple experiments with commas, or enter '*' to opt-in to all available experiments.",
Flag: "experiments",
Default: []string{},
},
UpdateCheck: &codersdk.DeploymentConfigField[bool]{
Name: "Update Check",
Expand DownExpand Up@@ -557,12 +566,12 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
// with a comma, but Viper only supports with a space. This
// is a small hack around it!
rawSlice := reflect.ValueOf(vip.GetStringSlice(prefix)).Interface()
slice, ok := rawSlice.([]string)
stringSlice, ok := rawSlice.([]string)
if !ok {
panic(fmt.Sprintf("string slice is of type %T", rawSlice))
}
value := make([]string, 0, len(slice))
for _, entry := rangeslice {
value := make([]string, 0, len(stringSlice))
for _, entry := rangestringSlice {
value = append(value, strings.Split(entry, ",")...)
}
val.FieldByName("Value").Set(reflect.ValueOf(value))
Expand Down
17 changes: 17 additions & 0 deletionscli/deployment/config_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -232,6 +232,23 @@ func TestConfig(t *testing.T) {
require.Equal(t, config.Prometheus.Enable.Value, true)
require.Equal(t, config.Prometheus.Address.Value, config.Prometheus.Address.Default)
},
}, {
Name: "Experiments - no features",
Env: map[string]string{
"CODER_EXPERIMENTS": "",
},
Valid: func(config *codersdk.DeploymentConfig) {
require.Empty(t, config.Experiments.Value)
},
}, {
Name: "Experiments - multiple features",
Env: map[string]string{
"CODER_EXPERIMENTS": "foo,bar",
},
Valid: func(config *codersdk.DeploymentConfig) {
expected := []string{"foo", "bar"}
require.ElementsMatch(t, expected, config.Experiments.Value)
},
}} {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletionscli/testdata/coder_server_--help.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,10 +61,12 @@ Flags:
Consumes
$CODER_DERP_SERVER_STUN_ADDRESSES
(default [stun.l.google.com:19302])
--experimental Enable experimental features.
Experimental features are not ready for
production.
Consumes $CODER_EXPERIMENTAL
--experiments strings Enable one or more experiments. These are
not ready for production. Separate
multiple experiments with commas, or
enter '*' to opt-in to all available
experiments.
Consumes $CODER_EXPERIMENTS
-h, --help help for server
--http-address string HTTP bind address of the server. Unset to
disable the HTTP endpoint.
Expand Down
48 changes: 47 additions & 1 deletioncoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

40 changes: 39 additions & 1 deletioncoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

35 changes: 35 additions & 0 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ import (
"net/url"
"path/filepath"
"regexp"
"strings"
"sync"
"sync/atomic"
"time"
Expand DownExpand Up@@ -52,6 +53,7 @@ import (
"github.com/coder/coder/coderd/telemetry"
"github.com/coder/coder/coderd/tracing"
"github.com/coder/coder/coderd/updatecheck"
"github.com/coder/coder/coderd/util/slice"
"github.com/coder/coder/coderd/wsconncache"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisionerd/proto"
Expand DownExpand Up@@ -220,6 +222,7 @@ func New(options *Options) *API {
},
metricsCache: metricsCache,
Auditor: atomic.Pointer[audit.Auditor]{},
Experiments: initExperiments(options.Logger, options.DeploymentConfig.Experiments.Value, options.DeploymentConfig.Experimental.Value),
}
if options.UpdateCheckOptions != nil {
api.updateChecker = updatecheck.New(
Expand DownExpand Up@@ -348,6 +351,10 @@ func New(options *Options) *API {
r.Post("/csp/reports", api.logReportCSPViolations)

r.Get("/buildinfo", buildInfo)
r.Route("/experiments", func(r chi.Router) {
r.Use(apiKeyMiddleware)
r.Get("/", api.handleExperimentsGet)
})
r.Get("/updatecheck", api.updateCheck)
r.Route("/config", func(r chi.Router) {
r.Use(apiKeyMiddleware)
Expand DownExpand Up@@ -646,6 +653,10 @@ type API struct {
metricsCache *metricscache.Cache
workspaceAgentCache *wsconncache.Cache
updateChecker *updatecheck.Checker

// Experiments contains the list of experiments currently enabled.
// This is used to gate features that are not yet ready for production.
Experiments codersdk.Experiments
}

// Close waits for all WebSocket connections to drain before returning.
Expand DownExpand Up@@ -752,3 +763,27 @@ func (api *API) CreateInMemoryProvisionerDaemon(ctx context.Context, debounce ti

return proto.NewDRPCProvisionerDaemonClient(clientSession), nil
}

// nolint:revive
func initExperiments(log slog.Logger, raw []string, legacyAll bool) codersdk.Experiments {
exps := make([]codersdk.Experiment, 0, len(raw))
for _, v := range raw {
switch v {
case "*":
exps = append(exps, codersdk.ExperimentsAll...)
default:
ex := codersdk.Experiment(strings.ToLower(v))
if !slice.Contains(codersdk.ExperimentsAll, ex) {
log.Warn(context.Background(), "🐉 HERE BE DRAGONS: opting into hidden experiment", slog.F("experiment", ex))
}
exps = append(exps, ex)
}
}

// --experiments takes precedence over --experimental. It's deprecated.
if legacyAll && len(raw) == 0 {
log.Warn(context.Background(), "--experimental is deprecated, use --experiments='*' instead")
exps = append(exps, codersdk.ExperimentsAll...)
}
return exps
}
1 change: 1 addition & 0 deletionscoderd/coderdtest/authorize.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,6 +48,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
"GET:/healthz": {NoAuthorize: true},
"GET:/api/v2": {NoAuthorize: true},
"GET:/api/v2/buildinfo": {NoAuthorize: true},
"GET:/api/v2/experiments": {NoAuthorize: true}, // This route requires AuthN, but not AuthZ.
"GET:/api/v2/updatecheck": {NoAuthorize: true},
"GET:/api/v2/users/first": {NoAuthorize: true},
"POST:/api/v2/users/first": {NoAuthorize: true},
Expand Down
1 change: 0 additions & 1 deletioncoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,7 +85,6 @@ type Options struct {
AppHostname string
AWSCertificates awsidentity.Certificates
Authorizer rbac.Authorizer
Experimental bool
AzureCertificates x509.VerifyOptions
GithubOAuth2Config *coderd.GithubOAuth2Config
RealIPConfig *httpmw.RealIPConfig
Expand Down
19 changes: 19 additions & 0 deletionscoderd/experiments.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
package coderd

import (
"net/http"

"github.com/coder/coder/coderd/httpapi"
)

// @Summary Get experiments
// @ID get-experiments
// @Security CoderSessionToken
// @Produce json
// @Tags General
// @Success 200 {array} codersdk.Experiment
// @Router /experiments [get]
func (api *API) handleExperimentsGet(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp