Skip to content

feat(site): add annotation to display values of type clibase.Duration correctly #10667

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 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
rename format_duration_ns -> format_duration
  • Loading branch information
johnstcn committed Nov 15, 2023
commit 6900281a03b40a8fce20962d3b191ca6dfea7007
30 changes: 15 additions & 15 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ type HealthcheckConfig struct {
}

const (
annotationFormatDurationNS = "format_duration_ns"
annotationEnterpriseKey = "enterprise"
annotationSecretKey = "secret"
annotationFormatDuration = "format_duration"
annotationEnterpriseKey = "enterprise"
annotationSecretKey = "secret"
// annotationExternalProxies is used to mark options that are used by workspace
// proxies. This is used to filter out options that are not relevant.
annotationExternalProxies = "external_workspace_proxies"
Expand Down Expand Up @@ -631,7 +631,7 @@ when required by your organization's security policy.`,
Default: time.Minute.String(),
Value: &c.AutobuildPollInterval,
YAML: "autobuildPollInterval",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Job Hang Detector Interval",
Expand All @@ -642,7 +642,7 @@ when required by your organization's security policy.`,
Default: time.Minute.String(),
Value: &c.JobHangDetectorInterval,
YAML: "jobHangDetectorInterval",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
httpAddress,
tlsBindAddress,
Expand Down Expand Up @@ -1336,7 +1336,7 @@ when required by your organization's security policy.`,
Value: &c.Provisioner.DaemonPollInterval,
Group: &deploymentGroupProvisioning,
YAML: "daemonPollInterval",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Poll Jitter",
Expand All @@ -1347,7 +1347,7 @@ when required by your organization's security policy.`,
Value: &c.Provisioner.DaemonPollJitter,
Group: &deploymentGroupProvisioning,
YAML: "daemonPollJitter",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Force Cancel Interval",
Expand All @@ -1358,7 +1358,7 @@ when required by your organization's security policy.`,
Value: &c.Provisioner.ForceCancelInterval,
Group: &deploymentGroupProvisioning,
YAML: "forceCancelInterval",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Provisioner Daemon Pre-shared Key (PSK)",
Expand Down Expand Up @@ -1512,7 +1512,7 @@ when required by your organization's security policy.`,
Value: &c.MaxTokenLifetime,
Group: &deploymentGroupNetworkingHTTP,
YAML: "maxTokenLifetime",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Enable swagger endpoint",
Expand Down Expand Up @@ -1620,7 +1620,7 @@ when required by your organization's security policy.`,
Hidden: true,
Default: time.Hour.String(),
Value: &c.MetricsCacheRefreshInterval,
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Agent Stat Refresh Interval",
Expand All @@ -1630,7 +1630,7 @@ when required by your organization's security policy.`,
Hidden: true,
Default: (30 * time.Second).String(),
Value: &c.AgentStatRefreshInterval,
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Agent Fallback Troubleshooting URL",
Expand Down Expand Up @@ -1697,7 +1697,7 @@ when required by your organization's security policy.`,
Value: &c.SessionDuration,
Group: &deploymentGroupNetworkingHTTP,
YAML: "sessionDuration",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Disable Session Expiry Refresh",
Expand Down Expand Up @@ -1800,7 +1800,7 @@ Write out the current server config as YAML to stdout.`,
Value: &c.ProxyHealthStatusInterval,
Group: &deploymentGroupNetworkingHTTP,
YAML: "proxyHealthInterval",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Default Quiet Hours Schedule",
Expand Down Expand Up @@ -1832,7 +1832,7 @@ Write out the current server config as YAML to stdout.`,
Value: &c.Healthcheck.Refresh,
Group: &deploymentGroupIntrospectionHealthcheck,
YAML: "refresh",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
{
Name: "Health Check Threshold: Database",
Expand All @@ -1843,7 +1843,7 @@ Write out the current server config as YAML to stdout.`,
Value: &c.Healthcheck.ThresholdDatabase,
Group: &deploymentGroupIntrospectionHealthcheck,
YAML: "thresholdDatabase",
Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),
Annotations: clibase.Annotations{}.Mark(annotationFormatDuration, "true"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions codersdk/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ func TestDeploymentValues_DurationFormatNanoseconds(t *testing.T) {
// Just make sure the annotation is set.
// If someone wants to not format a duration, they can
// explicitly set the annotation to false.
if s.Annotations.IsSet("format_duration_ns") {
if s.Annotations.IsSet("format_duration") {
continue
}
t.Logf("Option %q is a duration but does not have the format_duration_ns annotation.", s.Name)
t.Logf("Option %q is a duration but does not have the format_duration annotation.", s.Name)
t.Logf("To fix this, add the following to the option declaration:")
t.Logf(`Annotations: clibase.Annotations{}.Mark(annotationFormatDurationNS, "true"),`)
t.FailNow()
Expand Down
12 changes: 6 additions & 6 deletions site/src/components/DeploySettingsLayout/optionValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Max Token Lifetime",
value: 3600 * 1e9,
annotations: { format_duration_ns: "false" },
annotations: { format_duration: "false" },
},
expected: 3600000000000,
},
Expand All @@ -30,7 +30,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Max Token Lifetime",
value: 24 * 3600 * 1e9,
annotations: { format_duration_ns: "true" },
annotations: { format_duration: "true" },
},
expected: "1 day",
},
Expand All @@ -39,7 +39,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Session Duration",
value: 3600 * 1e9,
annotations: { format_duration_ns: "falsae" },
annotations: { format_duration: "some non-truthful value" },
},
expected: 3600000000000,
},
Expand All @@ -48,7 +48,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Session Duration",
value: 24 * 3600 * 1e9,
annotations: { format_duration_ns: "true" },
annotations: { format_duration: "true" },
},
expected: "1 day",
},
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Some Go Duration We Want To Show As A String",
value: 30 * 1e9,
annotations: { format_duration_ns: "true" },
annotations: { format_duration: "true" },
},
expected: "30 seconds",
},
Expand All @@ -122,7 +122,7 @@ describe("optionValue", () => {
...defaultOption,
name: "Some Other Go Duration We Want To Just Display As A Number",
value: 30 * 1e9,
annotations: { format_duration_ns: "false" },
annotations: { format_duration: "false" },
},
expected: 30000000000,
},
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/DeploySettingsLayout/optionValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function optionValue(
continue; // skip if not explicitly true
}
switch (k) {
case "format_duration_ns":
case "format_duration":
return formatDuration(
// intervalToDuration takes ms, so convert nanoseconds to ms
intervalToDuration({
Expand Down