From f0205f61d3745fe67e527054b4a85b0f3b523eb7 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Thu, 4 Jun 2020 12:11:40 +0200 Subject: [PATCH] Performance image code porting to sdk-go v2 Signed-off-by: Francesco Guardiani --- test/performance/infra/receiver/id_extractor.go | 2 +- test/performance/infra/receiver/receiver.go | 6 ++---- test/performance/infra/receiver/type_extractor.go | 2 +- .../infra/sender/http_load_generator.go | 14 ++++++-------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/test/performance/infra/receiver/id_extractor.go b/test/performance/infra/receiver/id_extractor.go index 581d22a4f3f..7c19c2b8def 100644 --- a/test/performance/infra/receiver/id_extractor.go +++ b/test/performance/infra/receiver/id_extractor.go @@ -16,7 +16,7 @@ limitations under the License. package receiver -import cloudevents "github.com/cloudevents/sdk-go" +import cloudevents "github.com/cloudevents/sdk-go/v2" // IdExtractor is used by the receiver to establish the id of the received event type IdExtractor func(event cloudevents.Event) string diff --git a/test/performance/infra/receiver/receiver.go b/test/performance/infra/receiver/receiver.go index 8e4330e348b..39b3038c060 100644 --- a/test/performance/infra/receiver/receiver.go +++ b/test/performance/infra/receiver/receiver.go @@ -21,11 +21,10 @@ import ( "fmt" "log" "net" - "net/http" "runtime" "time" - cloudevents "github.com/cloudevents/sdk-go" + cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/timestamp" @@ -159,7 +158,7 @@ func (r *Receiver) startCloudEventsReceiver(ctx context.Context) error { } // processReceiveEvent processes the event received by the CloudEvents receiver. -func (r *Receiver) processReceiveEvent(event cloudevents.Event, resp *cloudevents.EventResponse) { +func (r *Receiver) processReceiveEvent(event cloudevents.Event) { t := r.typeExtractor(event) switch t { case common.MeasureEventType: @@ -173,7 +172,6 @@ func (r *Receiver) processReceiveEvent(event cloudevents.Event, resp *cloudevent r.endCh <- struct{}{} }) } - resp.Status = http.StatusAccepted } // waitForPortAvailable waits until the given TCP port is available. diff --git a/test/performance/infra/receiver/type_extractor.go b/test/performance/infra/receiver/type_extractor.go index 30baad27a74..b601aa1738b 100644 --- a/test/performance/infra/receiver/type_extractor.go +++ b/test/performance/infra/receiver/type_extractor.go @@ -16,7 +16,7 @@ limitations under the License. package receiver -import cloudevents "github.com/cloudevents/sdk-go" +import cloudevents "github.com/cloudevents/sdk-go/v2" // TypeExtractor is used by the receiver to establish the type of the received event type TypeExtractor func(event cloudevents.Event) string diff --git a/test/performance/infra/sender/http_load_generator.go b/test/performance/infra/sender/http_load_generator.go index c95b22d1465..c45999c68fd 100644 --- a/test/performance/infra/sender/http_load_generator.go +++ b/test/performance/infra/sender/http_load_generator.go @@ -24,8 +24,7 @@ import ( "net/http" "time" - cloudevents "github.com/cloudevents/sdk-go" - "github.com/cloudevents/sdk-go/pkg/cloudevents/client" + cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/golang/protobuf/ptypes" "github.com/google/uuid" "github.com/rogpeppe/fastuuid" @@ -117,7 +116,7 @@ type HttpLoadGenerator struct { warmupAttacker *vegeta.Attacker paceAttacker *vegeta.Attacker - ceClient client.Client + ceClient cloudevents.Client } func NewHttpLoadGeneratorFactory(sinkUrl string, minWorkers uint64) LoadGeneratorFactory { @@ -186,9 +185,8 @@ func vegetaAttackerTransport() *http.Transport { } } -func newCloudEventsClient(sinkUrl string) (client.Client, error) { - t, err := cloudevents.NewHTTPTransport( - cloudevents.WithBinaryEncoding(), +func newCloudEventsClient(sinkUrl string) (cloudevents.Client, error) { + t, err := cloudevents.NewHTTP( cloudevents.WithTarget(sinkUrl), ) if err != nil { @@ -219,7 +217,7 @@ func (h HttpLoadGenerator) SendGCEvent() { event.SetType(common.GCEventType) event.SetSource(h.eventSource) - _, _, _ = h.ceClient.Send(context.TODO(), event) + _ = h.ceClient.Send(context.TODO(), event) } func (h HttpLoadGenerator) SendEndEvent() { @@ -229,5 +227,5 @@ func (h HttpLoadGenerator) SendEndEvent() { event.SetType(common.EndEventType) event.SetSource(h.eventSource) - _, _, _ = h.ceClient.Send(context.TODO(), event) + _ = h.ceClient.Send(context.TODO(), event) }