Skip to content

Commit

Permalink
feat: add vearch module (#2560)
Browse files Browse the repository at this point in the history
* add vearch test package

* fix vearch dorker version

* add new file about contribution file

* add vearch module

* chore: wrong copy & paste

* makefile

* Update modules/vearch/vearch_test.go

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>

* add vearch modules

* remove fmt

---------

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
  • Loading branch information
zhanghexian and mdelapenya committed Jun 6, 2024
1 parent 88af617 commit 392b6e5
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, dolt, elasticsearch, gcloud, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, weaviate]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, dolt, elasticsearch, gcloud, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, vearch, weaviate]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
"name": "module / vault",
"path": "../modules/vault"
},
{
"name": "module / vearch",
"path": "../modules/vearch"
},
{
"name": "module / weaviate",
"path": "../modules/weaviate"
Expand Down
57 changes: 57 additions & 0 deletions docs/modules/vearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Vearch

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for Vearch.

## Adding this module to your project dependencies

Please run the following command to add the Vearch module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/vearch
```

## Usage example

<!--codeinclude-->
[Creating a Vearch container](../../modules/vearch/examples_test.go) inside_block:runVearchContainer
<!--/codeinclude-->

## Module reference

The Vearch module exposes one entrypoint function to create the Vearch container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the Vearch container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different Vearch Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for Vearch. E.g. `testcontainers.WithImage("vearch/vearch:latest")`.

{% include "../features/common_functional_options.md" %}

### Container Methods

The Vearch container exposes the following methods:

#### REST Endpoint

This method returns the REST endpoint of the Vearch container, using the default `9001` port.

<!--codeinclude-->
[Get REST endpoint](../../modules/vearch/vearch_test.go) inside_block:restEndpoint
<!--/codeinclude-->


1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ nav:
- modules/registry.md
- modules/surrealdb.md
- modules/vault.md
- modules/vearch.md
- modules/weaviate.md
- Examples:
- examples/index.md
Expand Down
5 changes: 5 additions & 0 deletions modules/vearch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-vearch
85 changes: 85 additions & 0 deletions modules/vearch/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[global]
# the name will validate join cluster by same name
name = "vearch"
# specify which resources to use to create space
resource_name = "default"
# you data save to disk path ,If you are in a production environment, You'd better set absolute paths
data = ["datas/","datas1/"]
# log path , If you are in a production environment, You'd better set absolute paths
log = "logs/"
# default log type for any model
level = "debug"
# master <-> ps <-> router will use this key to send or receive data
signkey = "secret"
# skip auth for master and router
skip_auth = true
# tell Vearch whether it should manage it's own instance of etcd or not
self_manage_etcd = false
# automatically remove the failed node and recover when new nodes join
auto_recover_ps = false
# support access etcd basic auth,depend on self_manage_etcd = true
support_etcd_auth = false
# ensure leader-follow raft data synchronization is consistent
raft_consistent = false

# self_manage_etcd = true,means manage etcd by yourself,need provide additional configuration
[etcd]
# etcd server ip or domain
address = ["127.0.0.1"]
# advertise_client_urls AND listen_client_urls
etcd_client_port = 2379
# provider username and password,if you turn on auth
user_name = "root"
password = ""

# if you are master you'd better set all config for router and ps and router and ps use default config it so cool
[[masters]]
# name machine name for cluster
name = "m1"
# ip or domain
address = "127.0.0.1"
# api port for http server
api_port = 8817
# port for etcd server
etcd_port = 2378
# listen_peer_urls List of comma separated URLs to listen on for peer traffic.
# advertise_peer_urls List of this member's peer URLs to advertise to the rest of the cluster. The URLs needed to be a comma-separated list.
etcd_peer_port = 2390
# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
# advertise_client_urls AND listen_client_urls
etcd_client_port = 2370
# init cluster state
cluster_state = "new"
pprof_port = 6062
# monitor
monitor_port = 8818

[router]
# port for server
port = 9001
# rpc_port = 9002
pprof_port = 6061
plugin_path = "plugin"
allow_origins = ["http://google.com"]

[ps]
# port for server
rpc_port = 8081
ps_heartbeat_timeout = 5 # seconds
# raft config begin
raft_heartbeat_port = 8898
raft_replicate_port = 8899
heartbeat-interval = 200 # ms
raft_retain_logs = 20000000
raft_replica_concurrency = 1
raft_snap_concurrency = 1
raft_truncate_count = 500000
# when behind leader this value, will stop the server for search
raft_diff_count = 10000
pprof_port = 6060
# if set true, this ps only use in db meta config
private = false
# seconds
flush_time_interval = 600
flush_count_threshold = 200000
37 changes: 37 additions & 0 deletions modules/vearch/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package vearch_test

import (
"context"
"fmt"
"log"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/vearch"
)

func ExampleRunContainer() {
ctx := context.Background()

vearchContainer, err := vearch.RunContainer(ctx, testcontainers.WithImage("vearch/vearch:latest"))
if err != nil {
log.Fatalf("failed to start container: %s", err)
}

// Clean up the container
defer func() {
if err := vearchContainer.Terminate(ctx); err != nil {
log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
}
}()
// }

state, err := vearchContainer.State(ctx)
if err != nil {
log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
}

fmt.Println(state.Running)

// Output:
// true
}
57 changes: 57 additions & 0 deletions modules/vearch/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module github.com/testcontainers/testcontainers-go/modules/vearch

go 1.22.0

require github.com/testcontainers/testcontainers-go v0.31.0

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.15 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..
Loading

0 comments on commit 392b6e5

Please sign in to comment.