analytics

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MPL-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

View Source
const (
	AgggregateMixedCollectionName     = "tyk_analytics_aggregates"
	GraphAggregateMixedCollectionName = "tyk_graph_analytics_aggregate"
	MongoAggregatePrefix              = "mongo-pump-aggregate"
	AggregateSQLTable                 = "tyk_aggregated"
	AggregateGraphSQLTable            = "tyk_graph_aggregated"
)
View Source
const (
	PredefinedTagGraphAnalytics = "tyk-graph-analytics"
)
View Source
const SQLTable = "tyk_analytics"
View Source
const UptimeSQLTable = "tyk_uptime_analytics"

Variables

View Source
var GraphSQLTableName string

GraphSQLTableName should be defined before SQL migration is called on the GraphRecord the reason this approach is used to define the table name is due to gorm's inability to read values from the fields of the GraphRecord/AnalyticsRecord struct when it is migrating, due to that a single static value is going to be returned as TableName and it will be used as the prefix for index/relationship creation no matter the value passed to db.Table()

Functions

func AggregateData

func AggregateData(data []interface{}, trackAllPaths bool, ignoreTagPrefixList []string, dbIdentifier string, aggregationTime int) map[string]AnalyticsRecordAggregate

AggregateData calculates aggregated data, returns map orgID => aggregated analytics data

func AggregateGraphData added in v1.8.0

func AggregateGraphData(data []interface{}, dbIdentifier string, aggregationTime int) map[string]GraphRecordAggregate

AggregateGraphData collects the graph records into a map of GraphRecordAggregate to apiID

func AggregateUptimeData added in v1.5.0

func AggregateUptimeData(data []UptimeReportData) map[string]UptimeReportAggregate

func OnConflictAssignments added in v1.5.0

func OnConflictAssignments(tableName, tempTable string) map[string]interface{}

func OnConflictUptimeAssignments added in v1.5.0

func OnConflictUptimeAssignments(tableName, tempTable string) map[string]interface{}

func SetlastTimestampAgggregateRecord added in v1.7.0

func SetlastTimestampAgggregateRecord(id string, date time.Time)

SetlastTimestampAgggregateRecord sets the last timestamp for the aggregate record

func TrimTag added in v1.6.0

func TrimTag(thisTag string) string

Types

type AggregateFieldList added in v1.8.0

type AggregateFieldList struct {
	APIKeys       []Counter
	APIID         []Counter
	OauthIDs      []Counter
	Geo           []Counter
	Tags          []Counter
	Errors        []Counter
	Endpoints     []Counter
	KeyEndpoint   map[string][]Counter `bson:"keyendpoints"`
	OauthEndpoint map[string][]Counter `bson:"oauthendpoints"`
	APIEndpoint   []Counter            `bson:"apiendpoints"`
}

type AnalyticsFilters added in v1.0.0

type AnalyticsFilters struct {
	// Filters pump data by the whitelisted org_ids.
	OrgsIDs []string `json:"org_ids"`
	// Filters pump data by the whitelisted api_ids.
	APIIDs []string `json:"api_ids"`
	// Filters pump data by the whitelisted response_codes.
	ResponseCodes []int `json:"response_codes"`
	// Filters pump data by the blacklisted org_ids.
	SkippedOrgsIDs []string `json:"skip_org_ids"`
	// Filters pump data by the blacklisted api_ids.
	SkippedAPIIDs []string `json:"skip_api_ids"`
	// Filters pump data by the blacklisted response_codes.
	SkippedResponseCodes []int `json:"skip_response_codes"`
}

func (AnalyticsFilters) HasFilter added in v1.0.0

func (filters AnalyticsFilters) HasFilter() bool

func (AnalyticsFilters) ShouldFilter added in v1.0.0

func (filters AnalyticsFilters) ShouldFilter(record AnalyticsRecord) bool

type AnalyticsRecord

type AnalyticsRecord struct {
	Method        string       `json:"method" gorm:"column:method"`
	Host          string       `json:"host" gorm:"column:host"`
	Path          string       `json:"path" gorm:"column:path"`
	RawPath       string       `json:"raw_path" gorm:"column:rawpath"`
	ContentLength int64        `json:"content_length" gorm:"column:contentlength"`
	UserAgent     string       `json:"user_agent" gorm:"column:useragent"`
	Day           int          `json:"day" sql:"-"`
	Month         time.Month   `json:"month" sql:"-"`
	Year          int          `json:"year" sql:"-"`
	Hour          int          `json:"hour" sql:"-"`
	ResponseCode  int          `json:"response_code" gorm:"column:responsecode;index"`
	APIKey        string       `json:"api_key" gorm:"column:apikey;index"`
	TimeStamp     time.Time    `json:"timestamp" gorm:"column:timestamp;index"`
	APIVersion    string       `json:"api_version" gorm:"column:apiversion"`
	APIName       string       `json:"api_name" sql:"-"`
	APIID         string       `json:"api_id" gorm:"column:apiid;index"`
	OrgID         string       `json:"org_id" gorm:"column:orgid;index"`
	OauthID       string       `json:"oauth_id" gorm:"column:oauthid;index"`
	RequestTime   int64        `json:"request_time" gorm:"column:requesttime"`
	RawRequest    string       `json:"raw_request" gorm:"column:rawrequest"`
	RawResponse   string       `json:"raw_response" gorm:"column:rawresponse"`
	IPAddress     string       `json:"ip_address" gorm:"column:ipaddress"`
	Geo           GeoData      `json:"geo" gorm:"embedded"`
	Network       NetworkStats `json:"network"`
	Latency       Latency      `json:"latency"`
	Tags          []string     `json:"tags"`
	Alias         string       `json:"alias"`
	TrackPath     bool         `json:"track_path" gorm:"column:trackpath"`
	ExpireAt      time.Time    `bson:"expireAt" json:"expireAt"`
	ApiSchema     string       `json:"api_schema" bson:"-" gorm:"-:all"` //nolint

	GraphQLStats   GraphQLStats `json:"graphql_stats" bson:"-" gorm:"-:all"`
	CollectionName string       `json:"-" bson:"-" gorm:"-:all"`
	// contains filtered or unexported fields
}

AnalyticsRecord encodes the details of a request

func (*AnalyticsRecord) GetFieldNames

func (a *AnalyticsRecord) GetFieldNames() []string

func (*AnalyticsRecord) GetGeo added in v1.6.0

func (a *AnalyticsRecord) GetGeo(ipStr string, GeoIPDB *maxminddb.Reader)

func (*AnalyticsRecord) GetLineValues

func (a *AnalyticsRecord) GetLineValues() []string

func (*AnalyticsRecord) GetObjectID added in v1.8.0

func (a *AnalyticsRecord) GetObjectID() model.ObjectID

func (*AnalyticsRecord) IsGraphRecord added in v1.7.0

func (a *AnalyticsRecord) IsGraphRecord() bool

func (*AnalyticsRecord) RemoveIgnoredFields added in v1.7.0

func (a *AnalyticsRecord) RemoveIgnoredFields(ignoreFields []string)

func (*AnalyticsRecord) SetExpiry added in v1.6.0

func (a *AnalyticsRecord) SetExpiry(expiresInSeconds int64)

func (*AnalyticsRecord) SetObjectID added in v1.8.0

func (a *AnalyticsRecord) SetObjectID(id model.ObjectID)

func (*AnalyticsRecord) TableName added in v1.5.0

func (a *AnalyticsRecord) TableName() string

func (*AnalyticsRecord) TimeStampFromProto added in v1.6.0

func (a *AnalyticsRecord) TimeStampFromProto(protoRecord analyticsproto.AnalyticsRecord)

func (*AnalyticsRecord) TimestampToProto added in v1.6.0

func (a *AnalyticsRecord) TimestampToProto(newRecord *analyticsproto.AnalyticsRecord)

TimestampToProto will process timestamps and assign them to the proto record protobuf converts all timestamps to UTC so we need to ensure that we keep the same original location, in order to do so, we store the location

func (*AnalyticsRecord) ToGraphRecord added in v1.7.0

func (a *AnalyticsRecord) ToGraphRecord() GraphRecord

func (*AnalyticsRecord) TrimRawData added in v1.5.0

func (a *AnalyticsRecord) TrimRawData(size int)

type AnalyticsRecordAggregate

type AnalyticsRecordAggregate struct {
	TimeStamp time.Time
	OrgID     string
	TimeID    struct {
		Year  int
		Month int
		Day   int
		Hour  int
	}

	APIKeys map[string]*Counter
	Errors  map[string]*Counter

	Versions map[string]*Counter
	APIID    map[string]*Counter
	OauthIDs map[string]*Counter
	Geo      map[string]*Counter
	Tags     map[string]*Counter

	Endpoints map[string]*Counter

	Lists AggregateFieldList

	KeyEndpoint   map[string]map[string]*Counter `bson:"keyendpoints"`
	OauthEndpoint map[string]map[string]*Counter `bson:"oauthendpoints"`
	ApiEndpoint   map[string]*Counter            `bson:"apiendpoints"`

	Total Counter

	ExpireAt time.Time `bson:"expireAt" json:"expireAt"`
	LastTime time.Time
	Mixed    bool `bson:"-" json:"-"`
	// contains filtered or unexported fields
}

func (*AnalyticsRecordAggregate) AsChange

func (f *AnalyticsRecordAggregate) AsChange() (newUpdate model.DBM)

func (*AnalyticsRecordAggregate) AsTimeUpdate

func (f *AnalyticsRecordAggregate) AsTimeUpdate() model.DBM

func (*AnalyticsRecordAggregate) Dimensions added in v1.5.0

func (f *AnalyticsRecordAggregate) Dimensions() (dimensions []Dimension)

func (*AnalyticsRecordAggregate) DiscardAggregations added in v1.2.0

func (f *AnalyticsRecordAggregate) DiscardAggregations(fields []string)

DiscardAggregations this method discard the aggregations of X field specified in the aggregated pump configuration

func (*AnalyticsRecordAggregate) GetObjectID added in v1.8.0

func (f *AnalyticsRecordAggregate) GetObjectID() model.ObjectID

func (AnalyticsRecordAggregate) New

func (*AnalyticsRecordAggregate) SetErrorList added in v1.0.0

func (f *AnalyticsRecordAggregate) SetErrorList(parent, thisUnit string, counter *Counter, newUpdate model.DBM)

func (*AnalyticsRecordAggregate) SetObjectID added in v1.8.0

func (f *AnalyticsRecordAggregate) SetObjectID(id model.ObjectID)

func (*AnalyticsRecordAggregate) TableName added in v1.8.0

func (f *AnalyticsRecordAggregate) TableName() string

type City added in v1.6.0

type City struct {
	GeoNameID uint              `maxminddb:"geoname_id" json:"geoname_id"`
	Names     map[string]string `maxminddb:"names" json:"names"`
}

type Code added in v1.5.0

type Code struct {
	Code1x  int `json:"1x" gorm:"1x"`
	Code200 int `json:"200" gorm:"200"`
	Code201 int `json:"201" gorm:"201"`
	Code2x  int `json:"2x" gorm:"2x"`
	Code301 int `json:"301" gorm:"301"`
	Code302 int `json:"302" gorm:"302"`
	Code303 int `json:"303" gorm:"303"`
	Code304 int `json:"304" gorm:"304"`
	Code3x  int `json:"3x" gorm:"3x"`
	Code400 int `json:"400" gorm:"400"`
	Code401 int `json:"401" gorm:"401"`
	Code403 int `json:"403" gorm:"403"`
	Code404 int `json:"404" gorm:"404"`
	Code429 int `json:"429" gorm:"429"`
	Code4x  int `json:"4x" gorm:"4x"`
	Code500 int `json:"500" gorm:"500"`
	Code501 int `json:"501" gorm:"501"`
	Code502 int `json:"502" gorm:"502"`
	Code503 int `json:"503" gorm:"503"`
	Code504 int `json:"504" gorm:"504"`
	Code5x  int `json:"5x" gorm:"5x"`
}

func (*Code) ProcessStatusCodes added in v1.5.0

func (c *Code) ProcessStatusCodes(errorMap map[string]int)

type Counter

type Counter struct {
	Hits                 int       `json:"hits"`
	Success              int       `json:"success"`
	ErrorTotal           int       `json:"error" gorm:"column:error"`
	RequestTime          float64   `json:"request_time"`
	TotalRequestTime     float64   `json:"total_request_time"`
	Identifier           string    `json:"identifier" sql:"-"`
	HumanIdentifier      string    `json:"human_identifier"`
	LastTime             time.Time `json:"last_time"`
	OpenConnections      int64     `json:"open_connections"`
	ClosedConnections    int64     `json:"closed_connections"`
	BytesIn              int64     `json:"bytes_in"`
	BytesOut             int64     `json:"bytes_out"`
	MaxUpstreamLatency   int64     `json:"max_upstream_latency"`
	MinUpstreamLatency   int64     `json:"min_upstream_latency"`
	TotalUpstreamLatency int64     `json:"total_upstream_latency"`
	UpstreamLatency      float64   `json:"upstream_latency"`

	MaxLatency   int64   `json:"max_latency"`
	MinLatency   int64   `json:"min_latency"`
	TotalLatency int64   `json:"total_latency"`
	Latency      float64 `json:"latency"`

	ErrorMap  map[string]int `json:"error_map" sql:"-"`
	ErrorList []ErrorData    `json:"error_list" sql:"-"`
}

type Country added in v1.5.0

type Country struct {
	ISOCode string `maxminddb:"iso_code" json:"iso_code"`
}

type Dimension added in v1.5.0

type Dimension struct {
	Name    string
	Value   string
	Counter *Counter
}

type ErrorData added in v1.0.0

type ErrorData struct {
	Code  string
	Count int
}

type GeoData

type GeoData struct {
	Country  Country  `maxminddb:"country" json:"country"`
	City     City     `maxminddb:"city" json:"city"`
	Location Location `maxminddb:"location" json:"location"`
}

func GeoIPLookup added in v1.6.0

func GeoIPLookup(ipStr string, GeoIPDB *maxminddb.Reader) (*GeoData, error)

func (*GeoData) GetFieldNames added in v1.3.0

func (g *GeoData) GetFieldNames() []string

func (*GeoData) GetLineValues added in v1.3.0

func (g *GeoData) GetLineValues() []string

type GraphError added in v1.7.0

type GraphError struct {
	Message string        `json:"message"`
	Path    []interface{} `json:"path"`
}

type GraphQLOperations added in v1.9.0

type GraphQLOperations int
const (
	OperationUnknown GraphQLOperations = iota
	OperationQuery
	OperationMutation
	OperationSubscription
)

type GraphQLStats added in v1.9.0

type GraphQLStats struct {
	Variables     string
	RootFields    []string
	Types         map[string][]string
	Errors        []GraphError
	OperationType GraphQLOperations
	HasErrors     bool
	IsGraphQL     bool
}

type GraphRecord added in v1.7.0

type GraphRecord struct {
	Types map[string][]string `gorm:"types"`

	AnalyticsRecord AnalyticsRecord `bson:",inline" gorm:"embedded;embeddedPrefix:analytics_"`

	OperationType string       `gorm:"column:operation_type"`
	Variables     string       `gorm:"variables"`
	RootFields    []string     `gorm:"root_fields"`
	Errors        []GraphError `gorm:"errors"`
	HasErrors     bool         `gorm:"has_errors"`
}

func (*GraphRecord) GetObjectID added in v1.8.0

func (*GraphRecord) GetObjectID() model.ObjectID

GetObjectID is a dummy function to satisfy the interface

func (*GraphRecord) SetObjectID added in v1.8.0

func (*GraphRecord) SetObjectID(model.ObjectID)

SetObjectID is a dummy function to satisfy the interface

func (*GraphRecord) TableName added in v1.8.0

func (g *GraphRecord) TableName() string

TableName is used by both the sql orm and mongo driver the table name and collection name used for operations on this model the conditional return is to ensure the right value is used for both the sql and mongo operations

type GraphRecordAggregate added in v1.8.0

type GraphRecordAggregate struct {
	AnalyticsRecordAggregate

	Types      map[string]*Counter
	Fields     map[string]*Counter
	Operation  map[string]*Counter
	RootFields map[string]*Counter
}

func NewGraphRecordAggregate added in v1.8.0

func NewGraphRecordAggregate() GraphRecordAggregate

func (*GraphRecordAggregate) Dimensions added in v1.8.0

func (g *GraphRecordAggregate) Dimensions() []Dimension

type GraphSQLAnalyticsRecordAggregate added in v1.9.0

type GraphSQLAnalyticsRecordAggregate struct {
	ID string `gorm:"primaryKey"`

	OrgID          string `json:"org_id"`
	Dimension      string `json:"dimension"`
	DimensionValue string `json:"dimension_value"`
	APIID          string `json:"api_id"`

	Counter `json:"counter" gorm:"embedded"`
	Code    `json:"code" gorm:"embedded"`

	TimeStamp int64 `json:"timestamp"`
}

type Latency

type Latency struct {
	Total    int64 `json:"total"`
	Upstream int64 `json:"upstream"`
}

func (*Latency) GetFieldNames added in v1.3.0

func (l *Latency) GetFieldNames() []string

func (*Latency) GetLineValues added in v1.3.0

func (l *Latency) GetLineValues() []string

type Location added in v1.6.0

type Location struct {
	Latitude  float64 `maxminddb:"latitude" json:"latitude"`
	Longitude float64 `maxminddb:"longitude" json:"longitude"`
	TimeZone  string  `maxminddb:"time_zone" json:"time_zone"`
}

type NetworkStats

type NetworkStats struct {
	OpenConnections  int64 `json:"open_connections"`
	ClosedConnection int64 `json:"closed_connections"`
	BytesIn          int64 `json:"bytes_in"`
	BytesOut         int64 `json:"bytes_out"`
}

func (*NetworkStats) Flush added in v1.6.0

func (n *NetworkStats) Flush() NetworkStats

func (*NetworkStats) GetFieldNames added in v1.3.0

func (n *NetworkStats) GetFieldNames() []string

func (*NetworkStats) GetLineValues added in v1.3.0

func (n *NetworkStats) GetLineValues() []string

type SQLAnalyticsRecordAggregate added in v1.5.0

type SQLAnalyticsRecordAggregate struct {
	ID string `gorm:"primaryKey"`

	Counter `json:"counter" gorm:"embedded"`

	TimeStamp      int64  `json:"timestamp"`
	OrgID          string `json:"org_id"`
	Dimension      string `json:"dimension"`
	DimensionValue string `json:"dimension_value"`

	Code `json:"code" gorm:"embedded"`
}

func (*SQLAnalyticsRecordAggregate) TableName added in v1.5.0

func (f *SQLAnalyticsRecordAggregate) TableName() string

type UptimeReportAggregate added in v1.5.0

type UptimeReportAggregate struct {
	TimeStamp time.Time
	OrgID     string
	TimeID    struct {
		Year  int
		Month int
		Day   int
		Hour  int
	}

	URL    map[string]*Counter
	Errors map[string]*Counter

	Total Counter

	ExpireAt time.Time `bson:"expireAt" json:"expireAt"`
	LastTime time.Time
}

func (*UptimeReportAggregate) Dimensions added in v1.5.0

func (u *UptimeReportAggregate) Dimensions() (dimensions []Dimension)

func (UptimeReportAggregate) New added in v1.5.0

type UptimeReportAggregateSQL added in v1.5.0

type UptimeReportAggregateSQL struct {
	ID string `gorm:"primaryKey"`

	Counter `json:"counter" gorm:"embedded"`

	TimeStamp      int64  `json:"timestamp" gorm:"index:dimension, priority:1"`
	OrgID          string `json:"org_id" gorm:"index:dimension, priority:2"`
	Dimension      string `json:"dimension" gorm:"index:dimension, priority:3"`
	DimensionValue string `json:"dimension_value" gorm:"index:dimension, priority:4"`

	Code `json:"code" gorm:"embedded"`
}

func (*UptimeReportAggregateSQL) TableName added in v1.5.0

func (a *UptimeReportAggregateSQL) TableName() string

type UptimeReportData

type UptimeReportData struct {
	ID           model.ObjectID `json:"_id" bson:"_id" gorm:"-:all"`
	URL          string         `json:"url"`
	RequestTime  int64          `json:"request_time"`
	ResponseCode int            `json:"response_code"`
	TCPError     bool           `json:"tcp_error"`
	ServerError  bool           `json:"server_error"`
	Day          int            `json:"day"`
	Month        time.Month     `json:"month"`
	Year         int            `json:"year"`
	Hour         int            `json:"hour"`
	Minute       int            `json:"minute"`
	TimeStamp    time.Time      `json:"timestamp"`
	ExpireAt     time.Time      `bson:"expireAt"`
	APIID        string         `json:"api_id"`
	OrgID        string         `json:"org_id"`
}

func (*UptimeReportData) GetObjectID added in v1.8.0

func (a *UptimeReportData) GetObjectID() model.ObjectID

func (*UptimeReportData) SetObjectID added in v1.8.0

func (a *UptimeReportData) SetObjectID(id model.ObjectID)

func (*UptimeReportData) TableName added in v1.8.0

func (a *UptimeReportData) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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