Skip to content

Commit

Permalink
Add support for grpc-plugin storage (#1517)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Jul 26, 2021
1 parent 25e9291 commit 4823277
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 8 deletions.
5 changes: 5 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10677,6 +10677,11 @@ spec:
type: array
x-kubernetes-list-type: atomic
type: object
grpcPlugin:
properties:
image:
type: string
type: object
options:
type: object
x-kubernetes-preserve-unknown-fields: true
Expand Down
28 changes: 28 additions & 0 deletions examples/with-grpc-storage-plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This example shows how to use Jaeger's Clickhouse grpc-plugin https://github.com/pavolloffay/jaeger-clickhouse
# Before deploying Jaeger, create Clickhouse instance via Clickhouse operator and jaeger-clickhouse config map.
# kubectl create configmap jaeger-clickhouse --from-file config.yaml
# Content of config.yaml:
# address: tcp://clickhouse-simple-01:9000
# username: clickhouse_operator
# password: clickhouse_operator_password
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: clickhouse-grpc-plugin
spec:
storage:
type: grpc-plugin
grpcPlugin:
image: ghcr.io/pavolloffay/jaeger-clickhouse:0.4.1
options:
grpc-storage-plugin:
binary: /plugin/jaeger-clickhouse
configuration-file: /plugin-config/config.yaml
log-level: debug
volumeMounts:
- name: plugin-config
mountPath: /plugin-config
volumes:
- name: plugin-config
configMap:
name: jaeger-clickhouse
19 changes: 19 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ const (
// JaegerBadgerStorage indicates that the Jaeger storage type is badger
// +k8s:openapi-gen=true
JaegerBadgerStorage JaegerStorageType = "badger"

// JaegerGRPCPluginStorage indicates that the Jaeger storage type is grpc-plugin
// +k8s:openapi-gen=true
JaegerGRPCPluginStorage JaegerStorageType = "grpc-plugin"
)

// ValidStorageTypes returns the list of valid storage types
Expand All @@ -114,6 +118,7 @@ func ValidStorageTypes() []JaegerStorageType {
JaegerESStorage,
JaegerKafkaStorage,
JaegerBadgerStorage,
JaegerGRPCPluginStorage,
}
}

Expand All @@ -122,6 +127,9 @@ func (storageType JaegerStorageType) OptionsPrefix() string {
if storageType == JaegerESStorage {
return "es"
}
if storageType == JaegerGRPCPluginStorage {
return "grpc-storage-plugin"
}
return string(storageType)
}

Expand Down Expand Up @@ -522,6 +530,9 @@ type JaegerStorageSpec struct {

// +optional
Elasticsearch ElasticsearchSpec `json:"elasticsearch,omitempty"`

// +optional
GRPCPlugin GRPCPluginSpec `json:"grpcPlugin,omitempty"`
}

// ElasticsearchSpec represents the ES configuration options that we pass down to the Elasticsearch operator
Expand Down Expand Up @@ -593,6 +604,14 @@ type JaegerCassandraCreateSchemaSpec struct {
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
}

// GRPCPluginSpec represents the grpc-plugin configuration options.
// +k8s:openapi-gen=true
type GRPCPluginSpec struct {
// This image is used as an init-container to copy plugin binary into /plugin directory.
// +optional
Image string `json:"image,omitempty"`
}

// JaegerDependenciesSpec defined options for running spark-dependencies.
// +k8s:openapi-gen=true
type JaegerDependenciesSpec struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ func TestValidTypes(t *testing.T) {
JaegerESStorage,
JaegerKafkaStorage,
JaegerBadgerStorage,
JaegerGRPCPluginStorage,
})
}
17 changes: 17 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

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

28 changes: 27 additions & 1 deletion pkg/apis/jaegertracing/v1/zz_generated.openapi.go

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

4 changes: 4 additions & 0 deletions pkg/deployment/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sort"
"strconv"

"github.com/jaegertracing/jaeger-operator/pkg/storage"

"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,6 +68,7 @@ func (a *AllInOne) Get() *appsv1.Deployment {
tls.Update(a.jaeger, commonSpec, &options)
ca.Update(a.jaeger, commonSpec)
ca.AddServiceCA(a.jaeger, commonSpec)
storage.UpdateGRPCPlugin(a.jaeger, commonSpec)

// Enable tls by default for openshift platform
// even though the agent is in the same process as the collector, they communicate via gRPC, and the collector has TLS enabled,
Expand Down Expand Up @@ -223,6 +226,7 @@ func (a *AllInOne) Get() *appsv1.Deployment {
Tolerations: commonSpec.Tolerations,
SecurityContext: commonSpec.SecurityContext,
EnableServiceLinks: &falseVar,
InitContainers: storage.GetGRPCPluginInitContainers(a.jaeger, commonSpec),
},
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/deployment/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -397,6 +398,38 @@ func TestAllInOneEmptyStrategyType(t *testing.T) {
assert.Equal(t, appsv1.RecreateDeploymentStrategyType, dep.Spec.Strategy.Type)
}

func TestAllInOneGRPCPlugin(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAllInOneGRPCPlugin"})
jaeger.Spec.Storage.Type = v1.JaegerGRPCPluginStorage
jaeger.Spec.Storage.GRPCPlugin.Image = "plugin/plugin:1.0"
jaeger.Spec.Storage.Options = v1.NewOptions(map[string]interface{}{
"grpc-storage-plugin.binary": "/plugin/plugin",
})

allinone := NewAllInOne(jaeger)
dep := allinone.Get()

assert.Equal(t, []corev1.Container{
{
Image: "plugin/plugin:1.0",
Name: "install-plugin",
VolumeMounts: []corev1.VolumeMount{
{
Name: "testallinonegrpcplugin-sampling-configuration-volume",
MountPath: "/etc/jaeger/sampling",
ReadOnly: true,
},
{
Name: "plugin-volume",
MountPath: "/plugin",
},
},
},
}, dep.Spec.Template.Spec.InitContainers)
require.Equal(t, 1, len(dep.Spec.Template.Spec.Containers))
assert.Equal(t, []string{"--grpc-storage-plugin.binary=/plugin/plugin", "--sampling.strategies-file=/etc/jaeger/sampling/sampling.json"}, dep.Spec.Template.Spec.Containers[0].Args)
}

func getEnvVarByName(vars []corev1.EnvVar, name string) corev1.EnvVar {
envVar := corev1.EnvVar{}
for _, v := range vars {
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/jaegertracing/jaeger-operator/pkg/config/sampling"
"github.com/jaegertracing/jaeger-operator/pkg/config/tls"
"github.com/jaegertracing/jaeger-operator/pkg/service"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)

Expand Down Expand Up @@ -79,6 +80,7 @@ func (c *Collector) Get() *appsv1.Deployment {
tls.Update(c.jaeger, commonSpec, &options)
ca.Update(c.jaeger, commonSpec)
}
storage.UpdateGRPCPlugin(c.jaeger, commonSpec)

// ensure we have a consistent order of the arguments
// see https://github.com/jaegertracing/jaeger-operator/issues/334
Expand Down Expand Up @@ -194,6 +196,7 @@ func (c *Collector) Get() *appsv1.Deployment {
Tolerations: commonSpec.Tolerations,
SecurityContext: commonSpec.SecurityContext,
EnableServiceLinks: &falseVar,
InitContainers: storage.GetGRPCPluginInitContainers(c.jaeger, commonSpec),
},
},
},
Expand Down
36 changes: 34 additions & 2 deletions pkg/deployment/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"strings"
"testing"

"github.com/jaegertracing/jaeger-operator/pkg/version"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -18,6 +17,7 @@ import (

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/util"
"github.com/jaegertracing/jaeger-operator/pkg/version"
)

func init() {
Expand Down Expand Up @@ -596,6 +596,38 @@ func TestCollectorEmptyStrategyType(t *testing.T) {
assert.Equal(t, appsv1.RecreateDeploymentStrategyType, dep.Spec.Strategy.Type)
}

func TestCollectorGRPCPlugin(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestCollectorGRPCPlugin"})
jaeger.Spec.Storage.Type = v1.JaegerGRPCPluginStorage
jaeger.Spec.Storage.GRPCPlugin.Image = "plugin/plugin:1.0"
jaeger.Spec.Storage.Options = v1.NewOptions(map[string]interface{}{
"grpc-storage-plugin.binary": "/plugin/plugin",
})

collector := Collector{jaeger: jaeger}
dep := collector.Get()

assert.Equal(t, []corev1.Container{
{
Image: "plugin/plugin:1.0",
Name: "install-plugin",
VolumeMounts: []corev1.VolumeMount{
{
Name: "testcollectorgrpcplugin-sampling-configuration-volume",
MountPath: "/etc/jaeger/sampling",
ReadOnly: true,
},
{
Name: "plugin-volume",
MountPath: "/plugin",
},
},
},
}, dep.Spec.Template.Spec.InitContainers)
require.Equal(t, 1, len(dep.Spec.Template.Spec.Containers))
assert.Equal(t, []string{"--grpc-storage-plugin.binary=/plugin/plugin", "--sampling.strategies-file=/etc/jaeger/sampling/sampling.json"}, dep.Spec.Template.Spec.Containers[0].Args)
}

func hasVolume(name string, volumes []corev1.Volume) bool {
for _, v := range volumes {
if v.Name == name {
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/jaegertracing/jaeger-operator/pkg/account"
v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/config/ca"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)

Expand Down Expand Up @@ -75,6 +76,7 @@ func (i *Ingester) Get() *appsv1.Deployment {
i.jaeger.Spec.Storage.Options.Filter(i.jaeger.Spec.Storage.Type.OptionsPrefix()))

ca.Update(i.jaeger, commonSpec)
storage.UpdateGRPCPlugin(i.jaeger, commonSpec)

// ensure we have a consistent order of the arguments
// see https://github.com/jaegertracing/jaeger-operator/issues/334
Expand Down Expand Up @@ -161,6 +163,7 @@ func (i *Ingester) Get() *appsv1.Deployment {
Tolerations: commonSpec.Tolerations,
SecurityContext: commonSpec.SecurityContext,
EnableServiceLinks: &falseVar,
InitContainers: storage.GetGRPCPluginInitContainers(i.jaeger, commonSpec),
},
},
},
Expand Down
Loading

0 comments on commit 4823277

Please sign in to comment.