Skip to content

Commit

Permalink
Fix query ingress when using streaming strategy (jaegertracing#2120)
Browse files Browse the repository at this point in the history
* Fix query ingress when using streaming strategy

Signed-off-by: Kevin Earls <[email protected]>

* Add a new test, remove redundant tests

Signed-off-by: Kevin Earls <[email protected]>

* Remove redundant test

Signed-off-by: Kevin Earls <[email protected]>

Signed-off-by: Kevin Earls <[email protected]>
  • Loading branch information
kevinearls authored Nov 22, 2022
1 parent f3eb628 commit 2d28047
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
6 changes: 4 additions & 2 deletions pkg/ingress/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func (i *QueryIngress) Get() *networkingv1.Ingress {
func (i *QueryIngress) addRulesSpec(spec *networkingv1.IngressSpec, backend *networkingv1.IngressBackend) {
path := ""

if allInOneQueryBasePath, ok := i.jaeger.Spec.AllInOne.Options.StringMap()["query.base-path"]; ok && i.jaeger.Spec.Strategy == v1.DeploymentStrategyAllInOne {
jaegerSpec := i.jaeger.Spec
strategy := jaegerSpec.Strategy
if allInOneQueryBasePath, ok := jaegerSpec.AllInOne.Options.StringMap()["query.base-path"]; ok && strategy == v1.DeploymentStrategyAllInOne {
path = allInOneQueryBasePath
} else if queryBasePath, ok := i.jaeger.Spec.Query.Options.StringMap()["query.base-path"]; ok && i.jaeger.Spec.Strategy == v1.DeploymentStrategyProduction {
} else if queryBasePath, ok := jaegerSpec.Query.Options.StringMap()["query.base-path"]; ok && strategy == v1.DeploymentStrategyProduction || strategy == v1.DeploymentStrategyStreaming {
path = queryBasePath
}

Expand Down
77 changes: 37 additions & 40 deletions pkg/ingress/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,43 @@ func TestQueryIngressEnabled(t *testing.T) {
assert.NotNil(t, dep.Spec.DefaultBackend)
}

func TestQueryIngressAllInOneBasePath(t *testing.T) {
enabled := true
name := "TestQueryIngressAllInOneBasePath"
jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
jaeger.Spec.Ingress.Enabled = &enabled
jaeger.Spec.Strategy = v1.DeploymentStrategyAllInOne
jaeger.Spec.AllInOne.Options = v1.NewOptions(map[string]interface{}{"query.base-path": "/jaeger"})
ingress := NewQueryIngress(jaeger)

dep := ingress.Get()

assert.NotNil(t, dep)
assert.Nil(t, dep.Spec.DefaultBackend)
assert.Len(t, dep.Spec.Rules, 1)

assert.Len(t, dep.Spec.Rules[0].HTTP.Paths, 1)
assert.Equal(t, "/jaeger", dep.Spec.Rules[0].HTTP.Paths[0].Path)
assert.Empty(t, dep.Spec.Rules[0].Host)
assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend)
}

func TestQueryIngressQueryBasePath(t *testing.T) {
enabled := true
name := "TestQueryIngressQueryBasePath"
jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
jaeger.Spec.Ingress.Enabled = &enabled
jaeger.Spec.Strategy = v1.DeploymentStrategyProduction
jaeger.Spec.Query.Options = v1.NewOptions(map[string]interface{}{"query.base-path": "/jaeger"})
ingress := NewQueryIngress(jaeger)

dep := ingress.Get()

assert.NotNil(t, dep)
assert.Nil(t, dep.Spec.DefaultBackend)
assert.Len(t, dep.Spec.Rules, 1)

assert.Len(t, dep.Spec.Rules[0].HTTP.Paths, 1)
assert.Equal(t, "/jaeger", dep.Spec.Rules[0].HTTP.Paths[0].Path)
assert.Empty(t, dep.Spec.Rules[0].Host)
assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend)
func TestIngressWithPath(t *testing.T) {
type test struct {
name string
strategy v1.DeploymentStrategy
basePath string
}
allInOne := test{name: "TestQueryIngressAllInOneBasePath", strategy: v1.DeploymentStrategyAllInOne, basePath: "/jaeger"}
production := test{name: "TestQueryIngressProduction", strategy: v1.DeploymentStrategyProduction, basePath: "/jaeger-production"}
streaming := test{name: "TestQueryIngressStreaming", strategy: v1.DeploymentStrategyStreaming, basePath: "/jaeger-streaming"}

tests := []test{allInOne, production, streaming}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
enabled := true
jaeger := v1.NewJaeger(types.NamespacedName{Name: test.name})
jaeger.Spec.Ingress.Enabled = &enabled
jaeger.Spec.Strategy = test.strategy
if test.strategy == v1.DeploymentStrategyAllInOne {
jaeger.Spec.AllInOne.Options = v1.NewOptions(map[string]interface{}{"query.base-path": test.basePath})
} else {
jaeger.Spec.Query.Options = v1.NewOptions(map[string]interface{}{"query.base-path": test.basePath})
}

ingress := NewQueryIngress(jaeger)
dep := ingress.Get()

assert.NotNil(t, dep)
assert.Nil(t, dep.Spec.DefaultBackend)
assert.Len(t, dep.Spec.Rules, 1)

assert.Len(t, dep.Spec.Rules[0].HTTP.Paths, 1)
assert.Equal(t, test.basePath, dep.Spec.Rules[0].HTTP.Paths[0].Path)
assert.Empty(t, dep.Spec.Rules[0].Host)
assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend)
})
}
}

func TestQueryIngressAnnotations(t *testing.T) {
Expand Down

0 comments on commit 2d28047

Please sign in to comment.