選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CONTRIBUTING.md 6.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Contributing
  2. Prometheus uses GitHub to manage reviews of pull requests.
  3. * If you are a new contributor see: [Steps to Contribute](#steps-to-contribute)
  4. * If you have a trivial fix or improvement, go ahead and create a pull request,
  5. addressing (with `@...`) a suitable maintainer of this repository (see
  6. [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request.
  7. * If you plan to do something more involved, first discuss your ideas
  8. on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers).
  9. This will avoid unnecessary work and surely give you and us a good deal
  10. of inspiration. Also please see our [non-goals issue](https://github.com/prometheus/docs/issues/149) on areas that the Prometheus community doesn't plan to work on.
  11. * Relevant coding style guidelines are the [Go Code Review
  12. Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments)
  13. and the _Formatting and style_ section of Peter Bourgon's [Go: Best
  14. Practices for Production
  15. Environments](https://peter.bourgon.org/go-in-production/#formatting-and-style).
  16. * Be sure to sign off on the [DCO](https://github.com/probot/dco#how-it-works)
  17. ## Steps to Contribute
  18. Should you wish to work on an issue, please claim it first by commenting on the GitHub issue that you want to work on it. This is to prevent duplicated efforts from contributors on the same issue.
  19. Please check the [`help-wanted`](https://github.com/prometheus/procfs/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) label to find issues that are good for getting started. If you have questions about one of the issues, with or without the tag, please comment on them and one of the maintainers will clarify it. For a quicker response, contact us over [IRC](https://prometheus.io/community).
  20. For quickly compiling and testing your changes do:
  21. ```
  22. make test # Make sure all the tests pass before you commit and push :)
  23. ```
  24. We use [`golangci-lint`](https://github.com/golangci/golangci-lint) for linting the code. If it reports an issue and you think that the warning needs to be disregarded or is a false-positive, you can add a special comment `//nolint:linter1[,linter2,...]` before the offending line. Use this sparingly though, fixing the code to comply with the linter's recommendation is in general the preferred course of action.
  25. ## Pull Request Checklist
  26. * Branch from the master branch and, if needed, rebase to the current master branch before submitting your pull request. If it doesn't merge cleanly with master you may be asked to rebase your changes.
  27. * Commits should be as small as possible, while ensuring that each commit is correct independently (i.e., each commit should compile and pass tests).
  28. * If your patch is not getting reviewed or you need a specific person to review it, you can @-reply a reviewer asking for a review in the pull request or a comment, or you can ask for a review on IRC channel [#prometheus](https://webchat.freenode.net/?channels=#prometheus) on irc.freenode.net (for the easiest start, [join via Riot](https://riot.im/app/#/room/#prometheus:matrix.org)).
  29. * Add tests relevant to the fixed bug or new feature.
  30. ## Dependency management
  31. The Prometheus project uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) to manage dependencies on external packages. This requires a working Go environment with version 1.12 or greater installed.
  32. All dependencies are vendored in the `vendor/` directory.
  33. To add or update a new dependency, use the `go get` command:
  34. ```bash
  35. # Pick the latest tagged release.
  36. go get example.com/some/module/pkg
  37. # Pick a specific version.
  38. go get example.com/some/module/pkg@vX.Y.Z
  39. ```
  40. Tidy up the `go.mod` and `go.sum` files and copy the new/updated dependency to the `vendor/` directory:
  41. ```bash
  42. # The GO111MODULE variable can be omitted when the code isn't located in GOPATH.
  43. GO111MODULE=on go mod tidy
  44. GO111MODULE=on go mod vendor
  45. ```
  46. You have to commit the changes to `go.mod`, `go.sum` and the `vendor/` directory before submitting the pull request.
  47. ## API Implementation Guidelines
  48. ### Naming and Documentation
  49. Public functions and structs should normally be named according to the file(s) being read and parsed. For example,
  50. the `fs.BuddyInfo()` function reads the file `/proc/buddyinfo`. In addition, the godoc for each public function
  51. should contain the path to the file(s) being read and a URL of the linux kernel documentation describing the file(s).
  52. ### Reading vs. Parsing
  53. Most functionality in this library consists of reading files and then parsing the text into structured data. In most
  54. cases reading and parsing should be separated into different functions/methods with a public `fs.Thing()` method and
  55. a private `parseThing(r Reader)` function. This provides a logical separation and allows parsing to be tested
  56. directly without the need to read from the filesystem. Using a `Reader` argument is preferred over other data types
  57. such as `string` or `*File` because it provides the most flexibility regarding the data source. When a set of files
  58. in a directory needs to be parsed, then a `path` string parameter to the parse function can be used instead.
  59. ### /proc and /sys filesystem I/O
  60. The `proc` and `sys` filesystems are pseudo file systems and work a bit differently from standard disk I/O.
  61. Many of the files are changing continuously and the data being read can in some cases change between subsequent
  62. reads in the same file. Also, most of the files are relatively small (less than a few KBs), and system calls
  63. to the `stat` function will often return the wrong size. Therefore, for most files it's recommended to read the
  64. full file in a single operation using an internal utility function called `util.ReadFileNoStat`.
  65. This function is similar to `os.ReadFile`, but it avoids the system call to `stat` to get the current size of
  66. the file.
  67. Note that parsing the file's contents can still be performed one line at a time. This is done by first reading
  68. the full file, and then using a scanner on the `[]byte` or `string` containing the data.
  69. ```
  70. data, err := util.ReadFileNoStat("/proc/cpuinfo")
  71. if err != nil {
  72. return err
  73. }
  74. reader := bytes.NewReader(data)
  75. scanner := bufio.NewScanner(reader)
  76. ```
  77. The `/sys` filesystem contains many very small files which contain only a single numeric or text value. These files
  78. can be read using an internal function called `util.SysReadFile` which is similar to `os.ReadFile` but does
  79. not bother to check the size of the file before reading.
  80. ```
  81. data, err := util.SysReadFile("/sys/class/power_supply/BAT0/capacity")
  82. ```