dtcmiddleware

package
v0.1.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package dtcmiddleware provides a middleware for the Developer Credit Tracker.

Index

Constants

View Source
const (
	// EstimateCostKey is a context key for estimating cost
	EstimateCostKey contextKey = "estimateCost"
)

Variables

View Source
var (
	// DCTRequestLatency measures the latency of DCT requests
	DCTRequestLatency = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "telemetry_credit_tracker_grpc_request_latency_seconds",
			Help:    "Latency of Credit Tracker GRPC requests in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"operation"},
	)
)
View Source
var ErrOperationNotSet = errors.New("operation not set")

Functions

func EstimateCostHeaderMiddleware added in v0.1.22

func EstimateCostHeaderMiddleware(next http.Handler) http.Handler

EstimateCostHeaderMiddleware injects estimate cost header into the context

func GetSubjectAndTokenID added in v0.1.21

func GetSubjectAndTokenID(ctx context.Context) (string, *big.Int, *gqlerror.Error)

GetSubjectAndTokenID gets the subject and token ID from the context.

Types

type DCT

type DCT struct {
	Tracker        *credittracker.Client
	CostCalculator *pricing.CostCalculator
}

DCT provides a GraphQL middleware for the Developer Credit Tracker.

func NewDCT

func NewDCT(tracker *credittracker.Client, costCalculator *pricing.CostCalculator) *DCT

NewDCT creates a new DCT middleware with default values.

func (DCT) ExtensionName

func (DCT) ExtensionName() string

ExtensionName returns the name of this extension.

func (DCT) InterceptResponse

func (d DCT) InterceptResponse(
	ctx context.Context,
	next graphql.ResponseHandler,
) *graphql.Response

InterceptResponse intercepts GraphQL responses to handle errors from the credit tracker.

func (DCT) Validate

func (DCT) Validate(schema graphql.ExecutableSchema) error

Validate validates the GraphQL schema.

type EstimateCostResponse added in v0.1.22

type EstimateCostResponse struct {
	EstimatedCredits uint64                 `json:"estimatedCredits"`
	Message          string                 `json:"message"`
	QueryBreakdown   *pricing.CostBreakdown `json:"queryBreakdown"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL