Small adjustments to support the Serverless cloud merge (#2385)

This just changes a make target and the CLI setup. Nothing in
featurebase is actually affected.
This commit is contained in:
Travis Turner 2022-12-22 12:22:09 -06:00 committed by GitHub
parent c8242684f1
commit 33bc69ccc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 15 deletions

View file

@ -242,8 +242,8 @@ docker-image-datagen: vendor
docker build --tag dax/datagen --file Dockerfile-datagen .
ecr-push-featurebase: docker-login
docker tag dax/featurebase:latest $(AWS_ACCOUNTID).dkr.ecr.us-east-2.amazonaws.com/dax:latest
docker push $(AWS_ACCOUNTID).dkr.ecr.us-east-2.amazonaws.com/dax:latest
docker tag dax/featurebase:latest $(AWS_ACCOUNTID).dkr.ecr.us-east-2.amazonaws.com/dax/featurebase:latest
docker push $(AWS_ACCOUNTID).dkr.ecr.us-east-2.amazonaws.com/dax/featurebase:latest
ecr-push-datagen: docker-login
docker tag dax/datagen:latest $(AWS_ACCOUNTID).dkr.ecr.us-east-2.amazonaws.com/dax/datagen:latest

View file

@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/chzyer/readline"
"github.com/jedib0t/go-pretty/table"
@ -23,6 +24,7 @@ import (
)
const (
defaultHost string = "localhost"
promptBegin string = "fbsql> "
promptMid string = " -> "
terminationChar string = ";"
@ -71,7 +73,7 @@ func NewCLICommand(logdest logger.Logger) *CLICommand {
}
}
return &CLICommand{
Host: "localhost",
Host: defaultHost,
HistoryPath: historyPath,
OrganizationID: "",
@ -118,7 +120,7 @@ func (cmd *CLICommand) setupClient() error {
case featurebaseTypeCloud:
fmt.Println("Detected cloud deployment")
cmd.queryer = &fbcloud.Queryer{
Host: cmd.Host,
Host: hostPort(cmd.Host, cmd.Port),
ClientID: cmd.ClientID,
Region: cmd.Region,
@ -174,6 +176,16 @@ func (cmd *CLICommand) detectFBType() (featurebaseType, error) {
typ: featurebaseTypeStandard,
},
)
} else if strings.HasPrefix(cmd.Host, "https") {
// https suggesting we might be connecting to a cloud host
trials = append(trials,
// cloud
trial{
port: "",
health: "health",
typ: featurebaseTypeCloud,
},
)
} else {
// Try default ports just in case.
trials = append(trials,
@ -192,9 +204,12 @@ func (cmd *CLICommand) detectFBType() (featurebaseType, error) {
)
}
client := http.Client{
Timeout: 100 * time.Millisecond,
}
for _, trial := range trials {
url := hostPort(cmd.Host, trial.port) + trial.health
if resp, err := http.Get(url); err != nil {
if resp, err := client.Get(url); err != nil {
continue
} else if resp.StatusCode/100 == 2 {
cmd.Port = trial.port

View file

@ -427,7 +427,7 @@ func (c *Client) TranslateNodes(ctx context.Context, qtid dax.QualifiedTableID,
func (c *Client) RegisterNode(ctx context.Context, node *dax.Node) error {
url := fmt.Sprintf("%s/register-node", c.address.WithScheme(defaultScheme))
c.logger.Debugf("RegisterNode url: %s", url)
c.logger.Debugf("RegisterNode: %s, url: %s", node.Address, url)
req := &mdshttp.RegisterNodeRequest{
Address: node.Address,

View file

@ -23,11 +23,11 @@ type cognitoParameters struct {
type cognitoAuthRequest struct {
AuthParameters cognitoParameters `json:"AuthParameters"`
AuthFlow string `json:"AuthFlow"`
AppClientId string `json:"ClientId"`
AppClientID string `json:"ClientId"`
}
type cognitoAuthResult struct {
IdToken string `json:"IdToken"`
IDToken string `json:"IdToken"`
}
type cognitoAuthResponse struct {
@ -41,7 +41,7 @@ func authenticate(clientID, region, email, password string) (string, error) {
Password: password,
},
AuthFlow: authFlow,
AppClientId: clientID,
AppClientID: clientID,
}
data, err := json.Marshal(authPayload)
@ -75,5 +75,5 @@ func authenticate(clientID, region, email, password string) (string, error) {
return "", errors.Wrap(err, "decoding cognito auth response")
}
return auth.Result.IdToken, nil
return auth.Result.IDToken, nil
}

View file

@ -37,7 +37,6 @@ func (cq *Queryer) tokenRefresh() error {
}
cq.token = token
cq.lastRefresh = time.Now()
fmt.Println("refreshed auth token")
return nil
}
@ -53,7 +52,7 @@ func (cq *Queryer) Query(org, db, sql string) (*featurebase.WireQueryResponse, e
return nil, errors.Wrap(err, "refreshing token")
}
}
url := fmt.Sprintf("%s/v2/databases/%s/query", cq.Host, db)
url := fmt.Sprintf("%s/v2/databases/%s/query/sql", cq.Host, db)
sqlReq := &tokenizedSQL{
Language: "sql",
@ -71,6 +70,7 @@ func (cq *Queryer) Query(org, db, sql string) (*featurebase.WireQueryResponse, e
if err != nil {
return nil, errors.Wrap(err, "creating new post request")
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", cq.token)
var resp *http.Response
@ -85,11 +85,11 @@ func (cq *Queryer) Query(org, db, sql string) (*featurebase.WireQueryResponse, e
if resp.StatusCode/100 != 2 {
return nil, errors.Errorf("unexpected status: %s, full body: '%s'", resp.Status, fullbod)
}
var cloudResp cloudResponse
if err := json.Unmarshal(fullbod, &cloudResp); err != nil {
var sqlResponse featurebase.WireQueryResponse
if err := json.Unmarshal(fullbod, &sqlResponse); err != nil {
return nil, errors.Wrapf(err, "decoding cloud response, body:\n%s", fullbod)
}
sqlResponse := cloudResp.Results
return &sqlResponse, nil
}