Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Build error: redefinition of forceRegisterFilterFactory due to calling REGISTER_FACTORY twice with the same factory class.

Changes

  • Removed duplicate REGISTER_FACTORY(FilterFactory, Server::Configuration::UpstreamHttpFilterConfigFactory) call
  • Updated documentation to clarify that DualFactoryBase automatically registers the factory for both downstream and upstream contexts

DualFactoryBase inherits from both NamedHttpFilterConfigFactory and UpstreamHttpFilterConfigFactory, so a single registration with NamedHttpFilterConfigFactory is sufficient:

// Before (causes redefinition error)
REGISTER_FACTORY(FilterFactory, Server::Configuration::NamedHttpFilterConfigFactory);
REGISTER_FACTORY(FilterFactory, Server::Configuration::UpstreamHttpFilterConfigFactory);

// After (correct)
REGISTER_FACTORY(FilterFactory, Server::Configuration::NamedHttp

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> ## Background
> 
> This PR builds on the work from #1046 which adds per-route configuration support to the http-filter-cc example. Reviewer feedback from @ravenblackx in #1041 suggested adding upstream filter support to make this "a really good example."
> 
> ## What needs to be done
> 
> ### 1. Add upstream filter factory registration
> 
> The current implementation uses `DualFactoryBase` which supports both downstream and upstream filter chains, but the factory is only registered for downstream use. Add registration for the upstream filter factory to allow the filter to be used in upstream HTTP filter chains.
> 
> In `http-filter-cc/factory/factory.cc`, add:
> ```cpp
> REGISTER_FACTORY(FilterFactory, Server::Configuration::UpstreamHttpFilterConfigFactory);
> ```
> 
> This registers the same factory for upstream filter usage, enabling the filter to work in upstream HTTP filter chains as well as downstream.
> 
> ### 2. Update envoy.yaml to demonstrate upstream filter usage
> 
> Add an example of using the filter in an upstream HTTP filter chain in `http-filter-cc/envoy.yaml`. This could be added to the cluster configuration:
> 
> ```yaml
> clusters:
> - name: service_backend
>   # ... existing config ...
>   typed_extension_protocol_options:
>     envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
>       "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
>       upstream_http_protocol_options:
>         auto_sni: true
>       explicit_http_config:
>         http_protocol_options: {}
>       http_filters:
>       - name: sample
>         typed_config:
>           "@type": type.googleapis.com/sample.Decoder
>           key: "x-upstream-header"
>           val: "upstream-value"
>       - name: envoy.filters.http.upstream_codec
>         typed_config:
>           "@type": type.googleapis.com/envoy.extensions.filters.http.upstream_codec.v3.UpstreamCodec
> ```
> 
> ### 3. Improve documentation consistency with other examples
> 
> Update `http-filter-cc/example.rst` to follow the documentation pattern used in other examples. Looking at the structure of other examples, ensure:
> 
> - Step numbering is consistent with other examples (Step 1, Step 2, etc.)
> - The "See also" section follows the standard format
> - Add clear documentation about the upstream filter support
> - Include instructions on how to verify the upstream filter is working
> 
> ### 4. Update verify.sh to test upstream filter functionality
> 
> Update `http-filter-cc/verify.sh` to include tests for the upstream filter. Add a test case that verifies the upstream header is being added:
> 
> ```bash
> run_log "Test upstream filter header"
> responds_with \
>     '"x-upstream-header": "upstream-value"' \
>     "http://localhost:${PORT_PROXY}/"
> ```
> 
> ### 5. Ensure verify.sh is included in verify_examples.sh
> 
> Check that the http-filter-cc verify.sh is properly integrated with the main verification system. Looking at the CI workflow in `.github/workflows/_verify_filters.yml`, it seems to run verify.sh directly within the http-filter-cc directory. Ensure this is consistent with how other examples are verified and that it's properly included in the overall verification pipeline.
> 
> ## Acceptance Criteria
> 
> - [ ] Upstream filter factory is registered using `REGISTER_FACTORY(FilterFactory, Server::Configuration::UpstreamHttpFilterConfigFactory)`
> - [ ] envoy.yaml demonstrates upstream filter configuration  
> - [ ] example.rst documentation is updated to be consistent with other examples and documents upstream filter support
> - [ ] verify.sh includes tests for upstream filter functionality
> - [ ] verify.sh properly integrates with the example verification system
> 
> ## References
> 
> - Original PR with reviewer feedback: https://github.com/envoyproxy/examples/pull/1041
> - Current PR with per-route support: https://github.com/envoyproxy/examples/pull/1046
> - @ravenblackx's suggestion: "Maybe also register a factory for running the filter as an upstream filter"


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 2 commits February 3, 2026 22:58
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot AI changed the title [WIP] Add upstream filter factory registration for HTTP filter example Add upstream filter support to http-filter-cc example Feb 3, 2026
Copilot AI requested a review from phlax February 3, 2026 23:06
Copilot AI changed the title Add upstream filter support to http-filter-cc example Fix createRouteSpecificFilterConfigTyped return type for Envoy API change Feb 4, 2026
…tusOr

Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot AI and others added 2 commits February 4, 2026 08:18
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot AI changed the title Fix createRouteSpecificFilterConfigTyped return type for Envoy API change Remove duplicate REGISTER_FACTORY causing build failure Feb 4, 2026
@phlax phlax closed this Feb 4, 2026
Copilot stopped work on behalf of phlax due to an error February 4, 2026 08:30
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