2021-06-21 12:08:06 +08:00
# Development
2022-02-09 14:27:46 +08:00
This document will help to set up your Milvus development environment and to run tests. Please [file an issue ](https://github.com/milvus-io/milvus/issues/new/choose ) if there's a problem.
2021-06-21 12:08:06 +08:00
2023-06-06 14:06:36 +08:00
# Table of contents
2023-04-04 13:38:28 +08:00
- [Development ](#development )
- [Table of contents ](#table-of-contents )
- [Building Milvus with Docker ](#building-milvus-with-docker )
- [Building Milvus on a local OS/shell environment ](#building-milvus-on-a-local-osshell-environment )
- [Hardware Requirements ](#hardware-requirements )
- [Software Requirements ](#software-requirements )
- [Prerequisites ](#prerequisites )
- [Installing Dependencies ](#installing-dependencies )
- [Caveats ](#caveats )
- [CMake \& Conan ](#cmake--conan )
- [Go ](#go )
- [Docker \& Docker Compose ](#docker--docker-compose )
- [Building Milvus ](#building-milvus )
- [A Quick Start for Testing Milvus ](#a-quick-start-for-testing-milvus )
- [Pre-submission Verification ](#pre-submission-verification )
- [Unit Tests ](#unit-tests )
- [Code coverage ](#code-coverage )
- [E2E Tests ](#e2e-tests )
- [Test on local branch ](#test-on-local-branch )
- [With Linux and MacOS ](#with-linux-and-macos )
- [With docker ](#with-docker )
- [GitHub Flow ](#github-flow )
- [FAQs ](#faqs )
2021-07-07 15:12:00 +08:00
## Building Milvus with Docker
2022-02-09 14:27:46 +08:00
Our official Milvus versions are releases as Docker images. To build Milvus Docker on your own, please follow [these instructions ](https://github.com/milvus-io/milvus/blob/master/build/README.md ).
2021-07-07 15:12:00 +08:00
2021-06-21 12:08:06 +08:00
## Building Milvus on a local OS/shell environment
2022-02-09 14:27:46 +08:00
The details below outline the hardware and software requirements for building on Linux and MacOS.
2021-06-21 12:08:06 +08:00
### Hardware Requirements
2022-02-09 14:27:46 +08:00
The following specification (either physical or virtual machine resources) is recommended for Milvus to build and run from source code.
2021-06-21 12:08:06 +08:00
```
- 8GB of RAM
- 50GB of free disk space
```
2021-09-28 09:52:04 +08:00
### Software Requirements
2021-06-21 12:08:06 +08:00
2022-02-09 14:27:46 +08:00
All Linux distributions are available for Milvus development. However a majority of our contributor worked with Ubuntu or CentOS systems, with a small portion of Mac (both x86_64 and Apple Silicon) contributors. If you would like Milvus to build and run on other distributions, you are more than welcome to file an issue and contribute!
2021-06-21 12:08:06 +08:00
2022-02-09 14:27:46 +08:00
Here's a list of verified OS types where Milvus can successfully build and run:
2021-06-21 12:08:06 +08:00
2023-06-06 14:06:36 +08:00
- Debian/Ubuntu
2023-08-21 09:54:20 +08:00
- Amazon Linux
2023-06-06 14:06:36 +08:00
- MacOS (x86_64)
- MacOS (Apple Silicon)
2022-02-09 14:27:46 +08:00
#### Prerequisites
2023-06-06 14:06:36 +08:00
Linux systems (Recommend Ubuntu 20.04 or later):
2022-02-09 14:27:46 +08:00
```bash
2023-11-10 07:46:18 +08:00
go: >= 1.20
2022-02-09 14:27:46 +08:00
cmake: >= 3.18
gcc: 7.5
2021-06-21 12:08:06 +08:00
```
2022-02-09 14:27:46 +08:00
MacOS systems with x86_64 (Big Sur 11.5 or later recommended):
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
```bash
2023-11-10 07:46:18 +08:00
go: >= 1.20
2022-02-09 14:27:46 +08:00
cmake: >= 3.18
2023-04-04 13:38:28 +08:00
llvm: >= 15
2022-02-09 14:27:46 +08:00
```
2021-06-28 16:30:17 +08:00
2022-02-09 14:27:46 +08:00
MacOS systems with Apple Silicon (Monterey 12.0.1 or later recommended):
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
```bash
2023-11-10 07:46:18 +08:00
go: >= 1.20 (Arch=ARM64)
2022-02-09 14:27:46 +08:00
cmake: >= 3.18
2023-04-04 13:38:28 +08:00
llvm: >= 15
2022-02-09 14:27:46 +08:00
```
#### Installing Dependencies
2021-07-09 16:24:39 +08:00
2022-02-09 14:27:46 +08:00
In the Milvus repository root, simply run:
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
```bash
$ ./scripts/install_deps.sh
2021-06-28 16:30:17 +08:00
```
2022-02-09 14:27:46 +08:00
#### Caveats
2023-06-06 14:06:36 +08:00
- [Google Test ](https://github.com/google/googletest.git ) is automatically cloned from GitHub, which in some case could conflict with your local google test library.
2022-02-09 14:27:46 +08:00
2021-06-21 12:08:06 +08:00
Once you have finished, confirm that `gcc` and `make` are installed:
```shell
2021-09-17 10:25:50 +08:00
$ gcc --version
$ make --version
2021-06-21 12:08:06 +08:00
```
2023-04-04 13:38:28 +08:00
#### CMake & Conan
2021-06-21 12:08:06 +08:00
The algorithm library of Milvus, Knowhere is written in c++. CMake is required in the Milvus compilation. If you don't have it, please follow the instructions in the [Installing CMake ](https://cmake.org/install/ ).
Confirm that cmake is available:
```shell
2021-09-17 10:25:50 +08:00
$ cmake --version
2021-06-21 12:08:06 +08:00
```
2023-06-06 14:06:36 +08:00
2023-04-04 13:38:28 +08:00
Note: 3.25 or higher cmake version is required to build Milvus.
Milvus uses Conan to manage third-party dependencies for c++.
2023-06-06 14:06:36 +08:00
Install Conan
2023-04-04 13:38:28 +08:00
```shell
2023-10-24 17:50:10 +08:00
pip install conan==1.61.0
2023-04-04 13:38:28 +08:00
```
2023-06-06 14:06:36 +08:00
2023-04-04 13:38:28 +08:00
Note: Conan version 2.x is not currently supported, please use version 1.58.
2021-06-21 12:08:06 +08:00
#### Go
Milvus is written in [Go ](http://golang.org/ ). If you don't have a Go development environment, please follow the instructions in the [Go Getting Started guide ](https://golang.org/doc/install ).
Confirm that your `GOPATH` and `GOBIN` environment variables are correctly set as detailed in [How to Write Go Code ](https://golang.org/doc/code.html ) before proceeding.
```shell
2021-09-17 10:25:50 +08:00
$ go version
2021-06-21 12:08:06 +08:00
```
2023-11-10 07:46:18 +08:00
Note: go >= 1.20 is required to build Milvus.
2021-06-21 12:08:06 +08:00
#### Docker & Docker Compose
2021-10-26 14:31:03 +08:00
Milvus depends on etcd, Pulsar and MinIO. Using Docker Compose to manage these is an easy way in local development. To install Docker and Docker Compose in your development environment, follow the instructions from the Docker website below:
2021-06-21 12:08:06 +08:00
2023-06-06 14:06:36 +08:00
- Docker: https://docs.docker.com/get-docker/
- Docker Compose: https://docs.docker.com/compose/install/
2021-06-21 12:08:06 +08:00
### Building Milvus
To build the Milvus project, run the following command:
```shell
2023-04-04 13:38:28 +08:00
$ make
2021-06-21 12:08:06 +08:00
```
If this command succeed, you will now have an executable at `bin/milvus` off of your Milvus project directory.
2021-10-26 14:31:03 +08:00
If you want to update proto file before `make` , we can use the following command:
2023-06-06 14:06:36 +08:00
2021-10-05 21:10:22 +08:00
```shell
$ make generated-proto-go
```
If you want to know more, you can read Makefile.
2021-06-21 12:08:06 +08:00
## A Quick Start for Testing Milvus
2022-02-09 14:27:46 +08:00
### Pre-submission Verification
2021-06-21 12:08:06 +08:00
2022-02-09 14:27:46 +08:00
Pre-submission verification provides a battery of checks and tests to give your pull request the best chance of being accepted. Developers need to run as many verification tests as possible locally.
2021-06-21 12:08:06 +08:00
2022-02-09 14:27:46 +08:00
To run all pre-submission verification tests, use this command:
2021-06-21 12:08:06 +08:00
```shell
2021-09-17 10:25:50 +08:00
$ make verifiers
2021-06-21 12:08:06 +08:00
```
### Unit Tests
2022-02-09 14:27:46 +08:00
It is required that all pull request candidates should pass all Milvus unit tests.
2021-06-21 12:08:06 +08:00
2022-02-09 14:27:46 +08:00
Beforce running unit tests, you need to first bring up the Milvus deployment environment.
You may set up a local docker environment with our docker compose yaml file to start unit testing.
For Apple Silicon users (Apple M1):
2023-06-06 14:06:36 +08:00
2021-06-21 12:08:06 +08:00
```shell
2022-02-09 14:27:46 +08:00
$ cd deployments/docker/dev
$ docker-compose -f docker-compose-apple-silicon.yml up -d
$ cd ../../../
2021-09-17 10:25:50 +08:00
$ make unittest
2021-06-21 12:08:06 +08:00
```
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
For others:
2023-06-06 14:06:36 +08:00
2021-10-05 21:10:22 +08:00
```shell
$ cd deployments/docker/dev
$ docker-compose up -d
$ cd ../../../
$ make unittest
```
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
To run only cpp test:
2023-06-06 14:06:36 +08:00
2021-10-05 21:10:22 +08:00
```shell
2022-02-09 14:27:46 +08:00
$ make test-cpp
2021-10-05 21:10:22 +08:00
```
2022-02-09 14:27:46 +08:00
To run only go test:
2023-06-06 14:06:36 +08:00
2021-10-05 21:10:22 +08:00
```shell
2022-02-09 14:27:46 +08:00
$ make test-go
2021-10-05 21:10:22 +08:00
```
2022-02-09 14:27:46 +08:00
To run a single test case (TestSearchTask in /internal/proxy directory, for example):
2023-06-06 14:06:36 +08:00
2021-09-13 09:44:02 +08:00
```shell
2022-06-30 14:00:18 +08:00
$ source scripts/setenv.sh & & go test -v ./internal/proxy/ -test.run TestSearchTask
```
If using Mac with M1 chip
2023-06-06 14:06:36 +08:00
2022-06-30 14:00:18 +08:00
```
$ source scripts/setenv.sh & & go test -tags=dynamic -v ./internal/proxy/ -test.run TestSearchTask
2021-09-13 09:44:02 +08:00
```
2021-09-22 17:47:53 +08:00
### Code coverage
2022-02-09 14:27:46 +08:00
Before submitting your pull request, make sure your code change is covered by unit test. Use the following commands to check code coverage rate:
2021-09-22 17:47:53 +08:00
2021-10-04 09:07:56 +08:00
Run unit test and generate code coverage report:
2023-06-06 14:06:36 +08:00
2021-09-22 17:47:53 +08:00
```shell
$ make codecov
```
2023-06-06 14:06:36 +08:00
2021-09-22 17:47:53 +08:00
This command will generate html report for Golang and C++ respectively.
For Golang report, open the `go_coverage.html` under milvus project path.
For C++ report, open the `cpp_coverage/index.html` under milvus project path.
You also can generate Golang coverage report by:
2023-06-06 14:06:36 +08:00
2021-09-22 17:47:53 +08:00
```shell
$ make codecov-go
```
2023-06-06 14:06:36 +08:00
2021-09-22 17:47:53 +08:00
Or C++ coverage report by:
2023-06-06 14:06:36 +08:00
2021-09-22 17:47:53 +08:00
```shell
$ make codecov-cpp
```
2021-09-13 09:44:02 +08:00
2021-06-21 12:08:06 +08:00
### E2E Tests
2021-10-26 14:31:03 +08:00
Milvus uses Python SDK to write test cases to verify the correctness of Milvus functions. Before running E2E tests, you need a running Milvus:
2021-06-21 12:08:06 +08:00
```shell
2021-10-05 21:10:22 +08:00
# Running Milvus cluster
2021-09-17 10:25:50 +08:00
$ cd deployments/docker/dev
$ docker-compose up -d
$ cd ../../../
$ ./scripts/start_cluster.sh
2021-10-05 21:10:22 +08:00
# Or running Milvus standalone
2022-03-31 09:21:28 +08:00
$ cd deployments/docker/dev
2021-10-05 21:10:22 +08:00
$ docker-compose up -d
$ cd ../../../
$ ./scripts/start_standalone.sh
2021-06-21 12:08:06 +08:00
```
2021-10-26 14:31:03 +08:00
To run E2E tests, use these commands:
2021-06-21 12:08:06 +08:00
```shell
2021-09-17 10:25:50 +08:00
$ cd tests/python_client
$ pip install -r requirements.txt
$ pytest --tags=L0 -n auto
2021-06-21 12:08:06 +08:00
```
2021-10-01 08:55:21 +08:00
### Test on local branch
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
#### With Linux and MacOS
2023-06-06 14:06:36 +08:00
2021-10-05 21:10:22 +08:00
After preparing deployment environment, we can start the cluster on your host machine
2021-10-01 08:55:21 +08:00
```shell
$ ./scripts/start_cluster.sh
```
#### With docker
2023-06-06 14:06:36 +08:00
2021-10-01 08:55:21 +08:00
start the cluster on your host machine
2023-06-06 14:06:36 +08:00
2021-10-01 08:55:21 +08:00
```shell
$ ./build/builder.sh make install // build milvus
2023-10-24 09:30:10 +08:00
$ ./build/build_image.sh // build milvus latest docker image
2021-10-01 08:55:21 +08:00
$ docker images // check if milvus latest image is ready
REPOSITORY TAG IMAGE ID CREATED SIZE
milvusdb/milvus latest 63c62ff7c1b7 52 minutes ago 570MB
$ install with docker compose
```
2021-06-21 12:08:06 +08:00
## GitHub Flow
2021-09-28 09:52:04 +08:00
To check out code to work on, please refer to the [GitHub Flow ](https://guides.github.com/introduction/flow/ ).
2022-02-09 14:27:46 +08:00
## FAQs
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
Q: The go building phase fails on Apple Silicon (Mac M1) machines.
A: Please double-check that you have [right Go version ](https://go.dev/dl/ ) installed, i.e. with OS=macOS and Arch=ARM64.
---
2023-06-06 14:06:36 +08:00
Q: "make" fails with "_ld: library not found for -lSystem_" on MacOS.
2022-02-09 14:27:46 +08:00
A: There are a couple of things you could try:
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
1. Use **Software Update** (from **About this Mac** -> **Overview** ) to install updates.
2. Try the following commands:
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
```bash
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
```
---
2023-06-06 14:06:36 +08:00
Q: Rocksdb fails to compile with "_ld: warning: object file was built for newer macOS version (11.6) than being linked (11.0)._" on MacOS.
2022-02-09 14:27:46 +08:00
A: Use **Software Update** (from **About this Mac** -> **Overview** ) to install updates.
---
2023-06-06 14:06:36 +08:00
2022-02-09 14:27:46 +08:00
Q: Some Go unit tests failed.
2022-03-16 18:51:21 +08:00
A: We are aware that some tests can be flaky occasionally. If there's something you believe is abnormal (i.e. tests that fail every single time). You are more than welcome to [file an issue ](https://github.com/milvus-io/milvus/issues/new/choose )!