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

New segment mongodb #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

New segment mongodb #81

wants to merge 2 commits into from

Conversation

ynHuber
Copy link
Collaborator

@ynHuber ynHuber commented Oct 29, 2024

Allows exporting to an external mongoDb.
By using capped collections, the disk size used by the flowpipeline output can be limited to a fixed size.
Example usage:

  • segment: mongodb
    config:
    mongodb_uri: "mongodb://localhost:27017/"
    max_disk_usage: 1 GB
    database: "flowmonitoring"
    collection: "flowdata"
    fields: "SrcAddr,DstAddr"

Allows exporting to an external mongoDb.
By using capped collections, the disk size used by flowpipeline can be limited to a fixed size
Copy link
Collaborator

@debugloop debugloop left a comment

Choose a reason for hiding this comment

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

🚀


client, err := mongo.Connect(ctx, options.Client().ApplyURI(segment.mongodbUri))
if err != nil {
log.Panic(err) // this has already been checked in New
Copy link
Collaborator

Choose a reason for hiding this comment

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

It could still fail though ;)

Comment on lines +102 to +125
if config == nil {
return newsegment, errors.New("missing configuration for segment mongodb")
}

if config["mongodb_uri"] == "" {
return newsegment, errors.New("mongoDB: mongodb_uri not defined")
}
newsegment.mongodbUri = config["mongodb_uri"]

if config["database"] == "" {
log.Println("[INFO] mongoDB: no database defined - using default value (flowdata)")
config["database"] = "flowdata"
}
newsegment.databaseName = config["database"]

if config["collection"] == "" {
log.Println("[INFO] mongoDB: no collection defined - using default value (ringbuffer)")
config["collection"] = "ringbuffer"
}
newsegment.collectionName = config["collection"]

var ringbufferSize int64 = 10737418240
if config["max_disk_usage"] == "" {
log.Println("[INFO] mongoDB: no ring buffer size defined - using default value (10GB)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be time to rethink config parsing or even add some config parsing library in the future. I did not know enough about Go back in the day, but this sure is a lot of manual work.

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.

2 participants