From 068e293a44dc406df6f7c90cdd3807f623ce00be Mon Sep 17 00:00:00 2001 From: Daniel Baptista Dias Date: Wed, 27 Dec 2023 17:22:28 -0300 Subject: [PATCH 1/5] fix: skip open attribute list step on e2e (#3481) * fix: skip open attribute list step on e2e * adding quiet-pull option to avoid noisy logs on GH actions * disable github cache temporarily * removing cache from gh action --- .github/workflows/pull-request.yaml | 51 +++---------------- run.sh | 2 +- web/cypress/e2e/TestRunDetail/Outputs.spec.ts | 6 +-- .../e2e/TestRunDetail/TestRunDetail.spec.ts | 4 +- 4 files changed, 14 insertions(+), 49 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index ea3651380d..82fae73b10 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -146,80 +146,45 @@ jobs: with: fetch-depth: 0 - - name: set cache keys - shell: bash - run: | - echo "WEB_CACHE_KEY=$(git log --pretty=tformat:"%H" -n1 web)" >> $GITHUB_ENV - echo "SERVER_CACHE_KEY=$(git log --pretty=tformat:"%H" -n1 server)" >> $GITHUB_ENV - echo "CLI_CACHE_KEY=$(git log --pretty=tformat:"%H" -n1 cli)" >> $GITHUB_ENV - # web - - name: Cache Web Build - id: cache-web-build - uses: actions/cache@v3 - with: - path: web/build/ - key: web-build-${{ env.WEB_CACHE_KEY }} - - name: Setup node - # if cache miss - if: steps.cache-web-build.outputs.cache-hit != 'true' uses: actions/setup-node@v3 with: node-version: 16 cache: npm cache-dependency-path: web/package-lock.json - - name: Cache dependencies - id: cache-nodemodules - # if cache miss - if: steps.cache-web-build.outputs.cache-hit != 'true' - uses: actions/cache@v3 - with: - path: | - web/node_modules - /home/runner/.cache/Cypress - key: npm--${{ hashFiles('web/package-lock.json') }} - restore-keys: npm- - - name: Install dependencies run: cd web/; npm ci - # if cache miss for build and deps - if: steps.cache-web-build.outputs.cache-hit != 'true' && steps.cache-nodemodules.outputs.cache-hit != 'true' - - run: cd web; CI= npm run build - if: steps.cache-web-build.outputs.cache-hit != 'true' + - name: Build UI + run: cd web; CI= npm run build # go+docker - - name: Cache Build - id: cache-docker-build - uses: actions/cache@v3 - with: - path: dist/ - key: dist-${{env.SERVER_CACHE_KEY }}-${{env.CLI_CACHE_KEY }}-${{ hashFiles('.goreleaser.dev.yaml', 'Dockerfile') }} - name: Setup go - if: steps.cache-docker-build.outputs.cache-hit != 'true' uses: actions/setup-go@v3 with: go-version-file: "go.mod" cache: true cache-dependency-path: "go.mod" - - uses: goreleaser/goreleaser-action@v4 - if: steps.cache-docker-build.outputs.cache-hit != 'true' + + - name: Release Go binaries + uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser-pro version: v1.22.0 args: release --skip=announce --snapshot -f .goreleaser.dev.yaml + - name: Move binaries to known location - if: steps.cache-docker-build.outputs.cache-hit != 'true' run: | find ./dist -name 'tracetest' -exec cp {} ./dist \; find ./dist -name 'tracetest-server' -exec cp {} ./dist \; chmod +x ./dist/tracetest ./dist/tracetest-server + - name: Export docker image - if: steps.cache-docker-build.outputs.cache-hit != 'true' run: | docker save --output dist/image.tar "kubeshop/tracetest:$TAG" + - name: Upload assets uses: actions/upload-artifact@v3 with: diff --git a/run.sh b/run.sh index 41c2d58467..4c92fd06af 100755 --- a/run.sh +++ b/run.sh @@ -45,7 +45,7 @@ build() { } up() { - docker compose $opts up -d --remove-orphans + docker compose $opts up --detach --remove-orphans --quiet-pull } stop() { diff --git a/web/cypress/e2e/TestRunDetail/Outputs.spec.ts b/web/cypress/e2e/TestRunDetail/Outputs.spec.ts index aed1f4880a..63e3240670 100644 --- a/web/cypress/e2e/TestRunDetail/Outputs.spec.ts +++ b/web/cypress/e2e/TestRunDetail/Outputs.spec.ts @@ -7,7 +7,7 @@ describe('Outputs', () => { // Open output flow from the Trace view (attributes) cy.selectRunDetailMode(2); cy.get('[data-cy=trace-node-database]', {timeout: 25000}).first().click({force: true}); - cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); + // cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); cy.get('[data-cy=attributes-search-container] input').type('db.name'); cy.get('[data-cy=attribute-row-db-name] .ant-dropdown-trigger').click(); cy.contains('Create test output').click(); @@ -46,7 +46,7 @@ describe('Outputs', () => { // Open output flow from the Trace view (attributes) cy.selectRunDetailMode(2); cy.get('[data-cy=trace-node-database]', {timeout: 25000}).first().click({force: true}); - cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); + // cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); cy.get('[data-cy=attributes-search-container] input').type('db.name'); cy.get('[data-cy=attribute-row-db-name] .ant-dropdown-trigger').click(); cy.contains('Create test output').click(); @@ -89,7 +89,7 @@ describe('Outputs', () => { // Open output flow from the Trace view (attributes) cy.selectRunDetailMode(2); cy.get('[data-cy=trace-node-database]', {timeout: 25000}).first().click({force: true}); - cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); + // cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]', {timeout: 25000}).click({force: true}); cy.get('[data-cy=attributes-search-container] input').type('db.name'); cy.get('[data-cy=attribute-row-db-name] .ant-dropdown-trigger').click(); cy.contains('Create test output').click(); diff --git a/web/cypress/e2e/TestRunDetail/TestRunDetail.spec.ts b/web/cypress/e2e/TestRunDetail/TestRunDetail.spec.ts index 58c6614bb8..3ea65979fe 100644 --- a/web/cypress/e2e/TestRunDetail/TestRunDetail.spec.ts +++ b/web/cypress/e2e/TestRunDetail/TestRunDetail.spec.ts @@ -7,7 +7,7 @@ describe('Test Run Detail Views', () => { it('Trace view -> show the attribute list for a specific span', () => { cy.selectRunDetailMode(2); cy.get('[data-cy=trace-node-http]').click(); - cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]').click(); + // cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]').click(); cy.get('[data-cy=attribute-list]').should('be.visible'); cy.get('[data-cy=attribute-row-http-method]').should('be.visible'); @@ -16,7 +16,7 @@ describe('Test Run Detail Views', () => { it('Trace view -> attribute list', () => { cy.selectRunDetailMode(2); cy.get('[data-cy=trace-node-http]').click(); - cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]').click(); + // cy.get('[data-cy=toggle-drawer-SPAN_DETAILS]').click(); cy.get('[data-cy=attribute-list]').should('be.visible'); }); From ea2e2df438a34181065a120e61e46dce5e584df0 Mon Sep 17 00:00:00 2001 From: Daniel Baptista Dias Date: Wed, 27 Dec 2023 17:51:37 -0300 Subject: [PATCH 2/5] fix: test repository tenant_id query (#3476) * fix: test repository tenant_id query * omitting logs from cypress e2e tests * wip * added tenant_id check on get test sql to avoid cartesian products --- run.sh | 4 ---- server/test/test_repository.go | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/run.sh b/run.sh index 4c92fd06af..f45d3dd8de 100755 --- a/run.sh +++ b/run.sh @@ -53,10 +53,8 @@ stop() { } cypress-ci() { - echo "Running cypress" - export CYPRESS_BASE_URL=http://localhost:11633 export POKEMON_HTTP_ENDPOINT=http://demo-api:8081 @@ -65,10 +63,8 @@ cypress-ci() { } cypress() { - echo "Running cypress" - export CYPRESS_BASE_URL=http://localhost:11633 export POKEMON_HTTP_ENDPOINT=http://demo-api:8081 diff --git a/server/test/test_repository.go b/server/test/test_repository.go index 633507c533..f5b5c6e707 100644 --- a/server/test/test_repository.go +++ b/server/test/test_repository.go @@ -85,7 +85,7 @@ const ( ) as ltr ON ltr.test_id = t.id AND ltr.tenant_id = t.tenant_id LEFT OUTER JOIN test_runs last_test_run - ON last_test_run.test_id = ltr.test_id AND last_test_run.id = ltr.id + ON last_test_run.test_id = ltr.test_id AND last_test_run.id = ltr.id AND last_test_run.tenant_id = ltr.tenant_id ` testMaxVersionQuery = ` From d57fa67864ef35a5ded5d9e342a426393df9bbc2 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Wed, 27 Dec 2023 17:52:47 -0300 Subject: [PATCH 3/5] chore(server): update goreleaser version (#3483) --- .github/workflows/deploy-demo.yml | 2 +- .github/workflows/deploy-main.yml | 4 ++-- .github/workflows/pull-request.yaml | 2 +- .github/workflows/release-candidate.yml | 2 +- .github/workflows/release-version.yml | 2 +- Makefile | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-demo.yml b/.github/workflows/deploy-demo.yml index d956a35c31..1c6fe11a1c 100644 --- a/.github/workflows/deploy-demo.yml +++ b/.github/workflows/deploy-demo.yml @@ -79,7 +79,7 @@ jobs: - uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: release --clean --skip=announce -f .goreleaser.demo.yaml env: VERSION: ${{ github.ref_name}}-demo diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index 846244fc2d..109ca95af5 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -120,7 +120,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: release --clean --split --nightly env: GOOS: ${{ matrix.GOOS }} @@ -190,7 +190,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: continue --merge env: VERSION: sha-${{ env.sha_short }} diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 82fae73b10..4292d319a3 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -172,7 +172,7 @@ jobs: uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: release --skip=announce --snapshot -f .goreleaser.dev.yaml - name: Move binaries to known location diff --git a/.github/workflows/release-candidate.yml b/.github/workflows/release-candidate.yml index 251e0b92c8..002ca21c0e 100644 --- a/.github/workflows/release-candidate.yml +++ b/.github/workflows/release-candidate.yml @@ -82,7 +82,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: release --clean -f .goreleaser.rc.yaml env: VERSION: ${{ github.ref_name}} diff --git a/.github/workflows/release-version.yml b/.github/workflows/release-version.yml index 05f4fbf99c..1e789ef3a6 100644 --- a/.github/workflows/release-version.yml +++ b/.github/workflows/release-version.yml @@ -93,7 +93,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' with: distribution: goreleaser-pro - version: v1.22.0 + version: v1.22.1 args: release --clean env: VERSION: ${{ github.ref_name}} diff --git a/Makefile b/Makefile index d1de85df2c..43951d4c9a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION?=dev TAG?=$(VERSION) -GORELEASER_VERSION=1.22.0-pro +GORELEASER_VERSION=1.22.1-pro PROJECT_ROOT=${PWD} From 0652b3deb8b7f6eedf19b1d22e60a61e23837de5 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Wed, 27 Dec 2023 17:53:52 -0300 Subject: [PATCH 4/5] fix(server): take tenant_id into account for test run events (#3482) --- .../37_test_run_events_tenant.down.sql | 8 ++++ .../37_test_run_events_tenant.up.sql | 11 +++++ server/testdb/test_run_event.go | 43 +++++++++++-------- 3 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 server/migrations/37_test_run_events_tenant.down.sql create mode 100644 server/migrations/37_test_run_events_tenant.up.sql diff --git a/server/migrations/37_test_run_events_tenant.down.sql b/server/migrations/37_test_run_events_tenant.down.sql new file mode 100644 index 0000000000..4065f3411f --- /dev/null +++ b/server/migrations/37_test_run_events_tenant.down.sql @@ -0,0 +1,8 @@ +BEGIN; + +ALTER TABLE + test_run_events +DROP + COLUMN tenant_id; + +COMMIT; diff --git a/server/migrations/37_test_run_events_tenant.up.sql b/server/migrations/37_test_run_events_tenant.up.sql new file mode 100644 index 0000000000..e22fd1857e --- /dev/null +++ b/server/migrations/37_test_run_events_tenant.up.sql @@ -0,0 +1,11 @@ +BEGIN; + +ALTER TABLE + test_run_events +ADD + COLUMN tenant_id varchar +; + +CREATE INDEX idx_test_run_events_tenant_id ON test_run_events(tenant_id); + +COMMIT; diff --git a/server/testdb/test_run_event.go b/server/testdb/test_run_event.go index cf7b483fbe..20fa0250bf 100644 --- a/server/testdb/test_run_event.go +++ b/server/testdb/test_run_event.go @@ -9,6 +9,7 @@ import ( "github.com/kubeshop/tracetest/server/model" "github.com/kubeshop/tracetest/server/pkg/id" + "github.com/kubeshop/tracetest/server/pkg/sqlutil" ) const insertTestRunEventQuery = ` @@ -22,23 +23,30 @@ const insertTestRunEventQuery = ` "created_at", "data_store_connection", "polling", - "outputs" + "outputs", + "tenant_id" ) VALUES ( - $1, -- test_id - $2, -- run_id - $3, -- type - $4, -- stage - $5, -- title - $6, -- description - $7, -- created_at - $8, -- data_store_connection - $9, -- polling - $10 -- outputs + $1, -- test_id + $2, -- run_id + $3, -- type + $4, -- stage + $5, -- title + $6, -- description + $7, -- created_at + $8, -- data_store_connection + $9, -- polling + $10, -- outputs + $11 -- tenant_id ) - RETURNING "id" ` func (td *postgresDB) CreateTestRunEvent(ctx context.Context, event model.TestRunEvent) error { + stmt, err := td.db.Prepare(insertTestRunEventQuery) + if err != nil { + return fmt.Errorf("sql prepare: %w", err) + } + defer stmt.Close() + dataStoreConnectionJSON, err := json.Marshal(event.DataStoreConnection) if err != nil { return fmt.Errorf("could not marshal data store connection into JSON: %w", err) @@ -58,9 +66,7 @@ func (td *postgresDB) CreateTestRunEvent(ctx context.Context, event model.TestRu event.CreatedAt = time.Now() } - err = td.db.QueryRowContext( - ctx, - insertTestRunEventQuery, + params := sqlutil.TenantInsert(ctx, event.TestID, event.RunID, event.Type, @@ -71,7 +77,9 @@ func (td *postgresDB) CreateTestRunEvent(ctx context.Context, event model.TestRu dataStoreConnectionJSON, pollingJSON, outputsJSON, - ).Scan(&event.ID) + ) + + _, err = stmt.ExecContext(ctx, params...) if err != nil { return fmt.Errorf("could not insert event into database: %w", err) @@ -97,7 +105,8 @@ const getTestRunEventsQuery = ` ` func (td *postgresDB) GetTestRunEvents(ctx context.Context, testID id.ID, runID int) ([]model.TestRunEvent, error) { - rows, err := td.db.QueryContext(ctx, getTestRunEventsQuery, testID, runID) + query, params := sqlutil.Tenant(ctx, getTestRunEventsQuery, testID, runID) + rows, err := td.db.QueryContext(ctx, query, params...) if err != nil { return []model.TestRunEvent{}, fmt.Errorf("could not query test runs: %w", err) } From f0208f88379e57120c00a50172b232568a3411a2 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Thu, 28 Dec 2023 12:14:18 -0300 Subject: [PATCH 5/5] fix(server): correct query with tenant id for test run events (#3484) --- server/testdb/test_run_event.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/testdb/test_run_event.go b/server/testdb/test_run_event.go index 20fa0250bf..eb16a68152 100644 --- a/server/testdb/test_run_event.go +++ b/server/testdb/test_run_event.go @@ -101,12 +101,17 @@ const getTestRunEventsQuery = ` "data_store_connection", "polling", "outputs" - FROM test_run_events WHERE "test_id" = $1 AND "run_id" = $2 ORDER BY "created_at" ASC; + FROM test_run_events + WHERE + "test_id" = $1 + AND "run_id" = $2 + AND "tenant_id" = $3 + ORDER BY "created_at" ASC; ` func (td *postgresDB) GetTestRunEvents(ctx context.Context, testID id.ID, runID int) ([]model.TestRunEvent, error) { - query, params := sqlutil.Tenant(ctx, getTestRunEventsQuery, testID, runID) - rows, err := td.db.QueryContext(ctx, query, params...) + params := sqlutil.TenantInsert(ctx, testID, runID) + rows, err := td.db.QueryContext(ctx, getTestRunEventsQuery, params...) if err != nil { return []model.TestRunEvent{}, fmt.Errorf("could not query test runs: %w", err) }