Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke test #145

Merged
merged 7 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 86 additions & 3 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ required = [
name = "k8s.io/code-generator"
non-go = false
unused-packages = false

[[override]]
name = "github.com/pkg/errors"
version = "0.8.0"
2 changes: 1 addition & 1 deletion deploy/examples/with-cassandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ spec:
cassandra:
servers: cassandra
keyspace: jaeger_v1_datacenter3
cassandra-create-schema:
cassandraCreateSchema:
datacenter: "datacenter3"
mode: "test"
3 changes: 1 addition & 2 deletions pkg/deployment/collector_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package deployment

import (
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"testing"

"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
)
Expand Down
24 changes: 21 additions & 3 deletions test/e2e/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ func cassandraTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx)
},
Spec: v1alpha1.JaegerSpec{
Strategy: "allInOne",
AllInOne: v1alpha1.JaegerAllInOneSpec{},
Storage: v1alpha1.JaegerStorageSpec{
Type: "cassandra",
Options: v1alpha1.NewOptions(map[string]interface{}{"cassandra.servers": "cassandra.default.svc"}),
Options: v1alpha1.NewOptions(map[string]interface{}{"cassandra.servers": "cassandra.default.svc", "cassandra.keyspace": "jaeger_v1_datacenter1"}),
CassandraCreateSchema: v1alpha1.JaegerCassandraCreateSchemaSpec{
Datacenter: "datacenter1",
},
},
},
}
Expand All @@ -59,5 +61,21 @@ func cassandraTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx)
return err
}

return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "with-cassandra", 1, retryInterval, timeout)
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "with-cassandra", 1, retryInterval, timeout)
if err != nil {
return err
}

jaegerPod, err := GetPod(namespace, "with-cassandra", "jaegertracing/all-in-one", f.KubeClient)
if err != nil {
return err
}
portForw, closeChan, err := CreatePortForward(namespace, jaegerPod.Name, []string{"16686", "14268"}, f.KubeConfig)
if err != nil {
return err
}
defer portForw.Close()
defer close(closeChan)
return SmokeTest("http://localhost:16686/api/traces", "http://localhost:14268/api/traces", "foobar", retryInterval, timeout)
}

49 changes: 49 additions & 0 deletions test/e2e/port_forward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package e2e

import (
"bytes"
"fmt"
"net/http"
"net/url"
"strings"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/portforward"
"k8s.io/client-go/transport/spdy"
)

func CreatePortForward(namespace, pod string, ports []string, kConfig *rest.Config) (*portforward.PortForwarder, chan struct{}, error) {
roundTripper, upgrader, err := spdy.RoundTripperFor(kConfig)
if err != nil {
return nil, nil, err
}

path := fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/portforward", namespace, pod)
hostIP := strings.TrimLeft(kConfig.Host, "https://")
serverURL := url.URL{Scheme: "https", Path: path, Host: hostIP}

dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, &serverURL)

stopChan, readyChan := make(chan struct{}, 1), make(chan struct{}, 1)
out, errOut := new(bytes.Buffer), new(bytes.Buffer)
forwarder, err := portforward.New(dialer, ports, stopChan, readyChan, out, errOut)
if err != nil {
return nil, nil, err
}
go func() {
for range readyChan { // Kubernetes will close this channel when it has something to tell us.
}
if len(errOut.String()) != 0 {
panic(errOut.String())
} else if len(out.String()) != 0 {
fmt.Println(out.String())
}
}()
go func() {
if err := forwarder.ForwardPorts(); err != nil {
panic(err)
}
}()
<- forwarder.Ready
return forwarder, stopChan, nil
}
26 changes: 25 additions & 1 deletion test/e2e/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,29 @@ func simpleProd(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) er
return err
}

return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "simple-prod-query", 1, retryInterval, timeout)
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "simple-prod-query", 1, retryInterval, timeout)
if err != nil {
return err
}
queryPod, err := GetPod(namespace, "simple-prod-query","jaegertracing/jaeger-query", f.KubeClient)
if err != nil {
return err
}
collectorPod, err := GetPod(namespace, "simple-prod-collector","jaegertracing/jaeger-collector", f.KubeClient)
if err != nil {
return err
}
portForw, closeChan, err := CreatePortForward(namespace, queryPod.Name, []string{"16686"}, f.KubeConfig)
if err != nil {
return err
}
defer portForw.Close()
defer close(closeChan)
portForwColl, closeChanColl, err := CreatePortForward(namespace, collectorPod.Name, []string{"14268"}, f.KubeConfig)
if err != nil {
return err
}
defer portForwColl.Close()
defer close(closeChanColl)
return SmokeTest("http://localhost:16686/api/traces", "http://localhost:14268/api/traces", "foobar", retryInterval, timeout)
}
54 changes: 54 additions & 0 deletions test/e2e/smoketest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package e2e

import (
"errors"
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/uber/jaeger-client-go/config"
"k8s.io/apimachinery/pkg/util/wait"
)

func SmokeTest(apiTracesEndpoint, collectorEndpoint, serviceName string, interval, timeout time.Duration) error {
cfg := config.Configuration{
Reporter: &config.ReporterConfig{CollectorEndpoint: collectorEndpoint},
Sampler: &config.SamplerConfig{Type:"const", Param:1},
ServiceName: serviceName,
}
tracer, closer, err := cfg.NewTracer()
if err != nil {
return err
}

tStr := time.Now().Format(time.RFC3339Nano)
tracer.StartSpan("SmokeTest").
SetTag("time-RFC3339Nano", tStr).
Finish()
closer.Close()

return wait.Poll(interval, timeout, func() (done bool, err error) {
c := http.Client{Timeout: time.Second}
req, err := http.NewRequest(http.MethodGet, apiTracesEndpoint+ "?service=" + serviceName, nil)
if err != nil {
return false, err
}
resp, err := c.Do(req)
if err != nil {
return false, nil
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)

if !strings.Contains(bodyString, "errors\":null") {
return false, errors.New("query service returns errors")
}
if !strings.Contains(bodyString, tStr) {
return false, errors.New("query service does not return spans")
}
return true, nil
})
}
Loading