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: track resource replacements when claiming a prebuilt workspace#17571

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
dannykopping merged 38 commits intomainfromdk/logreplacements
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
38 commits
Select commitHold shift + click to select a range
b32923a
feat: log resource replacements
dannykoppingApr 25, 2025
0b0830f
feat: show terraform state drift diff in build logs
dannykoppingApr 25, 2025
256395a
feat: only highlight lines which mention replacement
dannykoppingApr 25, 2025
61ef61a
feat: notify template admins when prebuild claim results in resource …
dannykoppingApr 25, 2025
a66559f
chore: appease linter
dannykoppingApr 25, 2025
222892b
chore: fix notifications test
dannykoppingApr 25, 2025
f34e011
fix: don't panic
dannykoppingApr 28, 2025
5168c01
fix: renaming type
dannykoppingApr 28, 2025
41e5e0c
chore: updating migration numbers
dannykoppingMay 6, 2025
b29e8fa
chore: minor touch-ups
dannykoppingMay 6, 2025
b31ed5e
feat: add resource replacements metric
dannykoppingMay 7, 2025
adf98d2
feat: add resource replacement notification
dannykoppingMay 7, 2025
f24aef0
make lint; make fmt
dannykoppingMay 7, 2025
70f9a53
chore: adding tests
dannykoppingMay 8, 2025
1e8385d
feat: pass flag to terraform provider when prebuilt workspace claimed
dannykoppingMay 9, 2025
d0f00ce
chore: update provider, add test for is_prebuild_claim
dannykoppingMay 12, 2025
11a2c5a
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 12, 2025
ce63b24
Merge branch 'dk/is-prebuild-claim' of github.com:/coder/coder into d…
dannykoppingMay 12, 2025
d2c5d43
chore: replace GetTemplatePresetsByID with GetPresetByID
dannykoppingMay 12, 2025
22d82a4
chore: correcting docs link
dannykoppingMay 12, 2025
5209aae
Merge branch 'main' of github.com:/coder/coder into dk/logreplacement
dannykoppingMay 12, 2025
39ce658
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 12, 2025
ac5655f
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 12, 2025
82c3f58
chore: note provisioner API change
dannykoppingMay 12, 2025
7577a90
chore: fixups
dannykoppingMay 13, 2025
a893b79
chore: adding note about immutable resources
dannykoppingMay 13, 2025
d9c906a
chore: review feedback
dannykoppingMay 13, 2025
471198a
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 13, 2025
7d694e6
chore: merge conflicts
dannykoppingMay 13, 2025
6b7a8b7
chore: fix 'is not iterable' bullshit
dannykoppingMay 13, 2025
5df2cb3
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 14, 2025
6d1c3ea
chore: rename migrations
dannykoppingMay 14, 2025
5f62702
chore: set notifications manager before enterprise server initializes…
dannykoppingMay 14, 2025
f74d799
chore: completing refactor since https://github.com/coder/coder/pull/…
dannykoppingMay 14, 2025
971f65c
chore: remove unnecessary atomicity since map is protected by mutex a…
dannykoppingMay 14, 2025
bc362b0
chore: appeasing linter's Very Important Suggestion
dannykoppingMay 14, 2025
4fbd356
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykoppingMay 14, 2025
b9eb8be
chore: remove old replacement logging
dannykoppingMay 14, 2025
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
PrevPrevious commit
NextNext commit
chore: review feedback
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
  • Loading branch information
@dannykopping
dannykopping committedMay 13, 2025
commitd9c906a49331da79f2ee8af982b563f448ac28b7
5 changes: 3 additions & 2 deletionscoderd/provisionerdserver/provisionerdserver.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@ import (
protobuf "google.golang.org/protobuf/proto"

"cdr.dev/slog"

"github.com/coder/coder/v2/codersdk/drpcsdk"

"github.com/coder/quartz"
Expand DownExpand Up@@ -1729,8 +1730,8 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
// Track resource replacements, if there are any.
orchestrator := s.PrebuildsOrchestrator.Load()
if resourceReplacements := completed.GetWorkspaceBuild().GetResourceReplacements(); orchestrator != nil && len(resourceReplacements) > 0 {
// Fire and forget.
go (*orchestrator).TrackResourceReplacement(context.Background(), workspace.ID, workspaceBuild.ID, resourceReplacements)
// Fire and forget. Bind to the lifecycle of the server so shutdowns are handled gracefully.
go (*orchestrator).TrackResourceReplacement(s.lifecycleCtx, workspace.ID, workspaceBuild.ID, resourceReplacements)
}
}

Expand Down
9 changes: 4 additions & 5 deletionsenterprise/coderd/prebuilds/reconcile.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package prebuilds
import (
"context"
"database/sql"
"errors"
"fmt"
"math"
"strings"
Expand DownExpand Up@@ -631,7 +632,6 @@ func (c *StoreReconciler) provision(
}

func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement) {
// Set authorization context since this may be called in the background (i.e. with a bare context).
// nolint:gocritic // Necessary to query all the required data.
ctx = dbauthz.AsSystemRestricted(ctx)
// Since this may be called in a fire-and-forget fashion, we need to give up at some point.
Expand DownExpand Up@@ -716,8 +716,7 @@ func (c *StoreReconciler) trackResourceReplacement(ctx context.Context, workspac
return xerrors.Errorf("fetch template admins: %w", err)
}

var errs multierror.Error

var notifErr error
for _, templateAdmin := range templateAdmins {
if _, err := (*c.notifEnq.Load()).EnqueueWithData(ctx, templateAdmin.ID, notifications.TemplateWorkspaceResourceReplaced,
map[string]string{
Expand All@@ -735,10 +734,10 @@ func (c *StoreReconciler) trackResourceReplacement(ctx context.Context, workspac
// Associate this notification with all the related entities.
workspace.ID, workspace.OwnerID, workspace.TemplateID, templateVersion.ID, prebuildPreset.ID, workspace.OrganizationID,
); err != nil {
errs.Errors =append(errs.Errors,xerrors.Errorf("send notification to %q: %w", templateAdmin.ID.String(), err))
notifErr =errors.Join(xerrors.Errorf("send notification to %q: %w", templateAdmin.ID.String(), err))
continue
}
}

returnerrs.ErrorOrNil()
returnnotifErr
}
9 changes: 6 additions & 3 deletionsprovisioner/terraform/executor.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -416,7 +416,7 @@ func (e *executor) parsePlan(ctx, killCtx context.Context, planfilePath string)
// logDrift must only be called while the lock is held.
// It will log the output of `terraform show`, which will show which resources have drifted from the known state.
func (e *executor) logDrift(ctx, killCtx context.Context, planfilePath string, logr logSink) {
stdout, stdoutDone := resourceReplaceLogWriter(logr)
stdout, stdoutDone := resourceReplaceLogWriter(logr, e.logger)
stderr, stderrDone := logWriter(logr, proto.LogLevel_ERROR)
defer func() {
_ = stdout.Close()
Expand All@@ -436,9 +436,9 @@ func (e *executor) logDrift(ctx, killCtx context.Context, planfilePath string, l
//
// The WriteCloser must be closed by the caller to end logging, after which the returned channel will be closed to
// indicate that logging of the written data has finished. Failure to close the WriteCloser will leak a goroutine.
func resourceReplaceLogWriter(sink logSink) (io.WriteCloser, <-chanany) {
func resourceReplaceLogWriter(sink logSink, logger slog.Logger) (io.WriteCloser, <-chanstruct{}) {
r, w := io.Pipe()
done := make(chanany)
done := make(chanstruct{})

go func() {
defer close(done)
Expand All@@ -455,6 +455,9 @@ func resourceReplaceLogWriter(sink logSink) (io.WriteCloser, <-chan any) {

sink.ProvisionLog(level, string(line))
}
if err := scanner.Err(); err != nil {
logger.Error(context.Background(), "failed to read terraform log", slog.Error(err))
}
}()
return w, done
}
Expand Down
21 changes: 11 additions & 10 deletionsprovisioner/terraform/resource_replacements.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,21 +59,22 @@ func findResourceReplacements(plan *tfjson.Plan) resourceReplacements {
}

// Replacements found, problem!
for _, p := range ch.Change.ReplacePaths {
var path string
switch p := p.(type) {
for _, val := range ch.Change.ReplacePaths {
var pathStr string
// Each path needs to be coerced into a string. All types except []interface{} can be coerced using fmt.Sprintf.
switch path := val.(type) {
case []interface{}:
segs := p
list := make([]string, 0, len(segs))
for _,s := rangesegs {
list = append(list, fmt.Sprintf("%v",s))
// Found a slice of paths; coerce to string and join by ".".
segments := make([]string, 0, len(path))
for _,seg := rangepath {
segments = append(segments, fmt.Sprintf("%v",seg))
}
path = strings.Join(list, ".")
pathStr = strings.Join(segments, ".")
default:
path = fmt.Sprintf("%v",p)
pathStr = fmt.Sprintf("%v",path)
}

replacements[ch.Address] = append(replacements[ch.Address],path)
replacements[ch.Address] = append(replacements[ch.Address],pathStr)
}
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp