Skip to content

feat: release v1.3.0 with metric label filtering - #33

Merged
jarvis9443 merged 3 commits into
mainfrom
fix/metric-data-label-filter
Nov 30, 2026
Merged

jarvis9443 merged 3 commits into
mainfrom
fix/metric-data-label-filter

Conversation

@jarvis9443

@jarvis9443 jarvis9443 commented Nov 26, 2026 •

Copy link
Copy Markdown

Add an optional exact label filter to metric_data() and collect(). This lets callers expose the series for a current identity while retaining samples without the selected label.

The filter uses the existing label encoding and runs before sample and metadata rendering. It leaves the shared index and values intact, including series registered by other writers. It also applies to labels supplied for the error metric. Calls that omit the option retain their existing behavior.

Release the API as 1.3.0.

Summary by CodeRabbit

  • New Features
    • Added an optional exact label-and-value filter for metric data output. Matching samples are included, while samples without the selected label remain visible.
    • Filtering also applies to error metrics and supports string, number, and boolean values.
  • Documentation
    • Updated metric data guidance with filter behavior, accepted value types, and handling of invalid filters.
  • Release
    • Updated the package version to 1.3.0.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds an optional exact-label filter to metric_data(). It validates filter inputs and applies valid filters to metric keys. Unit and integration tests cover filtered output. The README, changelog, and package metadata are updated for version 1.3.0.

Changes: Metric Data Label Filtering

Layer / File(s) Summary
Filter implementation and coverage
prometheus.lua, prometheus_test.lua, integration/index.lua
metric_data() validates the optional filter and matches exact label names and values. Invalid filters are logged, and output remains unfiltered. Tests cover matching and excluded series, error metrics, and samples without the selected label.
Documentation and package version
README.md, CHANGELOG.md, dist.ini, rockspec/nginx-lua-prometheus-api7-1.3.0-1.rockspec
The README and changelog describe the filter. Package metadata and the rockspec identify version 1.3.0.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: knyar, nic-6443, alinsran

Merge Risk: Minimal · up to 5ff8d

This adds an optional label filter to metric output, and callers that don't use it see no change. No concrete merge-blocking risk was found in the reviewed changes.

Pre-merge checks: Passed 6

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the release version (1.3.0) and the metric label filtering feature. Both appear in the changeset: the CHANGELOG 1.3.0 entry, dist.ini and rockspec version bumps, and the new label_filt…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
E2e Test Quality Review Passed Summary: No blocking issue found. The PR has end-to-end coverage, and the open items are Major or Minor. Blocking checks: 1. E2E completeness: Pass. The PR adds label_filter to metric_data()/`coll…
Security Check Passed The Security Check does not apply to this change set. PR #33 (api7/nginx-lua-prometheus, base main, head fix/metric-data-label-filter, author jarvis9443) is a Lua Prometheus metrics library. It adds a…
Full details: Title check

Explanation

The title names the release version (1.3.0) and the metric label filtering feature. Both appear in the changeset: the CHANGELOG 1.3.0 entry, dist.ini and rockspec version bumps, and the new label_filter option in prometheus.lua for metric_data(). The title covers the main change, though it does not mention the error-metric handling or field-boundary matching.

Full details: E2e Test Quality Review

Explanation

Summary: No blocking issue found. The PR has end-to-end coverage, and the open items are Major or Minor. Blocking checks: 1. E2E completeness: Pass. The PR adds label_filter to metric_data()/collect(). integration/index.lua adds a writer-only gauge with instance_id and reads it through a second index_reader instance. integration/nginx.conf exposes this as /test_index in a real nginx with the shared dict index_metrics. integration/test.go calls http://localhost:18001/test_index and fails on a non-200 response, so the Lua assertions run in the Docker suite. The unit tests in prometheus_test.lua use a mocked dict, but the integration test covers the real writer-to-reader shared-dict path. 2. Error handling: Pass. compile_label_filter returns err, and metric_data checks it. The error is passed to log_error, which logs it and increments the error counter (prometheus.lua, Prometheus:log_error). It is not silently swallowed. Concern: an invalid filter fails open and returns unfiltered output. This matches the documented design, but a reviewer may want to confirm it for a filter meant to restrict exposure. 3. PR scope: Pass. The CHANGELOG, dist.ini, and rockspec changes are release metadata for the stated 1.3.0 release. No unrelated logic changed. 4. Concurrency: Pass. The filter path reads the dict and matches keys. It adds no new shared writes, locks, or state. Non-blocking findings: - Major, scenario coverage: No test covers invalid label_filter input. The cases are a missing name, an unsupported value type (table or nil), an invalid label name, and a nil value. No test checks that these log an error, increment nginx_metric_errors_total, and return unfiltered output. Numeric and boolean values are not tested. The integration test covers only one gauge and one value. It does not cover histograms, the error metric, or multiple writers. - Major, readability: testMetricDataLabelFilter builds expected_label from nested escapes ('instance_id="new\\"\\\\\\n"'). The test has no comment that explains the escaping. The scenario steps have no comments. - Minor: The integration assertions in index.lua have no failure messages, unlike the assert(..., "message") style used elsewhere in the file. - Minor: testMetricDataLabelFilter changes options.label_filter.value in place between assertions. This is local to one test and not a hidden cross-test dependency. Recommended follow-up: add invalid-filter tests that check the log and the error counter. Add a comment that explains the escaped label expectation.

Full details: Security Check

Explanation

The Security Check does not apply to this change set. PR #33 (api7/nginx-lua-prometheus, base main, head fix/metric-data-label-filter, author jarvis9443) is a Lua Prometheus metrics library. It adds an optional exact label filter to metric_data() and collect(). The changed files are CHANGELOG.md, README.md, dist.ini, integration/index.lua, prometheus.lua, prometheus_test.lua, and the renamed rockspec. Category review against the diff in prometheus.lua: 1. Sensitive data exposure: No credentials, tokens, headers, or plugin configs are handled. The new log_error(err) calls only pass fixed validation strings. The existing error log path is unchanged. 2. Unencrypted secrets in DB: No persistence code is touched. 3. Authorization bypass: No endpoints or permission checks are added or changed. 4. Cross-resource ownership: Not applicable to a metrics library. 5. TLS/crypto configuration: No TLS or crypto code is touched. 6. Shared resource isolation: The filter only skips dict:get for non-matching keys during output rendering. It does not mutate the shared key index or stored values, as the PR description states. 7. Secret reference resolution: No $env:// or $secret:// handling is involved. The filter narrows the exported output. It does not add exposure. Category findings: No issues found in categories 1–7.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: c52fb762-002a-418d-b1d0-25929d36955d
Commits

Reviewing files that changed from the base of the PR and between 861cd53 and 5ff8dcc.

Files selected for processing: 2

  • prometheus.lua
  • prometheus_test.lua

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

@membphis membphis left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This PR must not be merged until the metric filtering issue that silently drops valid samples is fixed.

This finding was reproduced on the revision associated with this review.

When filtering metrics by instance identity, another label's value can end with a comma followed by the instance-identity label name and an equals sign. The filter then misidentifies a label boundary and drops the entire sample. This was reproduced both for a sample without the instance-identity label and for a sample with a genuinely matching instance-identity label later in its label list. The documented API contract requires both samples to be retained.

Please correctly identify label boundaries and handle quoting and escaping according to the Prometheus text format. Label values containing double quotes, commas, and backslashes must be supported. Before merging, fix the filtering logic and add regression tests that verify the following behavior.

  • Samples without the target label are retained.
  • Samples whose target label value matches are retained, including when the target label appears after other labels.
  • Samples with the target label and a different value are excluded.

@jarvis9443

Copy link
Copy Markdown
Author

Addressed this review in 5ff8dcc. The matcher now walks label fields and skips escaped characters within quoted values. The regression covers preserving a sample without the target label, recognizing a matching label after misleading text in a preceding value, and excluding a nonmatching label.

@jarvis9443
jarvis9443 merged commit 361d67e into main Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants