Skip to content

Instantly share code, notes, and snippets.

@pierDipi
Last active May 31, 2021 21:59
Show Gist options
  • Save pierDipi/f2d6775c68d4c6b44b6fbfb6e73050e3 to your computer and use it in GitHub Desktop.
Save pierDipi/f2d6775c68d4c6b44b6fbfb6e73050e3 to your computer and use it in GitHub Desktop.
Contract size
package main
import (
"fmt"
"log"
"math"
"strings"
"github.com/google/uuid"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"knative.dev/eventing-kafka-broker/control-plane/pkg/contract"
)
func main() {
namespace := strings.Repeat("a", 63)
name := strings.Repeat("a", 63)
systemNamespace := "knative-eventing"
systemSvcName := "kafka-broker-ingress"
url := fmt.Sprintf("%s.%s.svc.cluster.local/%s/%s", systemSvcName, systemNamespace, namespace, name)
egress := &contract.Egress{
ConsumerGroup: uuid.New().String(),
Destination: url,
ReplyStrategy: &contract.Egress_ReplyToOriginalTopic{ReplyToOriginalTopic: &contract.Empty{}},
Filter: &contract.Filter{
Attributes: map[string]string{
"type": strings.Repeat("a", 50),
"source": strings.Repeat("a", 50),
"subject": strings.Repeat("a", 50),
},
},
Uid: uuid.New().String(),
EgressConfig: &contract.EgressConfig{
DeadLetter: url,
Retry: math.MaxUint32,
BackoffPolicy: contract.BackoffPolicy_Exponential,
BackoffDelay: math.MaxUint64,
},
DeliveryOrder: contract.DeliveryOrder_UNORDERED,
}
n := 1500
var egresses []*contract.Egress
for i := 0; i < n; i++ {
egresses = append(egresses, proto.Clone(egress).(*contract.Egress))
}
c := &contract.Contract{
Generation: 0,
Resources: []*contract.Resource{
{
Uid: uuid.New().String(),
Topics: []string{},
BootstrapServers: "",
Ingress: &contract.Ingress{
ContentMode: contract.ContentMode_BINARY,
IngressType: &contract.Ingress_Path{
Path: fmt.Sprintf("%s/%s", namespace, name),
},
},
EgressConfig: &contract.EgressConfig{
DeadLetter: url,
Retry: math.MaxUint32,
BackoffPolicy: contract.BackoffPolicy_Exponential,
BackoffDelay: math.MaxUint64,
},
Egresses: egresses,
Auth: &contract.Resource_AuthSecret{
AuthSecret: &contract.Reference{
Uuid: uuid.New().String(),
Namespace: namespace,
Name: name,
Version: uuid.New().String(),
},
},
},
},
}
bJSON, err := protojson.Marshal(c)
if err != nil {
panic(err)
}
bProto, err := proto.Marshal(c)
if err != nil {
panic(err)
}
log.Println("n", n, "json", len(bJSON), "proto", len(bProto))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment