Skip to content

REST datasource handler needs configurable timeout, auth, and fallback support #6275

@theycallmeaabie

Description

@theycallmeaabie

Please describe the enhancement

The REST datasource handler (internal/datasources/rest/handler.go) has several hardcoded values and unimplemented stubs that make it hard to use with real-world APIs:

  • Timeout is hardcoded to 5s (line 160-161) : there's a TODO acknowledging this. Slower upstream APIs will just time out with no way to adjust.
  • Auth is unimplemented (line 62): if your datasource points at an API that isn't the registered provider, there's no way to pass API keys or bearer tokens.
  • Fallback is a no-op (lines 61, 228): the struct references it and doRequest() has a placeholder, but nothing actually happens when a request fails.
  • 1MB response limit is hardcoded (line 40): MaxBytesLimit = 1 << 20 with no override. Some APIs legitimately return more.
  • No custom HTTP client support** (line 158): another existing TODO.

These are all flagged with TODO comments in the code already.

Solution Proposal

I think the cleanest approach would be adding a few optional fields to RestDataSource_Def in the proto definition something like a timeout duration, a max_response_bytes int, and an auth block that supports at least API keys and bearer tokens.

The current defaults (5s timeout, 1MB limit) are reasonable and should stay as-is for existing datasources. The new fields would just let people override them when needed.

For fallback, even something simple like "try an alternate endpoint" or "return a structured error instead of nothing" would go a long way.

Describe alternatives you've considered

You could handle some of this at the provider level instead of per-datasource, but that falls apart when a datasource calls a third-party API that has nothing to do with the registered provider. Putting the config on the datasource definition itself gives the most flexibility without overcomplicating things.

Additional context

For reference, here are the exact lines in internal/datasources/rest/handler.go:

  • Line 40: MaxBytesLimit int64 = 1 << 20
  • Line 61: // TODO implement fallback
  • Line 62: // TODO implement auth
  • Line 158: // TODO: Add option to use custom client
  • Line 160: // TODO: Make timeout configurable
  • Line 228: // TODO: Handle fallback here.

Acceptance Criteria

  • Datasource authors can set a custom timeout in their datasource definition
  • There's a way to configure auth for datasources (API key or bearer token at minimum)
  • The 1MB response limit can be overridden per datasource
  • Fallback in doRequest() actually does something, even a structured error is better than silently returning nothing
  • Existing datasources that don't set any of the new fields keep working exactly as they do today
  • New config paths have unit tests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions