Skip to content

feat: Add Key-Value Store Functionality#66

Merged
jshlbrd merged 8 commits intomainfrom
jshlbrd/caching
Jan 10, 2023
Merged

feat: Add Key-Value Store Functionality#66
jshlbrd merged 8 commits intomainfrom
jshlbrd/caching

Conversation

@jshlbrd
Copy link
Contributor

@jshlbrd jshlbrd commented Jan 9, 2023

Description

  • Adds support for read-write and read-only key-value stores
    • New interface with factory (internal/kv)
    • Methods for managing stores (Setup, Close), putting values into stores (Set, SetWithTTL), and retrieving values from stores (Get)
    • KV backends in this PR:
      • AWS DynamoDB (rw)
      • Memory (rw)
      • CSV File (ro)
      • JSON File (ro)
      • Text File (ro)
  • Adds a kv_store processor for retrieving and putting items into any KV store, all features of the KV store interface are supported
  • Adds two new patterns for the kv_store processor
  • Adds the DynamoDB API call GetItem (required for the DynamoDB KV store)

Motivation and Context

This addresses both #55 and #65 -- both use cases are abstracted into the generic KV store use case, which can be extended with support for future backends. This functionality enables this functionality / future work:

  • Idempotent Producers #59
  • Idempotent consumers (not ticketed)
  • Idempotent processing (now possible via configurations as code)
  • Refactoring internal/ip/database into KV store
  • Threat intelligence feeds (now possible via configurations as code)
  • Simplifying the project's caching strategies

How Has This Been Tested?

Unit tests are passing and all features were locally integration tested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@jshlbrd jshlbrd marked this pull request as ready for review January 9, 2023 17:48
@jshlbrd jshlbrd requested a review from a team as a code owner January 9, 2023 17:48
Copy link
Contributor

@julieagnessparks julieagnessparks left a comment

Choose a reason for hiding this comment

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

I like the add of Zeek Intelligence Framework, I was unfamiliar with it but it's a great way to bring in indicators.

Only concern is having documentation for how a user to utilize the test files you added.

"github.com/brexhq/substation/internal/kv"
)

func Example_memory() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there instructions for how someone should use this example test / what should be filled in (TODO)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, this is meant as an example for developers and not users who interact through configurations. Once we've merged this the user-facing documentation would be added to substation.readme.io, both as a processor and likely in a new section that describes the different types of KV stores.

@jshlbrd
Copy link
Contributor Author

jshlbrd commented Jan 9, 2023

I like the add of Zeek Intelligence Framework, I was unfamiliar with it but it's a great way to bring in indicators.

Yeah, that's a nice example of how we can create read-only KV stores from almost any file. Those files are just fancy CSV files (they use tab as the delimiter, so technically it's TSV) and this makes it relatively easy to retrieve and parse them.

Copy link
Contributor

@shellcromancer shellcromancer left a comment

Choose a reason for hiding this comment

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

Nice way to combine the cachine with the lookup processor proposal! Left a few comments on the semantics for the JSON KV and a few other things but overall this looks great! :)

//
// This is optional and defaults to using no TTL when setting values into the store.
OffsetTTL int `json:"offset_ttl"`
// KVOptions determine the type of KV store used by the processor. Refer to internal/kv
Copy link
Contributor

Choose a reason for hiding this comment

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

docs: this could be more clear as a doclink

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't think this matters since it's not exported -- check it out here https://pkg.go.dev/github.com/brexhq/substation@v0.8.0/process

@jshlbrd jshlbrd merged commit 39b88c9 into main Jan 10, 2023
@jshlbrd jshlbrd deleted the jshlbrd/caching branch January 10, 2023 21:23
@jshlbrd jshlbrd linked an issue Jan 11, 2023 that may be closed by this pull request
@jshlbrd jshlbrd mentioned this pull request Jan 11, 2023
@jshlbrd jshlbrd linked an issue Jan 11, 2023 that may be closed by this pull request
@jshlbrd jshlbrd mentioned this pull request Jan 11, 2023
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.

File/Lookup processor Application-Level Caching

3 participants