Go API Documentation

github.com/TykTechnologies/tyk-pump

No package summary is available.

Package

Files: 4. Third party imports: 4. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

Types

PumpConfig

This type doesn't have documentation.

Field name Field type Comment
Name

string

The name of the pump. This is used to identify the pump in the logs. Deprecated, use type instead.

Type

string

Sets the pump type. This is needed when the pump key does not equal to the pump name type. Current valid types are: mongo, mongo-pump-selective, mongo-pump-aggregate, csv, elasticsearch, influx, influx2, moesif, statsd, segment, graylog, splunk, hybrid, prometheus, logzio, dogstatsd, kafka, syslog, sql, sql_aggregate, stdout, timestream, mongo-graph, sql-graph, sql-graph-aggregate, resurfaceio.

Filters

analytics.AnalyticsFilters

This feature adds a new configuration field in each pump called filters and its structure is the following:

"filters":{
  "api_ids":[],
  "org_ids":[],
  "response_codes":[],
  "skip_api_ids":[],
  "skip_org_ids":[],
  "skip_response_codes":[]
}

The fields api_ids, org_ids and response_codes works as allow list (APIs and orgs where we want to send the analytics records) and the fields skip_api_ids, skip_org_ids and skip_response_codes works as block list.

The priority is always block list configurations over allow list.

An example of configuration would be:

"csv": {
 "type": "csv",
 "filters": {
   "org_ids": ["org1","org2"]
 },
 "meta": {
   "csv_dir": "./bar"
 }
}
Timeout

int

By default, a pump will wait forever for each write operation to complete; you can configure an optional timeout by setting the configuration option timeout. If you have deployed multiple pumps, then you can configure each timeout independently. The timeout is in seconds and defaults to 0.

The timeout is configured within the main pump config as shown here; note that this example would configure a 5 second timeout:

"pump_name": {
  ...
  "timeout":5,
  "meta": {...}
}

Tyk will inform you if the pump's write operation is taking longer than the purging loop (configured via purge_delay) as this will mean that data is purged before being written to the target data sink.

If there is no timeout configured and pump's write operation is taking longer than the purging loop, the following warning log will be generated: Pump {pump_name} is taking more time than the value configured of purge_delay. You should try to set a timeout for this pump.

If there is a timeout configured, but pump's write operation is still taking longer than the purging loop, the following warning log will be generated: Pump {pump_name} is taking more time than the value configured of purge_delay. You should try lowering the timeout configured for this pump..

OmitDetailedRecording

bool

Setting this to true will avoid writing raw_request and raw_response fields for each request in pumps. Defaults to false.

MaxRecordSize

int

Defines maximum size (in bytes) for Raw Request and Raw Response logs, this value defaults to 0. If it is not set then tyk-pump will not trim any data and will store the full information. This can also be set at a pump level. For example:

"csv": {
  "type": "csv",
  "max_record_size":1000,
  "meta": {
    "csv_dir": "./"
  }
}
IgnoreFields

[]string

IgnoreFields defines a list of analytics fields that will be ignored when writing to the pump. This can be used to avoid writing sensitive information to the Database, or data that you don't really need to have. The field names must be the same as the JSON tags of the analytics record fields. For example: ["api_key", "api_version"].

Meta

map[string]any

Meta is a map of configuration values that are specific to each pump. For example, the csv pump requires a csv_dir value to be set, that need to be set in the meta map.

DecodeRawRequest

bool

Setting this to true allows the Raw Request to be decoded from base 64 for all pumps. This is set to false by default.

DecodeRawResponse

bool

Setting this to true allows the Raw Response to be decoded from base 64 for all pumps. This is set to false by default.

StatsDSink

This type doesn't have documentation.

Field name Field type Comment
options

StatsDSinkOptions

No comment on field.
cmdChan

chan statsdEmitCmd

No comment on field.
drainDoneChan

chan struct{}

No comment on field.
stopDoneChan

chan struct{}

No comment on field.
flushPeriod

time.Duration

No comment on field.
udpBuf

bytes.Buffer

No comment on field.
timingBuf

[]byte

No comment on field.
udpConn

*net.UDPConn

No comment on field.
udpAddr

*net.UDPAddr

No comment on field.
prefixBuffers

map[eventKey]prefixBuffer

map of {job,event,suffix} to a re-usable buffer prefixed with the key. Since each timing/gauge has a unique component (the time), we'll truncate to the prefix, write the timing, and write the statsD suffix (eg, "|ms\n"). Then copy that to the UDP buffer.

StatsDSinkOptions

This type doesn't have documentation.

Field name Field type Comment
Prefix

string

Prefix is something like "metroid" Events emitted to StatsD would be metroid.myevent.wat Eg, don't include a trailing dot in the prefix. It can be "", that's fine.

SanitizationFunc

StatsDSinkSanitizationFunc

SanitizationFunc sanitizes jobs and events before sending them to statsd

SkipNestedEvents

bool

SkipNestedEvents will skip {events,timers,gauges} from sending the job.event version and will only send the event version.

SkipTopLevelEvents

bool

SkipTopLevelEvents will skip {events,timers,gauges} from sending the event version and will only send the job.event version.

StatsDSinkSanitizationFunc

This type doesn't have documentation.

Field name Field type Comment
type

func(*bytes.Buffer, string)

No comment on field.

TykPumpConfiguration

This type doesn't have documentation.

Field name Field type Comment
PurgeDelay

int

The number of seconds the Pump waits between checking for analytics data and purge it from Redis.

PurgeChunk

int64

The maximum number of records to pull from Redis at a time. If it's unset or 0, all the analytics records in Redis are pulled. If it's set, storage_expiration_time is used to reset the analytics record TTL.

StorageExpirationTime

int64

The number of seconds for the analytics records TTL. It only works if purge_chunk is enabled. Defaults to 60 seconds.

DontPurgeUptimeData

bool

Setting this to false will create a pump that pushes uptime data to Uptime Pump, so the Dashboard can read it. Disable by setting to true.

UptimePumpConfig

UptimeConf

Example Uptime Pump configuration:

"uptime_pump_config": {
  "uptime_type": "mongo",
  "mongo_url": "mongodb://localhost:27017",
  "collection_name": "tyk_uptime_analytics"
},
Pumps

map[string]PumpConfig

The default environment variable prefix for each pump follows this format: TYK_PMP_PUMPS_{PUMP-NAME}_, for example TYK_PMP_PUMPS_KAFKA_.

You can also set custom names for each pump specifying the pump type. For example, if you want a Kafka pump which is called PROD you need to create TYK_PMP_PUMPS_PROD_TYPE=kafka and configure it using the TYK_PMP_PUMPS_PROD_ prefix.

AnalyticsStorageType

string

Sets the analytics storage type. Where the pump will be fetching data from. Currently, only the redis option is supported.

AnalyticsStorageConfig

storage.TemporalStorageConfig

Example Temporal storage configuration:

  "analytics_storage_config": {
    "type": "redis",
    "host": "localhost",
    "port": 6379,
    "hosts": null,
    "username": "",
    "password": "",
    "database": 0,
    "optimisation_max_idle": 100,
    "optimisation_max_active": 0,
    "enable_cluster": false,
    "use_ssl": false,
    "ssl_insecure_skip_verify": false
  },
StatsdConnectionString

string

Connection string for StatsD monitoring for information please see the Instrumentation docs.

StatsdPrefix

string

Custom prefix value. For example separate settings for production and staging.

LogLevel

string

Set the logger details for tyk-pump. The posible values are: info,debug,error and warn. By default, the log level is info.

LogFormat

string

Set the logger format. The possible values are: text and json. By default, the log format is text.

HealthCheckEndpointName

string

TYKCONFIGHEADERSTART HEADER Health Check From v2.9.4, we have introduced a /health endpoint to confirm the Pump is running. You need to configure the following settings. This returns a HTTP 200 OK response if the Pump is running. TYKCONFIGHEADEREND The default is "hello".

HealthCheckEndpointPort

int

The default port is 8083.

OmitDetailedRecording

bool

Setting this to true will avoid writing raw_request and raw_response fields for each request in pumps. Defaults to false.

MaxRecordSize

int

Defines maximum size (in bytes) for Raw Request and Raw Response logs, this value defaults to 0. If it is not set then tyk-pump will not trim any data and will store the full information. This can also be set at a pump level. For example:

"csv": {
  "type": "csv",
  "max_record_size":1000,
  "meta": {
    "csv_dir": "./"
  }
}
OmitConfigFile

bool

Defines if tyk-pump should ignore all the values in configuration file. Specially useful when setting all configurations in environment variables.

HTTPProfile

bool

Enable debugging of Tyk Pump by exposing profiling information, the same as the gateway https://tyk.io/docs/troubleshooting/tyk-gateway/profiling/

DecodeRawRequest

bool

Setting this to true allows the Raw Request to be decoded from base 64 for all pumps. This is set to false by default.

DecodeRawResponse

bool

Setting this to true allows the Raw Response to be decoded from base 64 for all pumps. This is set to false by default.

UptimeConf

This type doesn't have documentation.

Field name Field type Comment

pumps.MongoConf

TYKCONFIGHEADERSTART HEADER Mongo Uptime Pump In uptime_pump_config you can configure a mongo uptime pump. By default, the uptime pump is going to be mongo type, so it's not necessary to specify it here. The minimum required configurations for uptime pumps are:

  • collection_name - That determines the uptime collection name in mongo. By default, tyk_uptime_analytics.
  • mongo_url - The uptime pump mongo connection url. It is usually something like "mongodb://username:password@{hostname:port},{hostname:port}/{db_name}". TYKCONFIGHEADEREND TYKCONFIGEXPAND

pumps.SQLConf

TYKCONFIGHEADERSTART HEADER SQL Uptime Pump Supported in Tyk Pump v1.5.0+

In uptime_pump_config you can configure a SQL uptime pump. To do that, you need to add the field uptime_type with sql value. You can also use different types of SQL Uptime pumps, like postgres using the type field.

An example of a SQL Postgres uptime pump would be:

"uptime_pump_config": {
    "uptime_type": "sql",
    "type": "postgres",
    "connection_string": "host=sql_host port=sql_port user=sql_usr dbname=dbname password=sql_pw",
    "table_sharding": false
},

Take into account that you can also set log_level field into the uptime_pump_config to debug, info or warning. By default, the SQL logger verbosity is silent. TYKCONFIGHEADEREND TYKCONFIGEXPAND

UptimeType

string

Determines the uptime type. Options are mongo and sql. Defaults to mongo.

eventKey

This type doesn't have documentation.

Field name Field type Comment
job

string

No comment on field.
event

string

No comment on field.
suffix

string

No comment on field.

prefixBuffer

This type doesn't have documentation.

Field name Field type Comment

*bytes.Buffer

No comment on field.
prefixLen

int

No comment on field.

statsdCmdKind

This type doesn't have documentation.

Field name Field type Comment
type

int

No comment on field.

statsdEmitCmd

This type doesn't have documentation.

Field name Field type Comment
Kind

statsdCmdKind

No comment on field.
Job

string

No comment on field.
Event

string

No comment on field.
Nanos

int64

No comment on field.
Value

float64

No comment on field.
Status

health.CompletionStatus

No comment on field.

Functions

func Init

Uses: kingpin.Parse, logrus.DebugLevel, logrus.ErrorLevel, logrus.Fields, logrus.JSONFormatter, logrus.WarnLevel, os.Getenv, pumps.Version, serializer.AnalyticsSerializer, serializer.MSGP_SERIALIZER, serializer.NewAnalyticsSerializer, serializer.PROTOBUF_SERIALIZER, strings.ToLower.

func LoadConfig

Uses: envconfig.Process, ioutil.ReadFile, json.Unmarshal, strings.ToUpper.

func MonitorApplicationInstrumentation

Uses: debug.ReadGCStats, health.Kvs, time.Duration, time.Second, time.Sleep.

func NewStatsDSink

Uses: net.ListenPacket, net.ResolveUDPAddr, net.UDPConn, time.Millisecond.

func PreprocessAnalyticsValues

Uses: analytics.AnalyticsRecord, logrus.Fields.

func SetupInstrumentation

SetupInstrumentation handles all the intialisation of the instrumentation handler

Uses: os.Getenv.

func StartPurgeLoop

Uses: fmt.Sprintf, logrus.Fields, storage.ANALYTICS_KEYNAME, storage.UptimeAnalytics_KEYNAME, time.Duration, time.Now, time.Second, time.Since, time.Tick.

func (*StatsDSink) Drain

func (*StatsDSink) EmitComplete

func (*StatsDSink) EmitEvent

func (*StatsDSink) EmitEventErr

func (*StatsDSink) EmitGauge

func (*StatsDSink) EmitTiming

func (*StatsDSink) Stop

func (*TykPumpConfiguration) LoadPumpsByEnv

Uses: envconfig.Process, fmt.Sprintf, os.Environ, os.LookupEnv, pumps.AvailablePumps, strings.HasPrefix, strings.Split, strings.ToLower, strings.ToUpper, strings.TrimPrefix.

Private functions

func checkShutdown

References: logrus.Fields.

func execPumpWriting

References: context.Background, context.CancelFunc, context.Canceled, context.Context, context.DeadlineExceeded, context.WithCancel, context.WithTimeout, logrus.Fields, pumps.Pump, time.AfterFunc, time.Duration, time.Second, time.Since.

func filterData

References: analytics.AnalyticsRecord, base64.StdEncoding.

func initialisePumps

References: logrus.Fields, pumps.GetPumpByName, pumps.Pump.

func initialiseUptimePump

References: logrus.Fields, pumps.MongoPump, pumps.SQLPump.

func main

References: context.Background, context.WithCancel, demo.DemoInit, demo.GenerateDemoData, logrus.Fields, os.Interrupt, os.Signal, server.ServeHealthCheck, signal.Notify, sync.WaitGroup, syscall.SIGINT, syscall.SIGTERM, time.Duration, time.Now, time.Second.

func sanitizeKey

func setupAnalyticsStore

References: logrus.Fields, storage.NewTemporalStorageHandler.

func storeVersion

References: logrus.Fields, pumps.Version, storage.NewTemporalStorageHandler.

func writeToPumps

References: logrus.Fields, sync.WaitGroup.

func flush

func getPrefixBuffer

References: bytes.Buffer.

func loop

References: time.NewTicker.

func processCmd

func processComplete

func processEvent

func processEventErr

func processGauge

References: strconv.AppendFloat.

func processTiming

func writeNanosToTimingBuf

References: strconv.AppendFloat, strconv.AppendInt, time.Millisecond.

func writeSanitizedKeys

func writeStatsDMetric

assumes b is a well-formed statsd metric like "job.event:1|c\n" (including newline)

func shouldOmitConfigFile

References: os.LookupEnv, strings.EqualFold.


Tests

Files: 2. Third party imports: 1. Imports from organisation: 2. Tests: 12. Benchmarks: 0.

Types

MockedPump

This type doesn't have documentation.

Field name Field type Comment
CounterRequest

int

No comment on field.
TurnedOff

bool

No comment on field.

pumps.CommonPumpConfig

No comment on field.

Test functions

TestConfigEnv

References: assert.Contains, assert.Equal, assert.Len, os.Setenv, os.Unsetenv.

TestDecodedKey

References: analytics.AnalyticsRecord, assert.Equal, assert.Len, assert.True, testing.T.

TestFilterData

References: analytics.AnalyticsFilters, analytics.AnalyticsRecord.

TestIgnoreConfig

References: assert.Equal, os.Setenv, os.Unsetenv, testing.T.

TestIgnoreFieldsFilterData

References: analytics.AnalyticsRecord, assert.Equal, assert.True, testing.T.

TestLoadExampleConf

References: assert.Equal, assert.NotNil, assert.NotZero, strings.ToUpper.

TestOmitDetailsFilterData

References: analytics.AnalyticsRecord.

TestShutdown

References: analytics.AnalyticsFilters, context.Background, context.WithCancel, os.Interrupt, os.Signal, pumps.Pump, signal.Notify, sync.WaitGroup, syscall.SIGINT, syscall.SIGTERM.

TestToUpperPumps

References: assert.Equal, os.Setenv, os.Unsetenv, strings.ToUpper.

TestTrimData

References: analytics.AnalyticsRecord, assert.Equal, assert.True, testing.T.

TestTykPumpConfiguration_LoadPumpsByEnv

References: assert.Equal, assert.NoError, os.Setenv, os.Unsetenv, testing.T.

TestWriteDataWithFilters

References: analytics.AnalyticsFilters, analytics.AnalyticsRecord, assert.Equal, assert.Len, pumps.Pump, testing.T, time.Now.