-
Notifications
You must be signed in to change notification settings - Fork 28
feat: support mongo connector #471
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d87d5d2
mongo connector
undertaker86001 9aca2cb
add docs
undertaker86001 2f345d5
add mongodb frontend && update background
undertaker86001 645931a
add test && doc
undertaker86001 d121461
add en doc
undertaker86001 7d6dc99
remove useless doc
undertaker86001 4ce84f4
add mutli mode
undertaker86001 fb634d8
update doc
undertaker86001 d36de5a
fix test
kitalkuyo-gita f5e66b4
fix: correct syntax error in MongoDB plugin tests
devin-ai-integration[bot] cc6547f
fix connection leak
f407c4c
remove time.sleep
f793bf9
refactor: support dynamic lastsynctime
45716f8
refactor:adapter sync_strategy
f28b36f
refactor: pre-allocate slice
dec2283
add system field
undertaker86001 c0ac8aa
refactor: use task framework
undertaker86001 5e75ebe
Merge branch 'issue-456' of https://github.com/undertaker86001/coco-s…
undertaker86001 4d817e8
remove useless files
undertaker86001 fe69e19
remove useless files
undertaker86001 bb3351a
update doc
undertaker86001 df53181
remove useless doc
undertaker86001 23f0111
refactor: simpfy monitor
undertaker86001 7114911
extract common config
undertaker86001 7f1e583
Merge remote-tracking branch 'upstream/main' into issue-456
undertaker86001 dc5ae54
merge conf
undertaker86001 9aa28fb
fix test && remove useless code
ae52455
fix imports
eeeb02e
add field mapping
ebb21ef
update imports
8b7ff74
Merge remote-tracking branch 'upstream/main' into issue-456
2667d5d
Merge branch 'issue-456' of https://github.com/undertaker86001/coco-s…
kitalkuyo-gita d87a9f3
fix tests
kitalkuyo-gita ce3c7a1
fix tests
kitalkuyo-gita 1117add
fix: update MongoDB integration test to match new config structure
kitalkuyo-gita b89461c
Merge branch 'main' into issue-456
medcl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // MongoDB initialization script for testing | ||
| db = db.getSiblingDB('coco_test'); | ||
|
|
||
| // Create test user | ||
| db.createUser({ | ||
| user: 'coco_test', | ||
| pwd: 'test_password', | ||
| roles: [ | ||
| { | ||
| role: 'readWrite', | ||
| db: 'coco_test' | ||
| } | ||
| ] | ||
| }); | ||
|
|
||
| // Create test collections with sample data | ||
| db.articles.insertMany([ | ||
| { | ||
| title: "Sample Article 1", | ||
| content: "This is sample content for testing", | ||
| category: "Technology", | ||
| tags: ["mongodb", "database"], | ||
| url: "https://example.com/article1", | ||
| updated_at: new Date(), | ||
| status: "published" | ||
| }, | ||
| { | ||
| title: "Sample Article 2", | ||
| content: "Another sample content for testing", | ||
| category: "Programming", | ||
| tags: ["go", "backend"], | ||
| url: "https://example.com/article2", | ||
| updated_at: new Date(), | ||
| status: "draft" | ||
| } | ||
| ]); | ||
|
|
||
| // Create indexes for better performance | ||
| db.articles.createIndex({ "updated_at": 1 }); | ||
| db.articles.createIndex({ "status": 1 }); | ||
| db.articles.createIndex({ "category": 1 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| mongodb: | ||
| image: mongo:7.0 | ||
| container_name: coco-mongodb-test | ||
| ports: | ||
| - "27017:27017" | ||
| environment: | ||
| MONGO_INITDB_ROOT_USERNAME: admin | ||
| MONGO_INITDB_ROOT_PASSWORD: password | ||
| MONGO_INITDB_DATABASE: coco_test | ||
| volumes: | ||
| - mongodb_data:/data/db | ||
| - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro | ||
| networks: | ||
| - coco-test | ||
|
|
||
| mongodb-replica: | ||
| image: mongo:7.0 | ||
| container_name: coco-mongodb-replica-test | ||
| ports: | ||
| - "27018:27017" | ||
| command: mongod --replSet rs0 --bind_ip_all | ||
| volumes: | ||
| - mongodb_replica_data:/data/db | ||
| networks: | ||
| - coco-test | ||
|
|
||
| volumes: | ||
| mongodb_data: | ||
| mongodb_replica_data: | ||
|
|
||
| networks: | ||
| coco-test: | ||
| driver: bridge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # MongoDB Connector Default Configuration | ||
| mongodb: | ||
| # Default connection settings | ||
| default_timeout: "30s" | ||
| default_batch_size: 1000 | ||
| default_max_pool_size: 10 | ||
|
|
||
| # Default sync settings | ||
| default_sync_strategy: "full" | ||
|
|
||
| # Performance tuning | ||
| max_concurrent_collections: 5 | ||
| memory_gc_interval: 10000 | ||
|
|
||
| # Retry settings | ||
| connection_retry_attempts: 3 | ||
| connection_retry_delay: "30s" | ||
|
|
||
| # Logging | ||
| log_level: "info" | ||
| log_slow_queries: true | ||
| slow_query_threshold: "5s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* Copyright © INFINI LTD. All rights reserved. | ||
| * Web: https://infinilabs.com | ||
| * Email: hello#infini.ltd */ | ||
|
|
||
| package mongodb | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // Config defines the configuration for the MongoDB connector | ||
| type Config struct { | ||
| // Connection configuration | ||
| ConnectionURI string `config:"connection_uri"` | ||
| Host string `config:"host"` | ||
| Port int `config:"port"` | ||
| Username string `config:"username"` | ||
| Password string `config:"password"` | ||
| Database string `config:"database"` | ||
| AuthDatabase string `config:"auth_database"` | ||
|
|
||
| // Replica set and sharding configuration | ||
| ReplicaSet string `config:"replica_set"` | ||
| ReadPreference string `config:"read_preference"` | ||
|
|
||
| // TLS/SSL configuration | ||
| EnableTLS bool `config:"enable_tls"` | ||
| TLSCAFile string `config:"tls_ca_file"` | ||
| TLSCertFile string `config:"tls_cert_file"` | ||
| TLSKeyFile string `config:"tls_key_file"` | ||
| TLSInsecure bool `config:"tls_insecure"` | ||
|
|
||
| // Data filtering configuration | ||
| Collections []CollectionConfig `config:"collections"` | ||
|
|
||
| // Performance optimization configuration | ||
| BatchSize int `config:"batch_size"` | ||
| Timeout string `config:"timeout"` | ||
| MaxPoolSize int `config:"max_pool_size"` | ||
|
|
||
| // Sync strategy | ||
| SyncStrategy string `config:"sync_strategy"` | ||
undertaker86001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TimestampField string `config:"timestamp_field"` | ||
| LastSyncTime time.Time `config:"last_sync_time"` | ||
undertaker86001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| type CollectionConfig struct { | ||
| Name string `config:"name"` | ||
| Filter map[string]interface{} `config:"filter"` | ||
| Fields []string `config:"fields"` | ||
| TitleField string `config:"title_field"` | ||
undertaker86001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ContentField string `config:"content_field"` | ||
| CategoryField string `config:"category_field"` | ||
| TagsField string `config:"tags_field"` | ||
| URLField string `config:"url_field"` | ||
| TimestampField string `config:"timestamp_field"` | ||
| } | ||
|
|
||
| func (p *Plugin) setDefaultConfig(config *Config) { | ||
| if config.BatchSize <= 0 { | ||
| config.BatchSize = 1000 | ||
| } | ||
| if config.MaxPoolSize <= 0 { | ||
| config.MaxPoolSize = 10 | ||
| } | ||
| if config.Timeout == "" { | ||
| config.Timeout = "30s" | ||
| } | ||
| if config.SyncStrategy == "" { | ||
| config.SyncStrategy = "full" | ||
| } | ||
| } | ||
|
|
||
| func (p *Plugin) validateConfig(config *Config) error { | ||
| if config.ConnectionURI == "" { | ||
| if config.Host == "" { | ||
| return fmt.Errorf("either connection_uri or host must be specified") | ||
| } | ||
| if config.Database == "" { | ||
| return fmt.Errorf("database must be specified") | ||
| } | ||
| } | ||
|
|
||
| if len(config.Collections) == 0 { | ||
| return fmt.Errorf("at least one collection must be configured") | ||
| } | ||
|
|
||
| for i, coll := range config.Collections { | ||
| if coll.Name == "" { | ||
| return fmt.Errorf("collection[%d].name is required", i) | ||
| } | ||
| } | ||
|
|
||
| if config.BatchSize < 0 { | ||
| return fmt.Errorf("batch_size must be positive") | ||
| } | ||
|
|
||
| if config.MaxPoolSize < 0 { | ||
| return fmt.Errorf("max_pool_size must be positive") | ||
| } | ||
|
|
||
| if config.SyncStrategy != "" && config.SyncStrategy != "full" && config.SyncStrategy != "incremental" { | ||
| return fmt.Errorf("sync_strategy must be 'full' or 'incremental'") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.