middleware

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package middleware provides any custom gin middlewares used by the service.

Index

Constants

View Source
const ContextKeyInstanceID = "instance-id"

ContextKeyInstanceID is the magic string set in the gin.Context key/value store used for storing the ID of the instance making the request, if the instance has been identified.

View Source
const ContextKeyRequestorIP = "requestor-ip-address"

ContextKeyRequestorIP is the magic string set in the gin.Context key/value store used for storing the IP address of a caller making a request for metadata or userdata.

Variables

View Source
var (
	// MetricMetadataCacheHit total number of metadata requests not requiring external lookups
	MetricMetadataCacheHit = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_cache_hit_total",
		Help: "Number of metadata requests that were immediately found in the db.",
	})

	// MetricMetadataCacheMiss total number of metadata requests that required external lookups
	MetricMetadataCacheMiss = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_cache_miss_total",
		Help: "Number of metadata requests not found in the db that needed to be sent to the lookup service.",
	})

	// MetricUserdataCacheHit total number of userdata requests not requiring external lookups
	MetricUserdataCacheHit = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_cache_hit_total",
		Help: "Number of userdata requests that were immediately found in the db.",
	})

	// MetricUserdataCacheMiss total number of requests that required external lookups
	MetricUserdataCacheMiss = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_cache_miss_total",
		Help: "Number of userdata requests not found in the db that needed to be sent to the lookup service.",
	})

	// MetricMetadataLookupRequestCount total number of metadata requests sent to the external lookup service
	MetricMetadataLookupRequestCount = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_lookup_request_total",
		Help: "Number of metadata lookup requests.",
	})

	// MetricUserdataLookupRequestCount total number of userdata requests sent to the external lookup service
	MetricUserdataLookupRequestCount = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_lookup_request_total",
		Help: "Number of userdata lookup requests.",
	})

	// MetricMetadataInsertsCount total number of metadata inserts (which originate from the API)
	MetricMetadataInsertsCount = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_inserts_total",
		Help: "Number of metadata inserts (which originate from the API).",
	})

	// MetricUserdataInsertsCount total number of userdata inserts (which originate from the API)
	MetricUserdataInsertsCount = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_inserts_total",
		Help: "Number of userdata inserts (which originate from the API).",
	})

	// MetricDeletionsCount total number of metadata deletions (which originate from the API)
	MetricDeletionsCount = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_deletions_total",
		Help: "Number of metadata deletions (which originate from the API).",
	})

	// MetricLookupErrors total number of errors produced during external lookup requests
	MetricLookupErrors = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_lookup_error_total",
		Help: "Number of errors produced during metadata lookups.",
	})

	// MetricMetadataStoreErrors total number of errors produced during saving/updating metadata to the db
	MetricMetadataStoreErrors = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_store_error_total",
		Help: "Number of errors produced while saving or updating metadata to the database.",
	})

	// MetricUserdataLookupErrors total number of errors produced during external userdata lookup requests
	MetricUserdataLookupErrors = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_lookup_error_total",
		Help: "Number of errors produced during metadata lookups.",
	})

	// MetricUserdataStoreErrors total number of errors produced during saving/updating userdata to the db
	MetricUserdataStoreErrors = promauto.NewCounter(prometheus.CounterOpts{
		Name: "metadata_userdata_store_error_total",
		Help: "Number of errors produced while saving or updating userdata to the database.",
	})
)

Functions

func IdentifyInstanceByIP

func IdentifyInstanceByIP(logger *zap.Logger, db *sqlx.DB) gin.HandlerFunc

IdentifyInstanceByIP is used to determine the ID of the instance making the request by looking at the request IP. If a row in the instance_ip_addresses table is found with a matching IP address, we set the instance ID in the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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