Updates rlpreader to demonstrate deterministic routing
@@ -19,8 +19,10 @@ import (
)
var (
- target = flag.String("target", "localhost:3457", "the host:port of the target rlp")
+ target = flag.String("target", "localhost:8082", "the host:port of the target rlp")
appID = flag.String("app-id", "", "app-id to stream data")
+ shardID = flag.String("shard-id", "", "sets the shard_id field")
+ deterministicName = flag.String("deterministic-name", "", "sets the deterministic_name field")
certFile = flag.String("cert", "", "cert to use to connect to rlp")
keyFile = flag.String("key", "", "key to use to connect to rlp")
caFile = flag.String("ca", "", "ca cert to use to connect to rlp")
@@ -28,6 +30,8 @@ var (
preferredTags = flag.Bool("preferred-tags", false, "use preferred tags")
counterName = flag.String("counter", "", "select a counter with the given name")
gaugeNames = flag.String("gauge", "", "select a gauge with the given comma separated names (must contain all the names)")
+
+ metricNames = flag.Bool("metric-names", false, "this is really only useful while trying out deterministic routing. It only grabs counters and gauges and only prints their names")
)
func main() {
@@ -82,8 +86,24 @@ func main() {
})
}
+ if *metricNames {
+ selectors = []*loggregator_v2.Selector{
+ {
+ Message: &loggregator_v2.Selector_Counter{
+ Counter: &loggregator_v2.CounterSelector{},
+ },
+ },
+ {
+ Message: &loggregator_v2.Selector_Gauge{
+ Gauge: &loggregator_v2.GaugeSelector{},
+ },
+ },
+ }
+ }
+
receiver, err := client.BatchedReceiver(context.TODO(), &loggregator_v2.EgressBatchRequest{
- ShardId: buildShardID(),
+ ShardId: buildShardID(*shardID),
+ DeterministicName: *deterministicName,
UsePreferredTags: *preferredTags,
Selectors: selectors,
})
@@ -98,16 +118,35 @@ func main() {
return
}
for _, e := range batch.Batch {
+ if *metricNames {
+ if e.GetCounter() != nil {
+ fmt.Printf("%s\n", e.GetCounter().GetName())
+ continue
+ }
+
+ var names []string
+ for name := range e.GetGauge().GetMetrics() {
+ names = append(names, name)
+ }
+
+ fmt.Printf("%s\n", strings.Join(names, ", "))
+ continue
+ }
+
fmt.Printf("%+v\n", e)
}
time.Sleep(*delay)
}
}
-func buildShardID() string {
+func buildShardID(shardID string) string {
+ if shardID == "" {
return "rlp-reader-" + randString()
}
+ return shardID
+}
+
func randString() string {
b := make([]byte, 20)
_, err := rand.Read(b)
