Documentation
¶
Index ¶
Constants ¶
const ( OutputFormatFull = "" /* 129-byte string literal not displayed */ OutputFormatCompact = "Request Cost: {totalReqCost} Grand Total: {grandTotal}" )
const ObjectTypeDefault string = "llm_proxy_traffic_log"
const SchemaVersion string = "v2"
const UnknownAddr = "unknown"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API_Provider ¶
type API_Provider struct {
// contains filtered or unexported fields
}
func (*API_Provider) String ¶
func (cc *API_Provider) String() string
type AuditOutput ¶
type AuditOutput struct {
URL string `JSON:"url"`
Model string `JSON:"model"`
InputCost string `JSON:"inputCost"`
OutputCost string `JSON:"outputCost"`
TotalReqCost string `JSON:"totalReqCost"`
GrandTotal string `JSON:"grandTotal"`
}
AuditOutput is a struct that holds the output data (cost totals) from a single transaction
func (*AuditOutput) OutputStringFormatter ¶
func (output *AuditOutput) OutputStringFormatter(formatString string) string
OutputStringFormatter takes an AuditOutput and a format string and returns a formatted string
func (*AuditOutput) String ¶
func (output *AuditOutput) String() string
type ConnectionStatsContainer ¶
type ConnectionStatsContainer struct {
ClientAddress string `json:"client_address"`
URL string `json:"url"`
Duration int64 `json:"duration_ms"`
ProxyID string `json:"proxy_id,omitempty"`
}
func NewConnectionStatusContainerWithDuration ¶
func NewConnectionStatusContainerWithDuration(f *px.Flow, doneAt int64) *ConnectionStatsContainer
NewConnectionStatusContainerWithDuration is a slightly leaky abstraction, the doneAt param is for logging the entire session length, and comes from the proxy addon layer.
func (*ConnectionStatsContainer) ToJSON ¶
func (obj *ConnectionStatsContainer) ToJSON() []byte
func (*ConnectionStatsContainer) ToJSONstr ¶
func (obj *ConnectionStatsContainer) ToJSONstr() string
type CostCounter ¶
type CostCounter struct {
// contains filtered or unexported fields
}
CostCounter is a struct that holds the state of the cost counter
func NewCostCounter ¶
func NewCostCounter(currencyLocale string) *CostCounter
NewCostCounter creates an object that _should_ be a singleton, in the Addon layer. currencyLocale is the locale for the currency formatter, e.g., "en-US" formatString is the output format string, e.g., OutputFormatFull or OutputFormatShort
func NewCostCounterDefaults ¶
func NewCostCounterDefaults() *CostCounter
NewCostCounterDefaults creates a new CostCounter object with reasonable defaults
func (*CostCounter) Add ¶
func (cc *CostCounter) Add(req ProxyRequest, resp ProxyResponse) (*AuditOutput, error)
Add is the primary method for working with this object, it takes a proxy req/resp and calculates the cost of the transaction, returning a struct with the output data
func (*CostCounter) String ¶
func (cc *CostCounter) String() string
type LogDumpContainer ¶
type LogDumpContainer struct {
ObjectType string `json:"object_type,omitempty"`
SchemaVersion string `json:"schema,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
ConnectionStats *ConnectionStatsContainer `json:"connection_stats,omitempty"`
Request *ProxyRequest `json:"request,omitempty"`
Response *ProxyResponse `json:"response,omitempty"`
// contains filtered or unexported fields
}
LogDumpContainer holds the request and response data for a given flow
func NewLogDumpContainer ¶
func NewLogDumpContainer(f *px.Flow, logSources config.LogSourceConfig, doneAt int64, filterReqHeaders, filterRespHeaders []string) (*LogDumpContainer, error)
NewLogDumpContainer returns a LogDumpContainer with *only* the fields requested in logSources populated
type ProxyRequest ¶
type ProxyRequest struct {
Method string `json:"method,omitempty"`
URL *url.URL `json:"url,omitempty"`
Proto string `json:"proto,omitempty"`
Header http.Header `json:"header"`
Body string `json:"body"`
// contains filtered or unexported fields
}
func NewProxyRequestFromMITMRequest ¶
func NewProxyRequestFromMITMRequest(req *px.Request, headersToFilter []string) (*ProxyRequest, error)
NewFromMITMRequest creates a new ProxyRequest from a MITM proxy request object
func (*ProxyRequest) HeaderString ¶
func (pReq *ProxyRequest) HeaderString() string
HeaderString returns the headers as a flat string
func (*ProxyRequest) MarshalJSON ¶
func (pReq *ProxyRequest) MarshalJSON() ([]byte, error)
MarshalJSON dumps this ProxyRequest into a byte array containing JSON
func (*ProxyRequest) UnmarshalJSON ¶
func (pReq *ProxyRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON performs a non-threadsafe load of json data into THIS ProxyRequest
type ProxyResponse ¶
type ProxyResponse struct {
Status int `json:"status,omitempty"`
Header http.Header `json:"header"`
Body string `json:"body"`
// contains filtered or unexported fields
}
func NewProxyResponseFromJSONBytes ¶
func NewProxyResponseFromJSONBytes(data []byte, headersToFilter []string) (*ProxyResponse, error)
NewFromJSONBytes unmarshals a JSON object into a TrafficObject
func NewProxyResponseFromMITMResponse ¶
func NewProxyResponseFromMITMResponse(req *px.Response, headersToFilter []string) (*ProxyResponse, error)
NewFromMITMRequest creates a new ProxyRequest from a MITM proxy request object
func (*ProxyResponse) HeaderString ¶
func (pRes *ProxyResponse) HeaderString() string
HeaderString returns the headers as a flat string
func (*ProxyResponse) ToProxyResponse ¶
func (pRes *ProxyResponse) ToProxyResponse(acceptEncodingHeader string) (*px.Response, error)
ToProxyResponse converts a ProxyResponse into a MITM proxy response object (with content encoding matching the new req) Because all responses are stored as uncompressed strings, the cached response might need to be encoded before being sent
func (*ProxyResponse) UnmarshalJSON ¶
func (pRes *ProxyResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON performs a non-threadsafe load of json data into THIS ProxyResponse