Skip to content

ci: Replace DataDog CI with custom upload script #169

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 5 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 12 additions & 30 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,45 +159,27 @@ jobs:
-covermode=atomic -coverprofile="gotests.coverage"
-timeout=3m -count=5 -race -short -parallel=2

- name: Upload DataDog Trace
if: (success() || failure()) && github.actor != 'dependabot[bot]'
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DD_DATABASE: fake
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: go run scripts/datadog-cireport/main.go gotests.xml

- name: Test with PostgreSQL Database
if: runner.os == 'Linux'
run: DB=true gotestsum --junitfile="gotests.xml" --packages="./..." --
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
-count=1 -race -parallel=2

- name: Setup Node for DataDog CLI
uses: actions/setup-node@v2
if: always() && github.actor != 'dependabot[bot]'
with:
node-version: "14"

- name: Cache DataDog CLI
if: always() && github.actor != 'dependabot[bot]'
uses: actions/cache@v2
with:
path: |
~/.npm
%LocalAppData%\npm-cache
key: datadogci-
restore-keys: datadogci-

- name: Upload DataDog Trace
if: always() && github.actor != 'dependabot[bot]'
# See: https://docs.datadoghq.com/continuous_integration/setup_tests/junit_upload/#collecting-environment-configuration-metadata
if: (success() || failure()) && github.actor != 'dependabot[bot]'
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DD_GIT_REPOSITORY_URL: ${{ github.repositoryUrl }}
DD_GIT_BRANCH: ${{ github.head_ref }}
DD_GIT_COMMIT_SHA: ${{ github.sha }}
DD_GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
DD_GIT_COMMIT_AUTHOR_NAME: ${{ github.event.head_commit.author.name }}
DD_GIT_COMMIT_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
DD_GIT_COMMIT_COMMITTER_NAME: ${{ github.event.head_commit.committer.name }}
DD_GIT_COMMIT_COMMITTER_EMAIL: ${{ github.event.head_commit.committer.email }}
DD_TAGS: ${{ format('os.platform:{0},os.architecture:{1}', runner.os, runner.arch) }}
run: |
npm install -g @datadog/datadog-ci
datadog-ci junit upload --service coder gotests.xml
DD_DATABASE: postgresql
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: go run scripts/datadog-cireport/main.go gotests.xml

- uses: codecov/codecov-action@v2
if: github.actor != 'dependabot[bot]'
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ ignore:
- peerbroker/proto
- provisionerd/proto
- provisionersdk/proto
- scripts/datadog-cireport
35 changes: 17 additions & 18 deletions coderd/projectversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,29 @@ func (api *api) postProjectVersionByOrganization(rw http.ResponseWriter, r *http
var provisionerJob database.ProvisionerJob
var projectVersion database.ProjectVersion
err = api.Database.InTx(func(db database.Store) error {
projectVersionID := uuid.New()
provisionerJobID := uuid.New()
projectVersion, err = api.Database.InsertProjectVersion(r.Context(), database.InsertProjectVersionParams{
Comment on lines +128 to +129
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: It'd be nice to have the race fixes in a separate PR - just so the CI could be evaluated independently (or if we found there was a regression, we could pull it off w/o impacting the DataDog improvements)

Copy link
Member Author

Choose a reason for hiding this comment

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

Entirely agree. Just fixed these in here to ensure my CI changes didn't break anything. I'm going to let it slide in this PR, because hopefully CI is reliable enough from this point forward that these types of things can't slip in.

ID: uuid.New(),
ProjectID: project.ID,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Name: namesgenerator.GetRandomName(1),
StorageMethod: createProjectVersion.StorageMethod,
StorageSource: createProjectVersion.StorageSource,
ImportJobID: provisionerJobID,
})
if err != nil {
return xerrors.Errorf("insert project version: %s", err)
}

input, err := json.Marshal(projectImportJob{
ProjectVersionID: projectVersionID,
ProjectVersionID: projectVersion.ID,
})
if err != nil {
return xerrors.Errorf("marshal import job: %w", err)
}

provisionerJob, err = db.InsertProvisionerJob(r.Context(), database.InsertProvisionerJobParams{
ID: uuid.New(),
ID: provisionerJobID,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
InitiatorID: apiKey.UserID,
Expand All @@ -146,20 +159,6 @@ func (api *api) postProjectVersionByOrganization(rw http.ResponseWriter, r *http
if err != nil {
return xerrors.Errorf("insert provisioner job: %w", err)
}

projectVersion, err = api.Database.InsertProjectVersion(r.Context(), database.InsertProjectVersionParams{
ID: projectVersionID,
ProjectID: project.ID,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
Name: namesgenerator.GetRandomName(1),
StorageMethod: createProjectVersion.StorageMethod,
StorageSource: createProjectVersion.StorageSource,
ImportJobID: provisionerJob.ID,
})
if err != nil {
return xerrors.Errorf("insert project version: %s", err)
}
return nil
})
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ func (server *provisionerdServer) CancelJob(ctx context.Context, cancelJob *prot
if err != nil {
return nil, xerrors.Errorf("parse job id: %w", err)
}
job, err := server.Database.GetProvisionerJobByID(ctx, jobID)
if err != nil {
return nil, xerrors.Errorf("get provisioner job: %w", err)
}
if job.CompletedAt.Valid {
return nil, xerrors.Errorf("job already completed")
}
err = server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
ID: jobID,
CompletedAt: sql.NullTime{
Expand Down
39 changes: 19 additions & 20 deletions coderd/workspacehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,32 @@ func (api *api) postWorkspaceHistoryByUser(rw http.ResponseWriter, r *http.Reque
// This must happen in a transaction to ensure history can be inserted, and
// the prior history can update it's "after" column to point at the new.
err = api.Database.InTx(func(db database.Store) error {
// Generate the ID before-hand so the provisioner job is aware of it!
workspaceHistoryID := uuid.New()
provisionerJobID := uuid.New()
workspaceHistory, err = db.InsertWorkspaceHistory(r.Context(), database.InsertWorkspaceHistoryParams{
ID: uuid.New(),
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
WorkspaceID: workspace.ID,
ProjectVersionID: projectVersion.ID,
BeforeID: priorHistoryID,
Name: namesgenerator.GetRandomName(1),
Initiator: user.ID,
Transition: createBuild.Transition,
ProvisionJobID: provisionerJobID,
})
if err != nil {
return xerrors.Errorf("insert workspace history: %w", err)
}

input, err := json.Marshal(workspaceProvisionJob{
WorkspaceHistoryID: workspaceHistoryID,
WorkspaceHistoryID: workspaceHistory.ID,
})
if err != nil {
return xerrors.Errorf("marshal provision job: %w", err)
}

provisionerJob, err = db.InsertProvisionerJob(r.Context(), database.InsertProvisionerJobParams{
ID: uuid.New(),
ID: provisionerJobID,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
InitiatorID: user.ID,
Expand All @@ -149,22 +164,6 @@ func (api *api) postWorkspaceHistoryByUser(rw http.ResponseWriter, r *http.Reque
return xerrors.Errorf("insert provisioner job: %w", err)
}

workspaceHistory, err = db.InsertWorkspaceHistory(r.Context(), database.InsertWorkspaceHistoryParams{
ID: workspaceHistoryID,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
WorkspaceID: workspace.ID,
ProjectVersionID: projectVersion.ID,
BeforeID: priorHistoryID,
Name: namesgenerator.GetRandomName(1),
Initiator: user.ID,
Transition: createBuild.Transition,
ProvisionJobID: provisionerJob.ID,
})
if err != nil {
return xerrors.Errorf("insert workspace history: %w", err)
}

if priorHistoryID.Valid {
// Update the prior history entries "after" column.
err = db.UpdateWorkspaceHistoryByID(r.Context(), database.UpdateWorkspaceHistoryByIDParams{
Expand Down
4 changes: 3 additions & 1 deletion coderd/workspacehistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ func TestPostWorkspaceHistoryByUser(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
user := coderdtest.CreateInitialUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
closeDaemon := coderdtest.NewProvisionerDaemon(t, client)
project := coderdtest.CreateProject(t, client, user.Organization)
version := coderdtest.CreateProjectVersion(t, client, user.Organization, project.Name, nil)
coderdtest.AwaitProjectVersionImported(t, client, user.Organization, project.Name, version.Name)
// Close here so workspace history doesn't process!
closeDaemon.Close()
workspace := coderdtest.CreateWorkspace(t, client, "me", project.ID)
_, err := client.CreateWorkspaceHistory(context.Background(), "", workspace.Name, coderd.CreateWorkspaceHistoryRequest{
ProjectVersionID: version.ID,
Expand Down
3 changes: 2 additions & 1 deletion codersdk/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ func TestFollowWorkspaceHistoryLogsAfter(t *testing.T) {
})
coderdtest.AwaitProjectVersionImported(t, client, user.Organization, project.Name, version.Name)
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
after := database.Now()
history, err := client.CreateWorkspaceHistory(context.Background(), "", workspace.Name, coderd.CreateWorkspaceHistoryRequest{
ProjectVersionID: version.ID,
Transition: database.WorkspaceTransitionCreate,
})
require.NoError(t, err)
logs, err := client.FollowWorkspaceHistoryLogsAfter(context.Background(), "", workspace.Name, history.Name, time.Time{})
logs, err := client.FollowWorkspaceHistoryLogsAfter(context.Background(), "", workspace.Name, history.Name, after)
require.NoError(t, err)
_, ok := <-logs
require.True(t, ok)
Expand Down
7 changes: 3 additions & 4 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ func xerrors(m dsl.Matcher) {
m.Import("errors")
m.Import("fmt")
m.Import("golang.org/x/xerrors")
msg := "Use xerrors to provide additional stacktrace information!"

m.Match("fmt.Errorf($*args)").
Suggest("xerrors.New($args)").
Report(msg)
Report("Use xerrors to provide additional stacktrace information!")

m.Match("fmt.Errorf($*args)").
Suggest("xerrors.Errorf($args)").
Report(msg)
Report("Use xerrors to provide additional stacktrace information!")

m.Match("errors.New($msg)").
Where(m["msg"].Type.Is("string")).
Suggest("xerrors.New($msg)").
Report(msg)
Report("Use xerrors to provide additional stacktrace information!")
}
Loading