Skip to content
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

feat: Upgrade to SDK v4 #7

Merged
merged 9 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
version: v1.55.1
args: --timeout=3m
skip-pkg-cache: true
skip-build-cache: true
- name: Get dependencies
run: go get -t -d ./...
- name: Build
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ The following source configuration file will sync to a PostgreSQL database. See
spec:
name: "coinpaprika"
path: "coinpaprika/coinpaprika"
version: "v1.0.1"
backend: local
version: "v2.0.0"
backend_options:
table_name: "cq_state_coinpaprika"
connection: "@@plugins.sqlite.connection"
tables:
[ "*" ]
destinations:
Expand All @@ -50,7 +52,8 @@ The following source configuration file will sync to a PostgreSQL database. See
spec:
name: sqlite
path: cloudquery/sqlite
version: "v2.2.1"
registry: cloudquery
version: "v2.4.15"
spec:
connection_string: ./db.sql
```
Expand All @@ -62,8 +65,10 @@ The following source configuration file will sync to a PostgreSQL database. See
spec:
name: "coinpaprika"
path: "coinpaprika/coinpaprika"
version: "v1.0.1"
backend: local
version: "v2.0.0"
backend_options:
table_name: "cq_state_coinpaprika"
connection: "@@plugins.sqlite.connection"
tables:
[ "*" ]
destinations:
Expand All @@ -82,7 +87,8 @@ The following source configuration file will sync to a PostgreSQL database. See
spec:
name: sqlite
path: cloudquery/sqlite
version: "v2.2.1"
registry: cloudquery
version: "v2.4.15"
spec:
connection_string: ./db.sql
```
Expand Down
4 changes: 2 additions & 2 deletions client/backend.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import "github.com/cloudquery/plugin-sdk/v3/backend"
import "github.com/cloudquery/plugin-sdk/v4/state"

type Backend interface {
backend.Backend
state.Client
}
20 changes: 5 additions & 15 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package client

import (
"context"
"fmt"
"github.com/cloudquery/plugin-sdk/v4/schema"
"time"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/state"
"github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
"github.com/rs/zerolog"
)

type Client struct {
Logger zerolog.Logger
CoinpaprikaClient CoinpaprikaServices
Backend Backend
Backend state.Client
StartDate time.Time
EndDate time.Time
Interval string
Expand All @@ -26,13 +23,7 @@ func (c *Client) ID() string {
return "coinpaprika"
}

func New(ctx context.Context, logger zerolog.Logger, s specs.Source, opts source.Options) (schema.ClientMeta, error) {
var pluginSpec Spec

if err := s.UnmarshalSpec(&pluginSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal plugin spec: %w", err)
}

func New(logger zerolog.Logger, pluginSpec Spec, backend state.Client) (schema.ClientMeta, error) {
var cOpts []coinpaprika.ClientOptions
if pluginSpec.AccessToken != "" {
cOpts = append(cOpts, coinpaprika.WithAPIKey(pluginSpec.AccessToken))
Expand Down Expand Up @@ -62,13 +53,12 @@ func New(ctx context.Context, logger zerolog.Logger, s specs.Source, opts source
cc := coinpaprika.NewClient(NewHttpClient(logger, pluginSpec.ApiDebug, rateNumber, rateDuration), cOpts...)

return &Client{
Logger: logger,
CoinpaprikaClient: CoinpaprikaServices{
Tickers: &cc.Tickers,
Coins: &cc.Coins,
Exchanges: &cc.Exchanges,
},
Backend: opts.Backend,
Backend: backend,
StartDate: startDate,
EndDate: endDate,
Interval: pluginSpec.Interval,
Expand Down
36 changes: 18 additions & 18 deletions client/mock/backend.go

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

55 changes: 24 additions & 31 deletions client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,52 @@ package client

import (
"context"
"github.com/cloudquery/plugin-sdk/v4/plugin"
"github.com/cloudquery/plugin-sdk/v4/scheduler"
"github.com/cloudquery/plugin-sdk/v4/state"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"os"
"testing"
"time"

"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/backend"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/golang/mock/gomock"
"github.com/rs/zerolog"
)

type TestOptions struct {
Backend backend.Backend
Backend state.Client
StartTime time.Time
EndTime time.Time
Interval string
Tickers []string
}

func MockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.T, *gomock.Controller) CoinpaprikaServices, opts TestOptions) {
version := "vDev"
table.IgnoreInTests = false
t.Helper()
ctrl := gomock.NewController(t)
l := zerolog.New(zerolog.NewTestWriter(t)).Output(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro},
).Level(zerolog.DebugLevel).With().Timestamp().Logger()

newTestExecutionClient := func(ctx context.Context, logger zerolog.Logger, spec specs.Source, _ source.Options) (schema.ClientMeta, error) {
return &Client{
Logger: l,
CoinpaprikaClient: builder(t, ctrl),
Backend: opts.Backend,
StartDate: opts.StartTime,
EndDate: opts.EndTime,
Interval: opts.Interval,
Tickers: opts.Tickers,
}, nil
client := &Client{
CoinpaprikaClient: builder(t, ctrl),
Backend: opts.Backend,
StartDate: opts.StartTime,
EndDate: opts.EndTime,
Interval: opts.Interval,
Tickers: opts.Tickers,
}
p := source.NewPlugin(
table.Name,
version,
[]*schema.Table{
table,
},
newTestExecutionClient)
p.SetLogger(l)
source.TestPluginSync(t, p, specs.Source{
Name: "dev",
Path: "cloudquery/dev",
Version: version,
Tables: []string{table.Name},
Destinations: []string{"mock-destination"},
})

tables := schema.Tables{table}
if err := transformers.TransformTables(tables); err != nil {
t.Fatal(err)
}
sched := scheduler.NewScheduler(scheduler.WithLogger(l))
messages, err := sched.SyncAll(context.Background(), client, tables)
if err != nil {
t.Fatalf("failed to sync: %v", err)
}
plugin.ValidateNoEmptyColumns(t, tables, messages)
}
2 changes: 1 addition & 1 deletion docs/tables/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Source Plugin: coinpaprika-coinpaprika
# Source Plugin: coinpaprika

## Tables

Expand Down
2 changes: 0 additions & 2 deletions docs/tables/coinpaprika_coins.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ The following tables depend on coinpaprika_coins:

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|`utf8`|
|_cq_sync_time|`timestamp[us, tz=UTC]`|
|_cq_id|`uuid`|
|_cq_parent_id|`uuid`|
|id (PK)|`utf8`|
Expand Down
8 changes: 3 additions & 5 deletions docs/tables/coinpaprika_exchanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

This table shows data for Coinpaprika Exchanges.

The primary key for this table is **_cq_id**.
The primary key for this table is **id**.

## Columns

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|`utf8`|
|_cq_sync_time|`timestamp[us, tz=UTC]`|
|_cq_id (PK)|`uuid`|
|_cq_id|`uuid`|
|_cq_parent_id|`uuid`|
|id|`utf8`|
|id (PK)|`utf8`|
|name|`utf8`|
|message|`utf8`|
|description|`utf8`|
Expand Down
8 changes: 3 additions & 5 deletions docs/tables/coinpaprika_tickers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This table shows data for Coinpaprika Tickers.

https://api.coinpaprika.com/#tag/Tickers/operation/getTickersHistoricalById

The composite primary key for this table is (**id**, **timestamp**).
The composite primary key for this table is (**coin_id**, **timestamp**).
It supports incremental syncs based on the **timestamp** column.
## Relations

Expand All @@ -14,12 +14,10 @@ This table depends on [coinpaprika_coins](coinpaprika_coins.md).

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|`utf8`|
|_cq_sync_time|`timestamp[us, tz=UTC]`|
|_cq_id|`uuid`|
|_cq_parent_id|`uuid`|
|id (PK)|`utf8`|
|timestamp (PK) (Incremental Key)|`utf8`|
|coin_id (PK)|`utf8`|
|timestamp (PK) (Incremental Key)|`timestamp[us, tz=UTC]`|
|price|`float64`|
|volume_24h|`float64`|
|market_cap|`float64`|
Loading