Skip to content

Commit

Permalink
Merge pull request #651 from 3scale/backport-644-add-opentracing
Browse files Browse the repository at this point in the history
[Backport 644] add opentracing
  • Loading branch information
eguzki authored Aug 16, 2021
2 parents 9c3ae02 + 85de816 commit aefaae3
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 10 deletions.
82 changes: 82 additions & 0 deletions apis/apps/v1alpha1/apimanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/3scale/3scale-operator/pkg/3scale/amp/component"
"github.com/3scale/3scale-operator/pkg/3scale/amp/product"
"github.com/3scale/3scale-operator/pkg/common"
"github.com/3scale/3scale-operator/version"
Expand Down Expand Up @@ -203,6 +204,10 @@ type ApicastProductionSpec struct {
// CustomPolicies specifies an array of defined custome policies to be loaded
// +optional
CustomPolicies []CustomPolicySpec `json:"customPolicies,omitempty"`
// OpenTracing contains the OpenTracing integration configuration
// with APIcast in the production environment.
// +optional
OpenTracing *APIcastOpenTracingSpec `json:"openTracing,omitempty"`
}

type ApicastStagingSpec struct {
Expand All @@ -220,6 +225,10 @@ type ApicastStagingSpec struct {
// CustomPolicies specifies an array of defined custome policies to be loaded
// +optional
CustomPolicies []CustomPolicySpec `json:"customPolicies,omitempty"`
// OpenTracing contains the OpenTracing integration configuration
// with APIcast in the staging environment.
// +optional
OpenTracing *APIcastOpenTracingSpec `json:"openTracing,omitempty"`
}

type BackendSpec struct {
Expand Down Expand Up @@ -533,6 +542,22 @@ type PersistentVolumeClaimResources struct {
Requests resource.Quantity `json:"requests"` // Should this be a string or a resoure.Quantity? it seems it is serialized as a string
}

type APIcastOpenTracingSpec struct {
// Enabled controls whether OpenTracing integration with APIcast is enabled.
// By default it is not enabled.
// +optional
Enabled *bool `json:"enabled,omitempty"`
// +optional
// TracingLibrary controls which OpenTracing library is loaded. At the moment
// the only supported tracer is `jaeger`. If not set, `jaeger` will be used.
TracingLibrary *string `json:"tracingLibrary,omitempty"`
// TracingConfig contains a secret reference the OpenTracing configuration.
// Each supported tracing library provides a default configuration file
// that is used if TracingConfig is not specified.
// +optional
TracingConfigSecretRef *v1.LocalObjectReference `json:"tracingConfigRef,omitempty"`
}

// SetDefaults sets the default values for the APIManager spec and returns true if the spec was changed
func (apimanager *APIManager) SetDefaults() (bool, error) {
var err error
Expand Down Expand Up @@ -867,6 +892,20 @@ func (apimanager *APIManager) IsPrometheusRulesEnabled() bool {
(apimanager.Spec.Monitoring.EnablePrometheusRules == nil || *apimanager.Spec.Monitoring.EnablePrometheusRules))
}

func (apimanager *APIManager) IsAPIcastProductionOpenTracingEnabled() bool {
return apimanager.Spec.Apicast != nil && apimanager.Spec.Apicast.ProductionSpec != nil &&
apimanager.Spec.Apicast.ProductionSpec.OpenTracing != nil &&
apimanager.Spec.Apicast.ProductionSpec.OpenTracing.Enabled != nil &&
*apimanager.Spec.Apicast.ProductionSpec.OpenTracing.Enabled
}

func (apimanager *APIManager) IsAPIcastStagingOpenTracingEnabled() bool {
return apimanager.Spec.Apicast != nil && apimanager.Spec.Apicast.StagingSpec != nil &&
apimanager.Spec.Apicast.StagingSpec.OpenTracing != nil &&
apimanager.Spec.Apicast.StagingSpec.OpenTracing.Enabled != nil &&
*apimanager.Spec.Apicast.StagingSpec.OpenTracing.Enabled
}

func (apimanager *APIManager) Validate() field.ErrorList {
fieldErrors := field.ErrorList{}

Expand All @@ -877,6 +916,7 @@ func (apimanager *APIManager) Validate() field.ErrorList {

if apimanager.Spec.Apicast.ProductionSpec != nil {
prodSpecFldPath := apicastFldPath.Child("productionSpec")

customPoliciesFldPath := prodSpecFldPath.Child("customPolicies")
duplicateMap := make(map[string]int)
for idx, customPolicySpec := range apimanager.Spec.Apicast.ProductionSpec.CustomPolicies {
Expand All @@ -896,6 +936,28 @@ func (apimanager *APIManager) Validate() field.ErrorList {
}
duplicateMap[customPolicySpec.VersionName()] = 0
}

if apimanager.IsAPIcastProductionOpenTracingEnabled() {
openTracingConfigSpec := apimanager.Spec.Apicast.ProductionSpec.OpenTracing
if openTracingConfigSpec.TracingConfigSecretRef != nil {
if openTracingConfigSpec.TracingConfigSecretRef.Name == "" {
apicastProductioOpenTracingFldPath := prodSpecFldPath.Child("openTracing")
customTracingConfigFldPath := apicastProductioOpenTracingFldPath.Child("tracingConfigSecretRef")
fieldErrors = append(fieldErrors, field.Invalid(customTracingConfigFldPath, apimanager.Spec.Apicast.ProductionSpec.OpenTracing, "custom tracing library secret name is empty"))
}
}

// For now only "jaeger" is accepted" as the tracing library
if openTracingConfigSpec.TracingLibrary != nil && *openTracingConfigSpec.TracingLibrary != component.APIcastDefaultTracingLibrary {
tracingLibraryFldPath := field.NewPath("spec").
Child("apicast").
Child("productionSpec").
Child("openTracing").
Child("tracingLibrary")
fieldErrors = append(fieldErrors, field.Invalid(tracingLibraryFldPath, openTracingConfigSpec, "invalid tracing library specified"))
}
}

}

if apimanager.Spec.Apicast.StagingSpec != nil {
Expand All @@ -920,6 +982,26 @@ func (apimanager *APIManager) Validate() field.ErrorList {
}
duplicateMap[customPolicySpec.VersionName()] = 0
}

if apimanager.IsAPIcastStagingOpenTracingEnabled() {
openTracingConfigSpec := apimanager.Spec.Apicast.StagingSpec.OpenTracing
if openTracingConfigSpec.TracingConfigSecretRef != nil {
if openTracingConfigSpec.TracingConfigSecretRef.Name == "" {
apicastStagingOpenTracingFldPath := stagingSpecFldPath.Child("openTracing")
customTracingConfigFldPath := apicastStagingOpenTracingFldPath.Child("tracingConfigSecretRef")
fieldErrors = append(fieldErrors, field.Invalid(customTracingConfigFldPath, openTracingConfigSpec, "custom tracing library secret name is empty"))
}
}
// For now only "jaeger" is accepted" as the tracing library
if openTracingConfigSpec.TracingLibrary != nil && *openTracingConfigSpec.TracingLibrary != component.APIcastDefaultTracingLibrary {
tracingLibraryFldPath := field.NewPath("spec").
Child("apicast").
Child("stagingSpec").
Child("openTracing").
Child("tracingLibrary")
fieldErrors = append(fieldErrors, field.Invalid(tracingLibraryFldPath, openTracingConfigSpec, "invalid tracing library specified"))
}
}
}

}
Expand Down
40 changes: 40 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

34 changes: 34 additions & 0 deletions bundle/manifests/apps.3scale.net_apimanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,23 @@ spec:
- alert
- emerg
type: string
openTracing:
description: OpenTracing contains the OpenTracing integration configuration with APIcast in the production environment.
properties:
enabled:
description: Enabled controls whether OpenTracing integration with APIcast is enabled. By default it is not enabled.
type: boolean
tracingConfigRef:
description: TracingConfig contains a secret reference the OpenTracing configuration. Each supported tracing library provides a default configuration file that is used if TracingConfig is not specified.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
tracingLibrary:
description: TracingLibrary controls which OpenTracing library is loaded. At the moment the only supported tracer is `jaeger`. If not set, `jaeger` will be used.
type: string
type: object
replicas:
format: int64
type: integer
Expand Down Expand Up @@ -852,6 +869,23 @@ spec:
- alert
- emerg
type: string
openTracing:
description: OpenTracing contains the OpenTracing integration configuration with APIcast in the staging environment.
properties:
enabled:
description: Enabled controls whether OpenTracing integration with APIcast is enabled. By default it is not enabled.
type: boolean
tracingConfigRef:
description: TracingConfig contains a secret reference the OpenTracing configuration. Each supported tracing library provides a default configuration file that is used if TracingConfig is not specified.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
tracingLibrary:
description: TracingLibrary controls which OpenTracing library is loaded. At the moment the only supported tracer is `jaeger`. If not set, `jaeger` will be used.
type: string
type: object
replicas:
format: int64
type: integer
Expand Down
52 changes: 52 additions & 0 deletions config/crd/bases/apps.3scale.net_apimanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,32 @@ spec:
- alert
- emerg
type: string
openTracing:
description: OpenTracing contains the OpenTracing integration
configuration with APIcast in the production environment.
properties:
enabled:
description: Enabled controls whether OpenTracing integration
with APIcast is enabled. By default it is not enabled.
type: boolean
tracingConfigRef:
description: TracingConfig contains a secret reference
the OpenTracing configuration. Each supported tracing
library provides a default configuration file that is
used if TracingConfig is not specified.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
type: object
tracingLibrary:
description: TracingLibrary controls which OpenTracing
library is loaded. At the moment the only supported
tracer is `jaeger`. If not set, `jaeger` will be used.
type: string
type: object
replicas:
format: int64
type: integer
Expand Down Expand Up @@ -1493,6 +1519,32 @@ spec:
- alert
- emerg
type: string
openTracing:
description: OpenTracing contains the OpenTracing integration
configuration with APIcast in the staging environment.
properties:
enabled:
description: Enabled controls whether OpenTracing integration
with APIcast is enabled. By default it is not enabled.
type: boolean
tracingConfigRef:
description: TracingConfig contains a secret reference
the OpenTracing configuration. Each supported tracing
library provides a default configuration file that is
used if TracingConfig is not specified.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
type: object
tracingLibrary:
description: TracingLibrary controls which OpenTracing
library is loaded. At the moment the only supported
tracer is `jaeger`. If not set, `jaeger` will be used.
type: string
type: object
replicas:
format: int64
type: integer
Expand Down
24 changes: 24 additions & 0 deletions doc/apimanager-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Generated using [github-markdown-toc](https://github.com/ekalinin/github-markdow
| Workers | `workers` | integer | No | Automatically computed. Check [apicast doc](https://github.com/3scale/APIcast/blob/master/doc/parameters.md#apicast_workers) for further info. | Defines the number of worker processes |
| LogLevel | `logLevel` | string | No | N/A | Log level for the OpenResty logs (see [docs](https://github.com/3scale/APIcast/blob/master/doc/parameters.md#apicast_log_level)) |
| CustomPolicies | `customPolicies` | [][CustomPolicySpec](#CustomPolicySpec) | No | N/A | List of custom policies |
| OpenTracing | `openTracing` | [OpenTracingSpec](#OpenTracingSpec) | No | N/A | contains the OpenTracing integration configuration |

### ApicastStagingSpec

Expand All @@ -119,6 +120,7 @@ Generated using [github-markdown-toc](https://github.com/ekalinin/github-markdow
| Resources | `resources` | [v1.ResourceRequirements](https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#resourcerequirements-v1-core) | No | `nil` | Resources describes the compute resource requirements. Takes precedence over `spec.resourceRequirementsEnabled` with replace behavior |
| LogLevel | `logLevel` | string | No | N/A | Log level for the OpenResty logs (see [docs](https://github.com/3scale/APIcast/blob/master/doc/parameters.md#apicast_log_level)) |
| CustomPolicies | `customPolicies` | [][CustomPolicySpec](#CustomPolicySpec) | No | N/A | List of custom policies |
| OpenTracing | `openTracing` | [APIcastOpenTracingSpec](#APIcastOpenTracingSpec) | No | N/A | contains the OpenTracing integration configuration |

### CustomPolicySpec

Expand All @@ -139,6 +141,28 @@ Some examples are available [here](/doc/adding-custom-policies.md)
| `init.lua` | Custom policy lua code entry point |
| `apicast-policy.json` | Custom policy metadata |

### APIcastOpenTracingSpec
| **Field** | **json/yaml field** | **Type** | **Required** | **Default value** | **Description** |
| --- | --- | --- | --- | --- | --- |
| Enabled | `enabled` | bool | No | `false` | Controls whether OpenTracing integration with APIcast is enabled. By default it is not enabled |
| TracingLibrary | `tracingLibrary` | string | No | `jaeger` | Controls which OpenTracing library is loaded. At the moment the supported values are: `jaeger`. If not set, `jaeger` will be used |
| | TracingConfigRef | `tracingConfigRef` | LocalObjectReference | No | tracing library-specific default | Secret reference with the tracing library-specific configuration. Each supported tracing library provides a default configuration file which is used if `tracingConfigRef` is not specified. See [APIcastTracingConfigSecret](#APIcastTracingConfigSecret) for more information. |

### APIcastTracingConfigSecret

| **Field** | **Description** |
| --- | --- |
| `config` | Tracing library-specific configuration |

*NOTE*: Once apicast has been deployed, the content of the secret should not be updated externally.
If the content of the secret is updated externally, after apicast has been deployed, the container can automatically see the changes.
However, apicast has the environment already loaded and it does not change the behavior.

If the custom environment content needs to be changed, there are two options:

* [**recommended way**] Create another secret with a different name and update the APIcast custom resource field `spec.apicast.<apicast-environment>.openTracing.tracingConfigRef.name`. The operator will trigger a rolling update loading the new custom environment content.
* Update the existing secret content and redeploy apicast turning `spec.replicas` to 0 and then back to the previous value.

### BackendSpec

| **Field** | **json/yaml field**| **Type** | **Required** | **Default value** | **Description** |
Expand Down
Loading

0 comments on commit aefaae3

Please sign in to comment.