CONTRIBUTING.md 10.9 KB
Newer Older
Z
zhenshan.cao 已提交
1 2 3 4 5 6 7 8
# Contributing to Milvus

Contributions to Milvus are welcome from everyone. We strive to make the contribution process simple and straightforward. Up-to-date information can be found at [milvus.io](https://milvus.io/).

The following are a set of guidelines for contributing to Milvus. Following these guidelines makes contributing to this project easy and transparent. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

As for everything else in the project, the contributions to Milvus are governed by our [Code of Conduct](CODE_OF_CONDUCT.md).

9 10
**Content**

11
- [Contributing to Milvus](#contributing-to-milvus)
12 13
  - [What contributions can you make?](#what-contributions-can-you-make)
  - [How can you contribute?](#how-can-you-contribute)
14 15 16
    - [Contributing code](#contributing-code)
    - [GitHub workflow](#github-workflow)
    - [General guidelines](#general-guidelines)
17 18 19 20 21
    - [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco)
  - [Coding Style](#coding-style)
    - [Golang coding style](#golang-coding-style)
    - [C++ coding style](#c-coding-style)
  - [Run unit test with code coverage](#run-unit-test-with-code-coverage)
22 23
    - [Golang](#run-golang-unit-tests)
    - [C++](#run-c-unit-tests)
24
  - [Commits and PRs](#commits-and-prs)
25

26
## What contributions can you make?
Z
zhenshan.cao 已提交
27

28 29 30
| Suitable for                             | Projects                                                                                                                                                                            | Resources                                                                                           |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| Go developers                            | [milvus](https://github.com/milvus-io/milvus), [milvus-sdk-go](https://github.com/milvus-io/milvus-sdk-go)                                                                          |                                                                                                     |
31
| CPP developers                           | [milvus](https://github.com/milvus-io/milvus), [knowhere](https://github.com/milvus-io/knowhere)                                                                                    |                                                                                                     |
32 33 34 35
| Developers interested in other languages | [pymilvus](https://github.com/milvus-io/pymilvus), [milvus-sdk-node](https://github.com/milvus-io/milvus-sdk-node), [milvus-sdk-java](https://github.com/milvus-io/milvus-sdk-java) | [Contributing to PyMilvus](https://github.com/milvus-io/pymilvus/blob/master/CONTRIBUTING.md)       |
| Kubernetes enthusiasts                   | [milvus-helm](https://github.com/milvus-io/milvus-helm)                                                                                                                             |                                                                                                     |
| Tech writers and docs enthusiasts        | [milvus-docs](https://github.com/milvus-io/milvus-docs)                                                                                                                             | [Contributing to milvus docs](https://github.com/milvus-io/milvus-docs/blob/v2.0.0/CONTRIBUTING.md) |
| Web developers                           | [milvus-insight](https://github.com/zilliztech/milvus-insight)                                                                                                                      |                                                                                                     |
36

37
## How can you contribute?
38

Z
zhenshan.cao 已提交
39 40
### Contributing code

41
**If you encounter a bug, you can**
42

43
- (**Recommended**) File an issue about the bug.
44 45 46
- Provide clear and concrete ways/scripts to reproduce the bug.
- Provide possible solutions for the bug.
- Pull a request to fix the bug.
47 48

**If you're interested in existing issues, you can**
49

50 51
- (**Recommended**) Provide answers for issue labeled `question`.
- Provide help for issues labeled `bug`, `improvement`, and `enhancement` by
S
shiyu22 已提交
52
  - (**Recommended**) Ask questions, reproduce the issue, or provide solutions.
53
  - Pull a request to fix the issue.
54

55
**If you require a new feature or major enhancement, you can**
56

57
- (**Recommended**) File an issue about the feature/enhancement with reasons.
S
shiyu22 已提交
58
- Provide an MEP for the feature/enhancement.
59
- Pull a request to implement the MEP.
60 61

**If you are a reviewer/approver of Milvus, you can**
62

63 64 65
- Participate in [PR review](CODE_REVIEW.md) process.
- Instruct newcomers in the community to complete the PR process.

66
If you want to become a contributor of Milvus, submit your pull requests! For those just getting started, see [GitHub workflow](#github-workflow) below.
67 68 69

All submissions will be reviewed as quickly as possible.
There will be a reviewer to review the codes, and an approver to review everything aside the codes, see [code review](CODE_REVIEW.md) for details.
70
If everything is perfect, the reviewer will label `/lgtm`, and the approver will label `/approve`.
S
shiyu22 已提交
71
Once the 2 labels are on your PR, and all actions pass, your PR will be merged into base branch automatically by our @sre-ci-robot
Z
zhenshan.cao 已提交
72 73 74 75 76 77 78 79

### GitHub workflow

Generally, we follow the "fork-and-pull" Git workflow.

1.  [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the repository on GitHub.
2.  Clone your fork to your local machine with `git clone git@github.com:<yourname>/milvus.git`.
3.  Create a branch with `git checkout -b my-topic-branch`.
S
shiyu22 已提交
80
4.  [Commit](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/committing-changes-to-a-pull-request-branch-created-from-a-fork) changes to your own branch, then push to GitHub with `git push origin my-topic-branch`.
Z
zhenshan.cao 已提交
81 82
5.  Submit a [pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) so that we can review your changes.

83 84
![](docs/developer_guides/figs/fork-and-pull.png)

85
Remember to [sync your forked repository](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#keep-your-fork-synced) _before_ submitting proposed changes upstream. If you have an existing local repository, please update it before you start, to minimize the chance of merge conflicts.
Z
zhenshan.cao 已提交
86 87 88

```shell
git remote add upstream git@github.com:milvus-io/milvus.git
89 90
git fetch upstream
git checkout upstream/master -b my-topic-branch
Z
zhenshan.cao 已提交
91 92
```

93 94
![](docs/developer_guides/figs/local-develop-steps.png)

Z
zhenshan.cao 已提交
95 96 97 98
### General guidelines

Before submitting your pull requests for review, make sure that your changes are consistent with the [coding style](CONTRIBUTING.md#coding-style), and run [unit tests](CONTRIBUTING.md#run-unit-test-with-code-coverage) to check your code coverage rate.

99 100 101 102
- Include unit tests when you contribute new features, as they help to prove that your code works correctly, and also guard against future breaking changes to lower the maintenance cost.
- Bug fixes also require unit tests, because the presence of bugs usually indicates insufficient test coverage.
- Keep API compatibility in mind when you change code in Milvus. Reviewers of your pull request will comment on any API compatibility issues.
- When you contribute a new feature to Milvus, the maintenance burden is (by default) transferred to the Milvus team. This means that the benefit of the contribution must be compared against the cost of maintaining the feature.
Z
zhenshan.cao 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

### Developer Certificate of Origin (DCO)

All contributions to this project must be accompanied by acknowledgment of, and agreement to, the [Developer Certificate of Origin](https://developercertificate.org/). Acknowledgment of and agreement to the Developer Certificate of Origin _must_ be included in the comment section of each contribution and _must_ take the form of `Signed-off-by: {{Full Name}} <{{email address}}>` (without the `{}`). Contributions without this acknowledgment will be required to add it before being accepted. If contributors are unable or unwilling to agree to the Developer Certificate of Origin, their contribution will not be included.

Contributors sign-off that they adhere to DCO by adding the following Signed-off-by line to commit messages:

```text
This is my commit message

Signed-off-by: Random J Developer <random@developer.example.org>
```

Git also has a `-s` command line option to append this automatically to your commit message:

```shell
$ git commit -s -m 'This is my commit message'
```

## Coding Style
123

124 125
Keeping a consistent style for code, code comments, commit messages, and PR descriptions will greatly accelerate your PR review process.
We highly recommend you refer to and comply to the following style guides when you put together your pull requests:
126

127
### Golang coding style
128

129 130
- Coding style: refer to the [Effictive Go Style Guide](https://golang.org/doc/effective_go)

S
shiyu22 已提交
131
We also use `golangci-lint` to perform code check. Run the following command before submitting your pull request and make sure there is no issue reported:
132

133 134 135 136
```shell
$ make static-check
```

137
To format code
138

139 140 141 142 143
```shell
$ make fmt
```

### C++ coding style
144

145
The C++ coding style used in Milvus generally follows [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
146
We made the following changes based on the guide:
Z
zhenshan.cao 已提交
147

148 149 150 151
- 4 spaces for indentation
- Adopt .cpp file extension instead of .cc extension
- 120-character line length
- Camel-Cased file names
Z
zhenshan.cao 已提交
152 153

Install clang-format
154

Z
zhenshan.cao 已提交
155 156 157
```shell
$ sudo apt-get install clang-format
```
158

Z
zhenshan.cao 已提交
159
Check code style
160

Z
zhenshan.cao 已提交
161
```shell
G
groot 已提交
162
$ make cppcheck
Z
zhenshan.cao 已提交
163 164 165
```

## Run unit test with code coverage
166

Z
zhenshan.cao 已提交
167 168
Before submitting your Pull Request, make sure you have run unit test, and your code coverage rate is >= 90%.

169
### Run golang unit tests
170 171

You can run all the Golang unit tests using make.
172

173
```shell
174
$ make test-go
175
```
176 177 178 179 180 181 182 183 184 185 186

You can also run unit tests in package level.

```shell
# run unit tests in datanode package
$ go test ./internal/datanode -cover
ok  	github.com/milvus-io/milvus/internal/datanode 3.874s	coverage: 88.2% of statements
```

You can run a sub unit test.

S
shiyu22 已提交
187
In this case, we are only concerned about the tests with name "SegmentReplica" and
188
sub tests with name "segmentFlushed". When running sub tests, the coverage is not concerned.
189

190
```shell
W
wayblink 已提交
191
$ go test ./internal/datanode -run SegmentReplica/segmentFlushed
192 193 194
ok  	github.com/milvus-io/milvus/internal/datanode 0.019s
```

195
### Run C++ unit tests
196

Z
zhenshan.cao 已提交
197
Install lcov
198

Z
zhenshan.cao 已提交
199 200 201
```shell
$ sudo apt-get install lcov
```
202

Z
zhenshan.cao 已提交
203
Run unit test and generate code for code coverage check
204

205
```shell
G
groot 已提交
206
$ make codecov-cpp
Z
zhenshan.cao 已提交
207
```
208 209

## Commits and PRs
210

211
- Commit message and PR description style: refer to [good commit messages](https://chris.beams.io/posts/git-commit)