Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh EndpointConfig request headers #12904

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/12904.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refresh headers used in requests (e.g. action server requests) made by `EndpointConfig` using its `headers` attribute.
10 changes: 5 additions & 5 deletions rasa/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import pluggy

from rasa.cli import SubParsersAction
from rasa.engine.storage.storage import ModelMetadata
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.nlu.training_data.message import Message

if TYPE_CHECKING:
from rasa.core.brokers.broker import EventBroker
from rasa.core.tracker_store import TrackerStore
from rasa.engine.graph import SchemaNode
from rasa.engine.storage.storage import ModelMetadata
from rasa.shared.core.domain import Domain
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.nlu.training_data.message import Message
from rasa.utils.endpoints import EndpointConfig


Expand Down Expand Up @@ -95,8 +95,8 @@ def init_telemetry(endpoints_file: Optional[Text]) -> None:

@hookspec # type: ignore[misc]
def mock_tracker_for_evaluation(
example: Message, model_metadata: Optional[ModelMetadata]
) -> Optional[DialogueStateTracker]:
example: "Message", model_metadata: Optional["ModelMetadata"]
) -> Optional["DialogueStateTracker"]:
"""Generate a mocked tracker for NLU evaluation."""


Expand Down
3 changes: 3 additions & 0 deletions rasa/utils/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ async def request(
headers.update(kwargs["headers"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the changes done to the headers here be "undone" by your changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a possibility that the similar keys get overwritten here. Do you have any ideas what can be done to minimise this risk, perhaps only add the tracing related header key?

Copy link
Member Author

Choose a reason for hiding this comment

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

It depends what could be in the self.headers, in the tracing scenarios it only contains the traceparent key-value pair. I've had a look at where this EndpointConfig.request() method is used in the codebase, and only in the rasa interactive code it is used in two places with headers keyword argument with value {"Accept": "application/json"} , let me know if you're interested and I can share the links.

Copy link
Member Author

Choose a reason for hiding this comment

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

only add the tracing related header key

yep sure, we can restrict to this only, however I think the risk is low for overwriting keys based on the code usage I could find of headers keyword argument (see reply above). Let me know before making the commit if I should go ahead?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you've looked into it already then it's cool. I'm good with it

del kwargs["headers"]

if self.headers:
headers.update(self.headers)

url = concat_url(self.url, subpath)

sslcontext = None
Expand Down