-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow proxy service work without metrics DB to allow db drop (#97)
feat: allow proxy service work without metrics DB to allow db drop; includes improves for ci and database disabling via env.
- Loading branch information
Showing
46 changed files
with
812 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Continuous Integration (E2E Testing Checks without metrics database) | ||
|
||
on: | ||
workflow_call: | ||
jobs: | ||
e2e-no-metrics-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout repo from current commit | ||
uses: actions/checkout@v3 | ||
- name: set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.21" | ||
check-latest: true | ||
cache: false | ||
- name: pull pre-built images | ||
run: sudo docker compose -f ci.docker-compose.yml pull | ||
- name: build and start proxy service and it's dependencies | ||
# We need to provide additional env file to override the METRIC_DATABASE_ENABLED variable, not via env variable. | ||
# Mentioned here: https://github.com/docker/compose/issues/9737 | ||
run: sudo docker compose -f ci.docker-compose.yml --env-file .env --env-file no_metric.env up -d --build proxy redis | ||
- name: wait for proxy service to be running | ||
run: bash ${GITHUB_WORKSPACE}/scripts/wait-for-proxy-service-running.sh | ||
env: | ||
PROXY_CONTAINER_PORT: 7777 | ||
- name: run e2e tests | ||
run: SKIP_METRICS=true make e2e-test | ||
- name: print proxy service logs | ||
run: sudo docker compose -f ci.docker-compose.yml logs proxy | ||
# because we especially want the logs if the test(s) fail 😅 | ||
if: always() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
// MetricsDatabase is an interface for interacting with the database | ||
type MetricsDatabase interface { | ||
SaveProxiedRequestMetric(ctx context.Context, metric *ProxiedRequestMetric) error | ||
ListProxiedRequestMetricsWithPagination(ctx context.Context, cursor int64, limit int) ([]*ProxiedRequestMetric, int64, error) | ||
CountAttachedProxiedRequestMetricPartitions(ctx context.Context) (int64, error) | ||
GetLastCreatedAttachedProxiedRequestMetricsPartitionName(ctx context.Context) (string, error) | ||
DeleteProxiedRequestMetricsOlderThanNDays(ctx context.Context, n int64) error | ||
|
||
HealthCheck() error | ||
Partition(prefillPeriodDays int) error | ||
} | ||
|
||
type ProxiedRequestMetric struct { | ||
ID int64 | ||
MethodName string | ||
BlockNumber *int64 | ||
ResponseLatencyMilliseconds int64 | ||
Hostname string | ||
RequestIP string | ||
RequestTime time.Time | ||
UserAgent *string | ||
Referer *string | ||
Origin *string | ||
ResponseBackend string | ||
ResponseBackendRoute string | ||
CacheHit bool | ||
PartOfBatch bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package noop | ||
|
||
import ( | ||
"context" | ||
"github.com/kava-labs/kava-proxy-service/clients/database" | ||
) | ||
|
||
// Noop is a database client that does nothing | ||
type Noop struct{} | ||
|
||
func New() *Noop { | ||
return &Noop{} | ||
} | ||
|
||
func (e *Noop) SaveProxiedRequestMetric(ctx context.Context, metric *database.ProxiedRequestMetric) error { | ||
return nil | ||
} | ||
|
||
func (e *Noop) ListProxiedRequestMetricsWithPagination(ctx context.Context, cursor int64, limit int) ([]*database.ProxiedRequestMetric, int64, error) { | ||
return []*database.ProxiedRequestMetric{}, 0, nil | ||
} | ||
|
||
func (e *Noop) CountAttachedProxiedRequestMetricPartitions(ctx context.Context) (int64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (e *Noop) GetLastCreatedAttachedProxiedRequestMetricsPartitionName(ctx context.Context) (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (e *Noop) DeleteProxiedRequestMetricsOlderThanNDays(ctx context.Context, n int64) error { | ||
return nil | ||
} | ||
|
||
func (e *Noop) HealthCheck() error { | ||
return nil | ||
} | ||
|
||
func (e *Noop) Partition(prefillPeriodDays int) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package postgres | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestDisabledDBCreation(t *testing.T) { | ||
config := DatabaseConfig{} | ||
_, err := NewClient(config) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestHealthcheckNoDatabase(t *testing.T) { | ||
config := DatabaseConfig{} | ||
_, err := NewClient(config) | ||
require.Error(t, err) | ||
} |
7 changes: 3 additions & 4 deletions
7
clients/database/database.go → clients/database/postgres/migrate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
"github.com/stretchr/testify/require" | ||
"github.com/uptrace/bun/migrate" | ||
"testing" | ||
) | ||
|
||
func TestMigrateNoDatabase(t *testing.T) { | ||
db := &Client{} | ||
|
||
_, err := db.Migrate(context.Background(), migrate.Migrations{}, nil) | ||
require.Error(t, err) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.