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

fix(site/src/api/typesGenerated): generate HealthSection enums#11049

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 1 commit intomainfromcj/healthsections-typegen
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
23 changes: 20 additions & 3 deletionscoderd/apidoc/docs.go
View file
Open in desktop

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

17 changes: 14 additions & 3 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

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

10 changes: 5 additions & 5 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -413,25 +413,25 @@ func New(options *Options) *API {
Database: healthcheck.DatabaseReportOptions{
DB: options.Database,
Threshold: options.DeploymentValues.Healthcheck.ThresholdDatabase.Value(),
Dismissed: slices.Contains(dismissedHealthchecks,healthcheck.SectionDatabase),
Dismissed: slices.Contains(dismissedHealthchecks,codersdk.HealthSectionDatabase),
},
Websocket: healthcheck.WebsocketReportOptions{
AccessURL: options.AccessURL,
APIKey: apiKey,
Dismissed: slices.Contains(dismissedHealthchecks,healthcheck.SectionWebsocket),
Dismissed: slices.Contains(dismissedHealthchecks,codersdk.HealthSectionWebsocket),
},
AccessURL: healthcheck.AccessURLReportOptions{
AccessURL: options.AccessURL,
Dismissed: slices.Contains(dismissedHealthchecks,healthcheck.SectionAccessURL),
Dismissed: slices.Contains(dismissedHealthchecks,codersdk.HealthSectionAccessURL),
},
DerpHealth: derphealth.ReportOptions{
DERPMap: api.DERPMap(),
Dismissed: slices.Contains(dismissedHealthchecks,healthcheck.SectionDERP),
Dismissed: slices.Contains(dismissedHealthchecks,codersdk.HealthSectionDERP),
},
WorkspaceProxy: healthcheck.WorkspaceProxyReportOptions{
CurrentVersion: buildinfo.Version(),
WorkspaceProxiesFetchUpdater: *(options.WorkspaceProxiesFetchUpdater).Load(),
Dismissed: slices.Contains(dismissedHealthchecks,healthcheck.SectionWorkspaceProxy),
Dismissed: slices.Contains(dismissedHealthchecks,codersdk.HealthSectionWorkspaceProxy),
},
})
}
Expand Down
5 changes: 3 additions & 2 deletionscoderd/database/types.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/codersdk"
)

// AuditOAuthConvertState is never stored in the database. It is stored in a cookie
Expand All@@ -24,8 +25,8 @@ type AuditOAuthConvertState struct {
}

type HealthSettings struct {
ID uuid.UUID `db:"id" json:"id"`
DismissedHealthchecks []string `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
ID uuid.UUID`db:"id" json:"id"`
DismissedHealthchecks []codersdk.HealthSection `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
}

type Actions []rbac.Action
Expand Down
9 changes: 5 additions & 4 deletionscoderd/debug.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -147,7 +147,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
}

if len(settings.DismissedHealthchecks) == 0 {
settings.DismissedHealthchecks = []string{}
settings.DismissedHealthchecks = []codersdk.HealthSection{}
}

httpapi.Write(r.Context(), rw, http.StatusOK, settings)
Expand DownExpand Up@@ -218,6 +218,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
Action: database.AuditActionWrite,
})
defer commitAudit()

aReq.New = database.HealthSettings{
ID: uuid.New(),
DismissedHealthchecks: settings.DismissedHealthchecks,
Expand All@@ -237,7 +238,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ

func validateHealthSettings(settings codersdk.HealthSettings) error {
for _, dismissed := range settings.DismissedHealthchecks {
ok := slices.Contains(healthcheck.Sections, dismissed)
ok := slices.Contains(codersdk.HealthSections, dismissed)
if !ok {
return xerrors.Errorf("unknown healthcheck section: %s", dismissed)
}
Expand All@@ -257,8 +258,8 @@ func validateHealthSettings(settings codersdk.HealthSettings) error {
// @x-apidocgen {"skip": true}
func _debugws(http.ResponseWriter, *http.Request) {} //nolint:unused

func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []string {
dismissedHealthchecks := []string{}
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []codersdk.HealthSection {
dismissedHealthchecks := []codersdk.HealthSection{}
settingsJSON, err := db.GetHealthSettings(ctx)
if err == nil {
var settings codersdk.HealthSettings
Expand Down
10 changes: 5 additions & 5 deletionscoderd/debug_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -251,7 +251,7 @@ func TestHealthSettings(t *testing.T) {
require.NoError(t, err)

// then
require.Equal(t, codersdk.HealthSettings{DismissedHealthchecks: []string{}}, settings)
require.Equal(t, codersdk.HealthSettings{DismissedHealthchecks: []codersdk.HealthSection{}}, settings)
})

t.Run("DismissSection", func(t *testing.T) {
Expand All@@ -265,7 +265,7 @@ func TestHealthSettings(t *testing.T) {
_ = coderdtest.CreateFirstUser(t, adminClient)

expected := codersdk.HealthSettings{
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
}

// when: dismiss "derp" and "websocket"
Expand All@@ -289,14 +289,14 @@ func TestHealthSettings(t *testing.T) {
_ = coderdtest.CreateFirstUser(t, adminClient)

initial := codersdk.HealthSettings{
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
}

err := adminClient.PutHealthSettings(ctx, initial)
require.NoError(t, err)

expected := codersdk.HealthSettings{
DismissedHealthchecks: []string{healthcheck.SectionDERP},
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP},
}

// when: undismiss "websocket"
Expand All@@ -320,7 +320,7 @@ func TestHealthSettings(t *testing.T) {
_ = coderdtest.CreateFirstUser(t, adminClient)

expected := codersdk.HealthSettings{
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
}

err := adminClient.PutHealthSettings(ctx, expected)
Expand Down
25 changes: 8 additions & 17 deletionscoderd/healthcheck/healthcheck.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,18 +9,9 @@ import (
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
"github.com/coder/coder/v2/coderd/healthcheck/health"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
)

const (
SectionDERP string = "DERP"
SectionAccessURL string = "AccessURL"
SectionWebsocket string = "Websocket"
SectionDatabase string = "Database"
SectionWorkspaceProxy string = "WorkspaceProxy"
)

var Sections = []string{SectionAccessURL, SectionDatabase, SectionDERP, SectionWebsocket, SectionWorkspaceProxy}

type Checker interface {
DERP(ctx context.Context, opts *derphealth.ReportOptions) derphealth.Report
AccessURL(ctx context.Context, opts *AccessURLReportOptions) AccessURLReport
Expand All@@ -39,7 +30,7 @@ type Report struct {
// Severity indicates the status of Coder health.
Severity health.Severity `json:"severity" enums:"ok,warning,error"`
// FailingSections is a list of sections that have failed their healthcheck.
FailingSections []string `json:"failing_sections"`
FailingSections []codersdk.HealthSection `json:"failing_sections"`

DERP derphealth.Report `json:"derp"`
AccessURL AccessURLReport `json:"access_url"`
Expand DownExpand Up@@ -162,21 +153,21 @@ func Run(ctx context.Context, opts *ReportOptions) *Report {
wg.Wait()

report.Time = time.Now()
report.FailingSections = []string{}
report.FailingSections = []codersdk.HealthSection{}
if !report.DERP.Healthy {
report.FailingSections = append(report.FailingSections,SectionDERP)
report.FailingSections = append(report.FailingSections,codersdk.HealthSectionDERP)
}
if !report.AccessURL.Healthy {
report.FailingSections = append(report.FailingSections,SectionAccessURL)
report.FailingSections = append(report.FailingSections,codersdk.HealthSectionAccessURL)
}
if !report.Websocket.Healthy {
report.FailingSections = append(report.FailingSections,SectionWebsocket)
report.FailingSections = append(report.FailingSections,codersdk.HealthSectionWebsocket)
}
if !report.Database.Healthy {
report.FailingSections = append(report.FailingSections,SectionDatabase)
report.FailingSections = append(report.FailingSections,codersdk.HealthSectionDatabase)
}
if !report.WorkspaceProxy.Healthy {
report.FailingSections = append(report.FailingSections,SectionWorkspaceProxy)
report.FailingSections = append(report.FailingSections,codersdk.HealthSectionWorkspaceProxy)
}

report.Healthy = len(report.FailingSections) == 0
Expand Down
31 changes: 16 additions & 15 deletionscoderd/healthcheck/healthcheck_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ import (
"github.com/coder/coder/v2/coderd/healthcheck"
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
"github.com/coder/coder/v2/coderd/healthcheck/health"
"github.com/coder/coder/v2/codersdk"
)

type testChecker struct {
Expand DownExpand Up@@ -47,7 +48,7 @@ func TestHealthcheck(t *testing.T) {
checker *testChecker
healthy bool
severity health.Severity
failingSections []string
failingSections []codersdk.HealthSection
}{{
name: "OK",
checker: &testChecker{
Expand All@@ -74,7 +75,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: true,
severity: health.SeverityOK,
failingSections: []string{},
failingSections: []codersdk.HealthSection{},
}, {
name: "DERPFail",
checker: &testChecker{
Expand All@@ -101,7 +102,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []string{healthcheck.SectionDERP},
failingSections: []codersdk.HealthSection{codersdk.HealthSectionDERP},
}, {
name: "DERPWarning",
checker: &testChecker{
Expand DownExpand Up@@ -129,7 +130,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: true,
severity: health.SeverityWarning,
failingSections: []string{},
failingSections: []codersdk.HealthSection{},
}, {
name: "AccessURLFail",
checker: &testChecker{
Expand All@@ -156,7 +157,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityWarning,
failingSections: []string{healthcheck.SectionAccessURL},
failingSections: []codersdk.HealthSection{codersdk.HealthSectionAccessURL},
}, {
name: "WebsocketFail",
checker: &testChecker{
Expand All@@ -183,7 +184,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []string{healthcheck.SectionWebsocket},
failingSections: []codersdk.HealthSection{codersdk.HealthSectionWebsocket},
}, {
name: "DatabaseFail",
checker: &testChecker{
Expand All@@ -210,7 +211,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []string{healthcheck.SectionDatabase},
failingSections: []codersdk.HealthSection{codersdk.HealthSectionDatabase},
}, {
name: "ProxyFail",
checker: &testChecker{
Expand All@@ -237,7 +238,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityError,
healthy: false,
failingSections: []string{healthcheck.SectionWorkspaceProxy},
failingSections: []codersdk.HealthSection{codersdk.HealthSectionWorkspaceProxy},
}, {
name: "ProxyWarn",
checker: &testChecker{
Expand DownExpand Up@@ -265,7 +266,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityWarning,
healthy: true,
failingSections: []string{},
failingSections: []codersdk.HealthSection{},
}, {
name: "AllFail",
healthy: false,
Expand All@@ -292,12 +293,12 @@ func TestHealthcheck(t *testing.T) {
},
},
severity: health.SeverityError,
failingSections: []string{
healthcheck.SectionDERP,
healthcheck.SectionAccessURL,
healthcheck.SectionWebsocket,
healthcheck.SectionDatabase,
healthcheck.SectionWorkspaceProxy,
failingSections: []codersdk.HealthSection{
codersdk.HealthSectionDERP,
codersdk.HealthSectionAccessURL,
codersdk.HealthSectionWebsocket,
codersdk.HealthSectionDatabase,
codersdk.HealthSectionWorkspaceProxy,
},
}} {
c := c
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp