From f759f270007b8044a80296248f81bf4ec509c800 Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 4 Aug 2024 07:31:31 -0700 Subject: [PATCH 1/6] SQL updates --- .github/workflows/ci.yml | 4 ++++ Makefile | 2 +- proto/sql.proto | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3a577e..d8026ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,10 @@ jobs: go-version: '1.21' - name: Install protoc-gen-go run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + - name: Install protoc-gen-go-vtproto + run: go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@latest - name: generate language files run: make all clean + env: + GOPATH: /root/go diff --git a/Makefile b/Makefile index 5aa0949..5be11f6 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ all: go go: @echo "Generating Go code..." mkdir -p $(GO_OUT) - protoc -I=./proto --go_out=$(GO_OUT) ./proto/*.proto + protoc -I=./proto --go_out=$(GO_OUT) --go-vtproto_out=$(GO_OUT) --plugin protoc-gen-go="${GOPATH}/bin/protoc-gen-go" --plugin protoc-gen-go-vtproto="${GOPATH}/bin/protoc-gen-go-vtproto" ./proto/*.proto clean: @echo "Cleaning up generated files..." diff --git a/proto/sql.proto b/proto/sql.proto index abbe40c..ad375e8 100644 --- a/proto/sql.proto +++ b/proto/sql.proto @@ -18,8 +18,27 @@ message SQLQueryResponse { // Status is the human readable error message or success message for function // execution. tarmac.Status status = 1; - // Data is a byte slice representing a JSON structure of the returned rows. - // Each row will contain a column name based map to access data. - bytes data = 2; + + // LastInsertID is the ID of the last inserted row. This field is only + // populated if the query was an insert query and the database supports + // returning the last inserted ID. + int64 last_insert_id = 2; + + // RowsAffected is the number of rows affected by the query. This field is + // only populated if the query was an insert, update, or delete query. + int64 rows_affected = 3; + + // Columns is a list of column names returned by the query. This field is + // only populated if the query was a select query. + repeated string columns = 4; + + // Rows is a list of rows returned by the query. This field is only populated + // if the query was a select query. + repeated Row rows = 5; } +// Row is a structure used to represent a row in a SQL query response. +// The data field is a map of column names to column values. +message Row { + map data = 1; +} From ff23dd6b3dc5f2170a9726e5179f64036c0653dd Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 25 Aug 2024 18:06:23 -0700 Subject: [PATCH 2/6] revamping SQL proto --- proto/sql.proto | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/proto/sql.proto b/proto/sql.proto index ad375e8..c32e446 100644 --- a/proto/sql.proto +++ b/proto/sql.proto @@ -5,16 +5,17 @@ package tarmac.sql; import "tarmac.proto"; option go_package = "github.com/tarmac-project/tarmac/proto"; -// SQLQuery is a structure used to create SQL queries to a SQL Database. -message SQLQuery { +// SQLExec is a structure used to execute a SQL query on a SQL Database. +// This message type should be leveraged for queries that do not return rows. +message SQLExec { // Query is the SQL Query to be executed. This field should be a byte slice // to avoid conflicts with JSON encoding. bytes query = 1; } -// SQLQueryResponse is a structure supplied as a response message to a SQL -// Database Query. -message SQLQueryResponse { +// SQLExecResponse is a structure supplied as a response message to a SQLExec +// request. +message SQLExecResponse { // Status is the human readable error message or success message for function // execution. tarmac.Status status = 1; @@ -27,18 +28,27 @@ message SQLQueryResponse { // RowsAffected is the number of rows affected by the query. This field is // only populated if the query was an insert, update, or delete query. int64 rows_affected = 3; +} + +// SQLQuery is a structure used to create SQL queries to a SQL Database. +message SQLQuery { + // Query is the SQL Query to be executed. This field should be a byte slice + // to avoid conflicts with JSON encoding. + bytes query = 1; +} + +// SQLQueryResponse is a structure supplied as a response message to a SQL +// Database Query. +message SQLQueryResponse { + // Status is the human readable error message or success message for function + // execution. + tarmac.Status status = 1; // Columns is a list of column names returned by the query. This field is // only populated if the query was a select query. repeated string columns = 4; - // Rows is a list of rows returned by the query. This field is only populated - // if the query was a select query. - repeated Row rows = 5; + // Data is a JSON encoded byte slice of the data returned by the query. + bytes data = 5; } -// Row is a structure used to represent a row in a SQL query response. -// The data field is a map of column names to column values. -message Row { - map data = 1; -} From 0b21f2c15b47b918570a8120bf2e9a520ab96e3f Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 6 Oct 2024 09:53:52 -0700 Subject: [PATCH 3/6] refactor(proto): migrate proto files to sdk directory Because directory names matter, and sdk sounds cooler. --- .github/workflows/ci.yml | 2 +- Makefile | 7 ++++--- {proto => sdk}/http.proto | 9 ++++++++- {proto => sdk}/kvstore.proto | 20 ++++++++++++++++++-- {proto => sdk}/metrics.proto | 5 +++-- {proto => sdk}/sql.proto | 2 +- {proto => sdk}/tarmac.proto | 4 ++-- 7 files changed, 37 insertions(+), 12 deletions(-) rename {proto => sdk}/http.proto (94%) rename {proto => sdk}/kvstore.proto (83%) rename {proto => sdk}/metrics.proto (93%) rename {proto => sdk}/sql.proto (96%) rename {proto => sdk}/tarmac.proto (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8026ed..5223d58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,6 @@ jobs: run: go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@latest - name: generate language files - run: make all clean + run: make build clean env: GOPATH: /root/go diff --git a/Makefile b/Makefile index 5be11f6..147dd81 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,15 @@ OUT_DIR=build # Go-specific settings GO_OUT=$(OUT_DIR)/go -.PHONY: all clean go +.PHONY: build clean go -all: go +build: go go: @echo "Generating Go code..." mkdir -p $(GO_OUT) - protoc -I=./proto --go_out=$(GO_OUT) --go-vtproto_out=$(GO_OUT) --plugin protoc-gen-go="${GOPATH}/bin/protoc-gen-go" --plugin protoc-gen-go-vtproto="${GOPATH}/bin/protoc-gen-go-vtproto" ./proto/*.proto + @echo "Generating SDK..." + protoc -I=./sdk --go_out=$(GO_OUT) --go-vtproto_out=$(GO_OUT) --plugin protoc-gen-go="${GOPATH}/bin/protoc-gen-go" --plugin protoc-gen-go-vtproto="${GOPATH}/bin/protoc-gen-go-vtproto" ./sdk/*.proto clean: @echo "Cleaning up generated files..." diff --git a/proto/http.proto b/sdk/http.proto similarity index 94% rename from proto/http.proto rename to sdk/http.proto index f2946d4..4a1f2fb 100644 --- a/proto/http.proto +++ b/sdk/http.proto @@ -3,20 +3,24 @@ syntax = "proto3"; package tarmac.http; import "tarmac.proto"; -option go_package = "github.com/tarmac-project/tarmac/proto"; +option go_package = "github.com/tarmac-project/protobuf-go/sdk/http"; // HTTPClient is a structure used to create HTTP calls to remote systems. message HTTPClient { // Method is the HTTP method type for the HTTP request; valid options are // GET, POST, PUT, PATCH, HEAD, & DELETE. string method = 1; + // Headers are the HTTP headers to include in the HTTP request. map headers = 2; + // URL is the HTTP URL to call. string url = 3; + // Body is the user-supplied HTTP body data. This field should contain the // request payload data. bytes body = 4; + // Insecure will disable TLS host verification; this is common with // self-signed certificates; however, use caution. bool insecure = 5; @@ -28,10 +32,13 @@ message HTTPClientResponse { // Status is the human readable error message or success message for function // execution. tarmac.Status status = 1; + // Code is the HTTP Status Code returned from the target server. int32 code = 2; + // Headers are the HTTP headers returned from the HTTP request. map headers = 3; + // Body is the server-supplied HTTP payload data. The server-supplied payload // will be a byte slice. bytes body = 4; diff --git a/proto/kvstore.proto b/sdk/kvstore.proto similarity index 83% rename from proto/kvstore.proto rename to sdk/kvstore.proto index 9e76ca2..42558ab 100644 --- a/proto/kvstore.proto +++ b/sdk/kvstore.proto @@ -3,7 +3,7 @@ syntax = "proto3"; package tarmac.kvstore; import "tarmac.proto"; -option go_package = "github.com/tarmac-project/tarmac/proto"; +option go_package = "github.com/tarmac-project/protobuf-go/sdk/kvstore"; // KVStoreGet is a structure used to create Get request callbacks to the Tarmac // KVStore interface. @@ -24,6 +24,7 @@ message KVStoreGetResponse { // Status is the human readable error message or success message for function // execution. tarmac.Status status = 1; + // Data is the response data provided by the key:value store. // This data is a byte slice to provide a simple field for arbitrary data. bytes data = 2; @@ -37,6 +38,7 @@ message KVStoreGetResponse { message KVStoreSet { // Key is the index key used to store the data. string key = 1; + // Data is the user-supplied key:value data. // Tarmac expects this field to be a byte slice. bytes data = 2; @@ -74,15 +76,29 @@ message KVStoreDeleteResponse { tarmac.Status status = 1; } +// KVStoreKeys is a structure used to create a Keys callback request to the +// Tarmac KVStore interface. +// +// This structure is a general request type used for all KVStore types provided +// by Tarmac. +message KVStoreKeys { + // ReturnProto is a boolean value that determines if the response should be + // returned as a JSON string or as a KVStoreKeysResponse message. + // + // This must be set to true to return a KVStoreKeysResponse message. + bool return_proto = 1; +} + // KVStoreKeysResponse is a structure supplied as a response message to the // KVStore Keys callback function. - +// // This response is a general response type used for all KVStore types provided // by Tarmac. message KVStoreKeysResponse { // Status is the human readable error message or success message for function // execution. tarmac.Status status = 1; + // Keys is a list of keys available within the KV Store. repeated string keys = 2; } diff --git a/proto/metrics.proto b/sdk/metrics.proto similarity index 93% rename from proto/metrics.proto rename to sdk/metrics.proto index f22496c..bb1e3d7 100644 --- a/proto/metrics.proto +++ b/sdk/metrics.proto @@ -1,8 +1,7 @@ syntax = "proto3"; package tarmac.metrics; - -option go_package = "github.com/tarmac-project/tarmac/proto"; +option go_package = "github.com/tarmac-project/protobuf-go/sdk/metrics"; // MetricsCounter is a structure used to create Counter metrics callback // requests to the Tarmac Metrics interface. @@ -16,6 +15,7 @@ message MetricsCounter { message MetricsGauge { // Name is the name of the metric as exposed via the metrics HTTP end-point. string name = 1; + // Action is the action to be performed for the Gauge metric. // Valid options are inc (Increment) and dec (Decrement). string action = 2; // inc or dec @@ -26,6 +26,7 @@ message MetricsGauge { message MetricsHistogram { // Name is the name of the metric as exposed via the metrics HTTP end-point. string name = 1; + // Value is the value to Observe for the Histogram metric. double value = 2; } diff --git a/proto/sql.proto b/sdk/sql.proto similarity index 96% rename from proto/sql.proto rename to sdk/sql.proto index c32e446..f9d2418 100644 --- a/proto/sql.proto +++ b/sdk/sql.proto @@ -3,7 +3,7 @@ syntax = "proto3"; package tarmac.sql; import "tarmac.proto"; -option go_package = "github.com/tarmac-project/tarmac/proto"; +option go_package = "github.com/tarmac-project/protobuf-go/sdk/sql"; // SQLExec is a structure used to execute a SQL query on a SQL Database. // This message type should be leveraged for queries that do not return rows. diff --git a/proto/tarmac.proto b/sdk/tarmac.proto similarity index 88% rename from proto/tarmac.proto rename to sdk/tarmac.proto index acf66a0..0e452d3 100644 --- a/proto/tarmac.proto +++ b/sdk/tarmac.proto @@ -1,8 +1,7 @@ syntax = "proto3"; package tarmac; - -option go_package = "github.com/tarmac-project/tarmac/proto"; +option go_package = "github.com/tarmac-project/protobuf-go/sdk"; // Status is used to return a status code and message to clients when // performing host callbacks to Tarmac. @@ -16,6 +15,7 @@ option go_package = "github.com/tarmac-project/tarmac/proto"; message Status { // Code is the status code for callback execution. int32 code = 1; + // Status is the human readable error message or success message for function // execution. string status = 2; From 56f5052e338d12b6dc4a3d94a3301bd2ce8f5598 Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 6 Oct 2024 09:58:51 -0700 Subject: [PATCH 4/6] chore(ci): remove redundant shell declaration --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5223d58..64634ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,6 @@ on: - main pull_request: -shell: bash - jobs: lint: runs-on: ubuntu-latest From 012d3699dbf4a8e85b12e1bce3390e01c3fad488 Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 6 Oct 2024 10:15:00 -0700 Subject: [PATCH 5/6] ci: add bash as default shell in workflows Because every workflow deserves a good shell companion. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64634ec..1352f89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: - main pull_request: +defaults: + run: + shell: bash + jobs: lint: runs-on: ubuntu-latest From 808e37c94e861e65e9a305dce6a20c5d00e45ffb Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 6 Oct 2024 14:57:10 -0700 Subject: [PATCH 6/6] ci: update GOPATH for CI runner's benefit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1352f89..c9cd019 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,4 +41,4 @@ jobs: - name: generate language files run: make build clean env: - GOPATH: /root/go + GOPATH: /home/runner/go