Documentation ¶
Overview ¶
package service provides functions and methods for creating and running the api of the proxy service
Index ¶
- Constants
- func Call(client ProxyServiceClient, request *http.Request, result interface{}) error
- func CreateRequest(method string, path string, params interface{}) (*http.Request, error)
- func MarshalJSONResponse(obj interface{}, w http.ResponseWriter) error
- func NewError(message, url string, statusCode int) error
- type DatabaseStatusResponse
- type HostProxies
- type Proxies
- type ProxyMetadata
- type ProxyService
- type ProxyServiceClient
- type ProxyServiceClientConfig
- type PruningOrDefaultProxies
- type RequestError
- type RequestInterceptor
- type ShardProxies
Constants ¶
const ( DefaultAnonymousUserAgent = "anon" // Service defined context keys DecodedRequestContextKey = "X-KAVA-PROXY-DECODED-REQUEST-BODY" DecodedBatchRequestContextKey = "X-KAVA-PROXY-DECODED-BATCH-REQUEST-BODY" OriginRoundtripLatencyMillisecondsKey = "X-KAVA-PROXY-ORIGIN-ROUNDTRIP-LATENCY-MILLISECONDS" RequestStartTimeContextKey = "X-KAVA-PROXY-REQUEST-START-TIME" RequestHostnameContextKey = "X-KAVA-PROXY-REQUEST-HOSTNAME" RequestIPContextKey = "X-KAVA-PROXY-REQUEST-IP" RequestUserAgentContextKey = "X-KAVA-PROXY-USER-AGENT" RequestRefererContextKey = "X-KAVA-PROXY-REFERER" RequestOriginContextKey = "X-KAVA-PROXY-ORIGIN" ProxyMetadataContextKey = "X-KAVA-PROXY-RESPONSE-BACKEND" // Values defined by upstream services LoadBalancerForwardedForHeaderKey = "X-Forwarded-For" UserAgentHeaderkey = "User-Agent" RefererHeaderKey = "Referer" OriginHeaderKey = "Origin" )
const ( ResponseBackendDefault = "DEFAULT" ResponseBackendPruning = "PRUNING" ResponseBackendShard = "SHARD" )
ResponseBackend values for metric reporting of where request was routed
const (
DatabaseStatusPath = "/status/database"
)
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(client ProxyServiceClient, request *http.Request, result interface{}) error
Call makes an http request to a JSON HTTP api decoding the JSON response to the result interface if non-nil returning error (if any)
func CreateRequest ¶
CreateRequest isolates duplicate code in creating http search request.
func MarshalJSONResponse ¶
func MarshalJSONResponse(obj interface{}, w http.ResponseWriter) error
MarshalJSONResponse marshals an interface into the response body and sets JSON content type headers
Types ¶
type DatabaseStatusResponse ¶
type DatabaseStatusResponse struct { LatestProxiedRequestMetricPartitionTableName string `json:"latest_proxied_request_metric_partition_table_name"` // name of the latest created and currently attached partition for the proxied_request_metrics table TotalProxiedRequestMetricPartitions int64 `json:"total_proxied_request_metric_partitions"` // total number of attached partitions for the proxied_request_metrics table }
DatabaseStatusResponse wraps values returned by calls to /status/database
type HostProxies ¶
type HostProxies struct {
// contains filtered or unexported fields
}
HostProxies chooses a proxy based solely on the Host of the incoming request, and the host -> backend url map defined in the config. HostProxies name is the response backend provided for all requests
func (HostProxies) ProxyForRequest ¶
func (hbp HostProxies) ProxyForRequest(r *http.Request) (*httputil.ReverseProxy, ProxyMetadata, bool)
ProxyForRequest implements Proxies. It determines the proxy based solely on the request Host.
type Proxies ¶
type Proxies interface {
ProxyForRequest(r *http.Request) (proxy *httputil.ReverseProxy, metadata ProxyMetadata, found bool)
}
Proxies is an interface for getting a reverse proxy for a given request. proxy is the reverse proxy to use for the request
func NewProxies ¶
func NewProxies(config config.Config, serviceLogger *logging.ServiceLogger) Proxies
NewProxies creates a Proxies instance based on the service configuration: - for non-sharding configuration, it returns a HostProxies - for height-based-routing configurations, it returns a PruningOrDefaultProxies
type ProxyMetadata ¶
type ProxyMetadata struct { // name of the backend used BackendName string // url of the backend used BackendRoute url.URL // height interval endpoint of shard. // only defined if BackendName is "SHARD" ShardEndHeight uint64 }
ProxyMetadata wraps details about the proxy used for a request. It is useful for gathering details about the proxied request to include in metrics.
type ProxyService ¶
type ProxyService struct { Database *database.PostgresClient Cache *cachemdw.ServiceCache *logging.ServiceLogger // contains filtered or unexported fields }
ProxyService represents an instance of the proxy service API
func New ¶
func New(ctx context.Context, config config.Config, serviceLogger *logging.ServiceLogger) (ProxyService, error)
New returns a new ProxyService with the specified config and error (if any)
func (*ProxyService) Run ¶
func (p *ProxyService) Run() error
Run runs the proxy service, returning error (if any) in the event the proxy service stops
type ProxyServiceClient ¶
type ProxyServiceClient struct { *http.Client DebugLogResponses bool // contains filtered or unexported fields }
ProxyServiceClient provides a client for making requests and decoding responses to the proxy service API
func NewProxyServiceClient ¶
func NewProxyServiceClient(config ProxyServiceClientConfig) (*ProxyServiceClient, error)
NewProxyServiceClient creates a new ProxyServiceClient using the provided config, returning the client and error (if any)
func (*ProxyServiceClient) GetDatabaseStatus ¶
func (c *ProxyServiceClient) GetDatabaseStatus(ctx context.Context) (DatabaseStatusResponse, error)
GetDatabaseStatus calls `DatabaseStatusPath` to get metadata related to proxy service database operations such as proxied request metrics compaction and partitioning
type ProxyServiceClientConfig ¶
ProxyServiceClientConfig wraps values used to create a new ProxyServiceClient
type PruningOrDefaultProxies ¶
type PruningOrDefaultProxies struct { *logging.ServiceLogger // contains filtered or unexported fields }
PruningOrDefaultProxies routes traffic based on the host _and_ the height of the query. If the height is "latest" (or equivalent), return Pruning node proxy host. Otherwise return default node proxy host.
func (PruningOrDefaultProxies) ProxyForRequest ¶
func (hsp PruningOrDefaultProxies) ProxyForRequest(r *http.Request) (*httputil.ReverseProxy, ProxyMetadata, bool)
ProxyForRequest implements Proxies. Decodes height of request - routes to Pruning proxy if defined & height is "latest" - otherwise routes to Default proxy
type RequestError ¶
RequestError provides additional details about the failed request.
func (*RequestError) Error ¶
func (err *RequestError) Error() string
Error implements the error interface for RequestError.
type RequestInterceptor ¶
RequestInterceptors (a.k.a. 🦖🦖) are functions run by the proxy service to modify the original request sent by the caller or the response returned by the backend
type ShardProxies ¶
type ShardProxies struct { *logging.ServiceLogger // contains filtered or unexported fields }
ShardProxies handles routing requests for specific heights to backends that contain the height. The height is parsed out of requests that would route to the default backend of the underlying `defaultProxies` If the height is contained by a backend in the host's IntervalURLMap, it is routed to that url. Otherwise, it forwards the request via the wrapped defaultProxies.
func (ShardProxies) ProxyForRequest ¶
func (sp ShardProxies) ProxyForRequest(r *http.Request) (*httputil.ReverseProxy, ProxyMetadata, bool)
ProxyForRequest implements Proxies.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
The cache status header will be set to:
|
The cache status header will be set to: |
Package cachemdw is responsible for caching EVM requests and provides corresponding middleware package can work with any underlying storage which implements simple cache.Cache interface
|
Package cachemdw is responsible for caching EVM requests and provides corresponding middleware package can work with any underlying storage which implements simple cache.Cache interface |