mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 04:31:36 +08:00
Backend Plugins: Support handling of streaming resource response (#22580)
Use v0.19.0 of SDK. Support handling of streaming resource response. Disable gzip/compression middleware for resources to allow chunked/streaming response to clients the gzip middleware had to be disabled since it buffers the full response before sending it to the client. Closes #22569 Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:

committed by
GitHub

parent
f95c8b785c
commit
4ff613a432
@ -37,8 +37,8 @@ func (hs HealthStatus) String() string {
|
||||
|
||||
// CheckHealthResult check health result.
|
||||
type CheckHealthResult struct {
|
||||
Status HealthStatus
|
||||
Info string
|
||||
Status HealthStatus
|
||||
Message string
|
||||
}
|
||||
|
||||
func checkHealthResultFromProto(protoResp *pluginv2.CheckHealth_Response) *CheckHealthResult {
|
||||
@ -51,8 +51,8 @@ func checkHealthResultFromProto(protoResp *pluginv2.CheckHealth_Response) *Check
|
||||
}
|
||||
|
||||
return &CheckHealthResult{
|
||||
Status: status,
|
||||
Info: protoResp.Info,
|
||||
Status: status,
|
||||
Message: protoResp.Message,
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,3 +91,46 @@ type CallResourceResult struct {
|
||||
Headers map[string][]string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
type callResourceResultStream interface {
|
||||
Recv() (*CallResourceResult, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
type callResourceResultStreamImpl struct {
|
||||
stream pluginv2.Core_CallResourceClient
|
||||
}
|
||||
|
||||
func (s *callResourceResultStreamImpl) Recv() (*CallResourceResult, error) {
|
||||
protoResp, err := s.stream.Recv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
respHeaders := map[string][]string{}
|
||||
for key, values := range protoResp.Headers {
|
||||
respHeaders[key] = values.Values
|
||||
}
|
||||
|
||||
return &CallResourceResult{
|
||||
Headers: respHeaders,
|
||||
Body: protoResp.Body,
|
||||
Status: int(protoResp.Code),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *callResourceResultStreamImpl) Close() error {
|
||||
return s.stream.CloseSend()
|
||||
}
|
||||
|
||||
type singleCallResourceResult struct {
|
||||
result *CallResourceResult
|
||||
}
|
||||
|
||||
func (s *singleCallResourceResult) Recv() (*CallResourceResult, error) {
|
||||
return s.result, nil
|
||||
}
|
||||
|
||||
func (s *singleCallResourceResult) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user