Thank you for your interest in contributing! This document provides guidelines and instructions for contributing to the project.
Be respectful, constructive, and professional in all interactions.
- OpenResty or NGINX with Lua support
- Lua 5.1+ or LuaJIT
- Docker (for testing)
- Git
- Fork the repository
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/lua-resty-ngxstats.git
cd lua-resty-ngxstats- Install development dependencies:
luarocks install luacheck
luarocks install busted- Build and run:
make build
make run_devgit checkout -b feature/your-feature-nameUse prefixes: feature/, fix/, docs/, test/, refactor/
Follow the coding standards (see below).
# Lint your code
make lint
# Run unit tests
make test
# Build Docker image
make buildAll checks must pass before submitting a PR.
Follow conventional commit format:
<type>: <description>
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Adding or updating testsrefactor: Code refactoringchore: Maintenance tasksci: CI/CD changes
Example:
git commit -m "feat: add SSL/TLS metrics tracking
Track ssl_protocol and ssl_cipher for HTTPS connections.
Adds new Prometheus metrics for SSL session analysis.
Closes #123"git push origin feature/your-feature-nameCreate a pull request on GitHub with:
- Clear description of changes
- Reference to related issues
- Screenshots/examples if applicable
- Indentation: 4 spaces (no tabs)
- Line length: Max 100 characters
- Variables: Use
localfor all variables - Naming:
- Functions:
snake_case - Variables:
snake_case - Constants:
UPPER_CASE - Modules:
_Mpattern
- Functions:
All modules should follow this pattern:
--[[
Module description
]]--
local _M = {}
-- Private function
local function helper()
-- implementation
end
--[[
Public function documentation
@param arg1 - Description
@return result - Description
]]--
function _M.public_function(arg1)
-- implementation
end
return _M- Always validate input parameters
- Use
common.errlog()for error logging - Return
nil, error_messageon failures - Check return values from all ngx.shared operations
Example:
function _M.increment(stats, key, value)
if not key or key == "" then
return nil, "key cannot be empty"
end
local newval, err = stats:incr(key, value)
if not newval then
common.errlog("Failed to increment ", key, ": ", err)
return nil, err
end
return newval
end- Add file-level comments explaining module purpose
- Document all public functions with parameters and return values
- Include usage examples for complex functions
- Update README.md for new features
Tests use the busted framework. Create test files in spec/:
describe("my_module", function()
local my_module
before_each(function()
package.loaded['stats.my_module'] = nil
my_module = require "stats.my_module"
end)
describe("my_function()", function()
it("should handle valid input", function()
local result = my_module.my_function("test")
assert.equals("expected", result)
end)
it("should handle invalid input", function()
local result, err = my_module.my_function(nil)
assert.is_nil(result)
assert.is_not_nil(err)
end)
end)
end)- Aim for >80% coverage on new code
- Test edge cases and error conditions
- Use mocks from
spec/helpers.lua
- Update
lib/resty/ngxstats/log.luato collect the metric - Update
lib/resty/ngxstats/prometheus.luato format it - Add metadata to
metric_infotable in prometheus.lua - Write tests in
spec/prometheus_spec.lua - Update README.md metrics table
- Add example output to README.md
Example:
-- In log.lua
local ssl_protocol = ngx.var.ssl_protocol
if ssl_protocol then
common.incr_or_create(stats,
common.key({'server_zones', group, 'ssl', ssl_protocol}), 1)
end
-- In prometheus.lua metric_info
["server_zone_ssl_total"] = {
help = "Total requests per SSL/TLS protocol version",
type = "counter"
}
-- In prometheus.lua parse_metric()
elseif parts[3] == "ssl" then
metric.name = "nginx_server_zone_ssl_total"
metric.labels.protocol = parts[4]
metric.value = value
end- Update documentation - README, CHANGELOG, code comments
- Add tests - For new features or bug fixes
- Run all checks -
make lint && make test && make build - Update CHANGELOG.md - Add entry under "Unreleased"
- Create PR with clear description
- Respond to feedback - Address review comments promptly
- Squash commits if requested before merge
- Code follows style guidelines
- Tests added/updated and passing
- Documentation updated
- CHANGELOG.md updated
- Commit messages follow convention
- No merge conflicts
(For maintainers)
- Update version in
dist.ini - Update CHANGELOG.md (move Unreleased to version)
- Create git tag:
git tag -a v1.0.0 -m "Release 1.0.0" - Push tag:
git push origin v1.0.0 - GitHub Actions will build and publish
- Issues: Open an issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Security: Email security issues privately (see SECURITY.md)
By contributing, you agree that your contributions will be licensed under the MIT License.