Skip to content

Proposal: ProcessContext #6969

@ahedberg

Description

@ahedberg

Title: Allow users to pass data to filters via e.g. ProcessContext

Description:
This is a hand-wavy feature request. Design ideas welcome.

We run Envoys in a binary with other serving threads. We'd like some of our filters to behave differently based on the lameduck status of those other serving threads. However, there's not a great way currently to get state from those threads/servers to the filters, short of a global variable.

This hypothetical ProcessContext could provide an API for information to flow from those other servers/serving threads to the filter factories. Envoy would be given a ProcessContext at startup, and would hand it to factories as needed.

A really naive implementation (note: my former Abseil colleagues might disown me if we actually implemented this version):

class ProcessContext {
 public:
  ProcessContext(void* process_data) : process_data_(process_data) {}
  void* get() { return process_data_; }

 private:
  void* process_data_;
};

// In e.g. a filter factory:
Envoy::Http::FilterFactoryCb MyFilter::createFilter(
    const std::string& stat_prefix,
    Envoy::Server::Configuration::FactoryContext& context,
    ProcessContext& process_context) {
  MyServerData* server_data = reinterpret_cast<MyServerData*>(process_context.get());
  return [&server_data](Envoy::Http::FilterChainFactoryCallbacks& callbacks) {
    callbacks.addStreamDecoderFilter(std::make_shared<MyFilter>(server_data));
  };
}

// Now MyFilter has a pointer to MyServerData

Thoughts?

cc @mergeconflict @htuch

Metadata

Metadata

Assignees

No one assigned

    Labels

    design proposalNeeds design doc/proposal before implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions