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

Aerospike storage backend #10131

Merged
merged 8 commits into from
Jan 12, 2021
Merged

Aerospike storage backend #10131

merged 8 commits into from
Jan 12, 2021

Conversation

reugn
Copy link
Contributor

@reugn reugn commented Oct 12, 2020

This adds support for Aerospike as a (non-HA) storage backend for Vault.

@hashicorp-cla
Copy link

hashicorp-cla commented Oct 12, 2020

CLA assistant check
All committers have signed the CLA.

@reugn
Copy link
Contributor Author

reugn commented Nov 3, 2020

@jasonodonnell , @calvn , @catsby , @Valarissa , @vishalnayak , @kalafut could you please review this PR?

@kalafut
Copy link
Contributor

kalafut commented Dec 4, 2020

@reugn Thanks for the PR! Yes, we'll be reviewing this soon.

Copy link
Contributor

@kalafut kalafut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good! Some initial feedback, mostly minor.

return nil, err
}

return &AerospikeBackend{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since (per the docs), set/namespace/hostname are all required, should we be validating != "" before successfully returning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like set is optional, and both namespace and hostname now have default values so we should be good.

return err
}

writePolicy := aero.NewWritePolicy(0, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I comment or docs link that has some details about this would be helpful.


record, err := a.client.Get(nil, aeroKey)
if err != nil {
if err.Error() == "Key not found" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the compared-to error exported by chance?


return &physical.Entry{
Key: key,
Value: record.Bins[valueBin].([]byte),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering indexing against valueBin in advance so we can check for the presence of the key and error (otherwise we'll panic on nil)

}

// Put is used to insert or update an entry.
func (a *AerospikeBackend) Put(ctx context.Context, entry *physical.Entry) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ctx/_ on these unused ctx parameters

}
recordKey := res.Record.Bins[keyBin].(string)
if strings.HasPrefix(recordKey, prefix) {
trimPrefix := strings.Replace(recordKey, prefix, "", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.TrimPrefix is a little simpler.

keyList = append(keyList, keys[0])
} else {
withSlash := keys[0] + "/"
if !listContains(keyList, withSlash) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a helper you can use:

func StrListContains(haystack []string, needle string) bool {

}

func hash(s string) string {
h := fnv.New32a()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this was chosen in particular? 32-bits is a fairly small hash size. We'd typically use sha256 to satisfy both irreversibility and collision avoidance.


# Aerospike Storage Backend

The Aerospike storage backend is used to persist Vault's data in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Aerospike storage backend is used to persist Vault's data in
The Aerospike storage backend is used to persist Vault's data in an

page_title: Aerospike - Storage Backends - Configuration
sidebar_title: Aerospike
description: |-
The Aerospike storage backend is used to persist Vault's data in Aerospike
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Aerospike storage backend is used to persist Vault's data in Aerospike
The Aerospike storage backend is used to persist Vault's data in an Aerospike

@kalafut kalafut self-assigned this Dec 9, 2020
@@ -0,0 +1,50 @@
---
Copy link
Contributor

@kalafut kalafut Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update the JSON to reference this new file as well:

category: 'storage',

policy.User = conf["username"]
policy.Password = conf["password"]

port, err := strconv.Atoi(conf["port"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If port is not provided, the error returned does not make it obvious that this is the case. Consider checking the value beforehand separately.

strconv.Atoi: parsing "": invalid syntax

ContainerName: "aerospikedb",
ImageTag: "latest",
Ports: []string{"3000/tcp", "3001/tcp", "3002/tcp", "3003/tcp"},
DoNotAutoRemove: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strictly necessary? This leaves dangling containers on the host, and may result in errors if tests are ran multiple times due to colliding container name.

@reugn
Copy link
Contributor Author

reugn commented Dec 10, 2020

@kalafut , @calvn thanks for the review. Fixes and improvements were done.

@reugn reugn requested review from kalafut and calvn December 10, 2020 15:36
go.mod Outdated
@@ -17,6 +17,7 @@ require (
github.com/SAP/go-hdb v0.14.1
github.com/Sectorbob/mlab-ns2 v0.0.0-20171030222938-d3aa0c295a8a
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/aerospike/aerospike-client-go v3.1.0+incompatible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit curious as to why this particular pseudo-version was chosen since v3.1.1 is available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, the +incompatible label is actually how go/mod sees the release: https://pkg.go.dev/github.com/aerospike/[email protected]+incompatible?tab=versions

Since v3.1.1+incompatible has been released, we should consider bumping it to that version (unless there's a particular reason not to)


defaultNamespace = "test"

defaultHost = "127.0.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since this is assigned as the default hostname, can we rename this to defaultHostname?

Copy link
Contributor

@calvn calvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor suggestions, otherwise looks good!


- `auth_mode` `(string: "INTERNAL")` - Specifies the authentication mode when user/password is defined (INTERNAL/EXTERNAL).

- `timeout` `(int: 30000)` - Initial host connection timeout duration in milliseconds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the timeout and idle_timeout values come from?

physical/aerospike/aerospike.go Show resolved Hide resolved
go.mod Outdated
@@ -17,6 +17,7 @@ require (
github.com/SAP/go-hdb v0.14.1
github.com/Sectorbob/mlab-ns2 v0.0.0-20171030222938-d3aa0c295a8a
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/aerospike/aerospike-client-go v3.1.0+incompatible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, the +incompatible label is actually how go/mod sees the release: https://pkg.go.dev/github.com/aerospike/[email protected]+incompatible?tab=versions

Since v3.1.1+incompatible has been released, we should consider bumping it to that version (unless there's a particular reason not to)

return nil, err
}

return &AerospikeBackend{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like set is optional, and both namespace and hostname now have default values so we should be good.

@reugn reugn force-pushed the aerospike_backend branch from 263443e to e234700 Compare January 6, 2021 07:43
@reugn
Copy link
Contributor Author

reugn commented Jan 6, 2021

@calvn for some reason, it doesn't pass the test-go-race-remote-docker with the aerospike client v3.1.1 .

@calvn
Copy link
Contributor

calvn commented Jan 12, 2021

Can you give v3.1.1 another try? The failure seems to be from a non-related test:

Failed
=== RUN   TestRaft_SnapshotAPI_RekeyRotate_Backward
--- FAIL: TestRaft_SnapshotAPI_RekeyRotate_Backward (0.00s)

There also seems to be a conflict with go.sum since your latest push. It's looking ready though!

@calvn calvn self-requested a review January 12, 2021 17:18
@reugn reugn force-pushed the aerospike_backend branch from ae3b7a0 to e234700 Compare January 12, 2021 17:59
@reugn
Copy link
Contributor Author

reugn commented Jan 12, 2021

Still failed.

@calvn
Copy link
Contributor

calvn commented Jan 12, 2021

Looks like that's a known flaky test. I'm kicking off CI again to see if we can get a passing run.

@calvn
Copy link
Contributor

calvn commented Jan 12, 2021

@reugn can you merge master into this PR to get the latest set of changes and ensure that things are still working? Some of the flakiness and test failures might have already been addressed on master.

@calvn
Copy link
Contributor

calvn commented Jan 12, 2021

Can you move the docs page to website/content/docs/configuration/storage/? We recently changed where these files live.

@calvn calvn added this to the 1.7 milestone Jan 12, 2021
@calvn calvn merged commit 6423be8 into hashicorp:master Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants