Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
[TT-10016] Added support of analytics plugin (#671)
Browse files Browse the repository at this point in the history
* Add support of analytics plugin

* Update changelog

* Update docs and add sample

* Update deepcopy file

* Update api/model/api.go

Co-authored-by: Burak Sekili <[email protected]>

* Update api/model/api.go

Co-authored-by: Burak Sekili <[email protected]>

* Update api.go

* Update crds

* Fix linter error

* Mark enable field as optional again

* Set field as pointer

* Update default tyk version to v5.2

---------

Co-authored-by: Burak Sekili <[email protected]>
  • Loading branch information
komalsukhani and buraksekili authored Jan 11, 2024
1 parent 28bcef0 commit c84ece1
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `imagePullSecrets` configuration for ServiceAccount in Tyk Operator Helm chart
- Added `tyk` to `categories` field of CRDs. So, from now on, all CRs related to Tyk Operator is grouped
into `tyk` category and can be displayed via `kubectl get tyk`.
- Added support of analytics plugin
- Added `global_headers` support for UDG API Definition
- Added `introspection` option to disable GraphQL introspection
- Added `detailed_tracing` of APIDefinition for OpenTelemetry
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

TYK_VERSION ?= v4.3
TYK_VERSION ?= v5.2

# Image URL to use all building/pushing image targets
IMG ?= tyk-operator:latest
Expand Down
12 changes: 12 additions & 0 deletions api/model/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,23 @@ type APIDefinitionSpec struct {

GraphQL *GraphQLConfig `json:"graphql,omitempty"`

// AnalyticsPlugin is used to configure analytics plugin which enables editing or removal of all parts of analytics
// records, raw request and responses recorded by Tyk at the gateway level
// +optional
// +nullable
AnalyticsPlugin *AnalyticsPluginConfig `json:"analytics_plugin,omitempty"`

// +optional
// +nullable
DetailedTracing *bool `json:"detailed_tracing,omitempty"`
}

type AnalyticsPluginConfig struct {
Enabled bool `json:"enable"`
PluginPath string `json:"plugin_path,omitempty"`
FuncName string `json:"func_name,omitempty"`
}

func (a *APIDefinitionSpec) CollectLoopingTarget() (targets []Target) {
fn := func(t Target) {
targets = append(targets, t)
Expand Down
17 changes: 17 additions & 0 deletions api/model/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions config/crd/bases/tyk.tyk.io_apidefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ spec:
items:
type: string
type: array
analytics_plugin:
description: AnalyticsPlugin is used to configure analytics plugin
which enables editing or removal of all parts of analytics records,
raw request and responses recorded by Tyk at the gateway level
nullable: true
properties:
enable:
type: boolean
func_name:
type: string
plugin_path:
type: string
required:
- enable
type: object
api_id:
description: 'Only set this field if you are referring to an existing
API def. The Operator will use this APIID to link the CR with the
Expand Down
19 changes: 19 additions & 0 deletions config/samples/analytics_plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# It is assumed that you have already created and uploaded analytics plugin to gateway filesystem.
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: analytics-plugin
spec:
name: httpbin-analytics-plugin
active: true
protocol: http
proxy:
listen_path: /httpbin
strip_listen_path: true
target_url: http://httpbin.org
use_keyless: true
enable_detailed_recording: true
analytics_plugin:
enable: true
func_name: MaskAnalyticsData # Replace it with function name of your plugin
plugin_path: /opt/tyk-gateway/plugins/example-plugin.so # Replace it with path of your plugin file
1 change: 1 addition & 0 deletions docs/api_definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ To check the supported features of the API Definitions CRD version you're curren
| Custom Plugins - Javascript || v0.1 | - | [Sample](./api_definitions/custom_plugin.md) |
| Custom Plugins - Lua | ⚠️ | v0.1 | Untested |
| Custom Plugins - Python | ⚠️ | v0.1 | Untested |
| Custom Plugins - Analytics Plugin || v0.16.0 | - | [Sample](./../config/samples/analytics_plugin.yaml)|
| Global Rate Limit || v0.10 | - | [Sample](./../config/samples/httpbin_global_rate_limit.yaml) |
| Segment Tags || v0.1 | - | [Sample](./../config/samples/httpbin_tagged.yaml) |
| Tag Headers | ⚠️ | - | Untested |
Expand Down
13 changes: 13 additions & 0 deletions helm/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ spec:
items:
type: string
type: array
analytics_plugin:
description: AnalyticsPlugin is used to configure analytics plugin which enables editing or removal of all parts of analytics records, raw request and responses recorded by Tyk at the gateway level
nullable: true
properties:
enable:
type: boolean
func_name:
type: string
plugin_path:
type: string
required:
- enable
type: object
api_id:
description: 'Only set this field if you are referring to an existing API def. The Operator will use this APIID to link the CR with the API in Tyk Note: The values in the CR will become the new source of truth, overriding the existing API Definition'
type: string
Expand Down

0 comments on commit c84ece1

Please sign in to comment.