Skip to content

Commit

Permalink
Small adjustments to support the Serverless cloud merge (FeatureBaseD…
Browse files Browse the repository at this point in the history
…B#2385)

This just changes a make target and the CLI setup. Nothing in
featurebase is actually affected.

(cherry picked from commit 33bc69c)
  • Loading branch information
travisturner authored and ch7ck committed Jan 10, 2023
1 parent 0f67a0c commit 69a1744
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,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
Expand Down
21 changes: 18 additions & 3 deletions ctl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/chzyer/readline"
"github.com/jedib0t/go-pretty/table"
Expand All @@ -23,6 +24,7 @@ import (
)

const (
defaultHost string = "localhost"
promptBegin string = "fbsql> "
promptMid string = " -> "
terminationChar string = ";"
Expand Down Expand Up @@ -71,7 +73,7 @@ func NewCLICommand(logdest logger.Logger) *CLICommand {
}
}
return &CLICommand{
Host: "localhost",
Host: defaultHost,
HistoryPath: historyPath,

OrganizationID: "",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dax/mds/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,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,
Expand Down
8 changes: 4 additions & 4 deletions fbcloud/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions fbcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (cq *Queryer) tokenRefresh() error {
}
cq.token = token
cq.lastRefresh = time.Now()
fmt.Println("refreshed auth token")
return nil
}

Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 69a1744

Please sign in to comment.