You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/11/28 07:19:52 UTC

[GitHub] [skywalking-satellite] mrproliu commented on a diff in pull request #123: Adding kafka forwarder plugins

mrproliu commented on code in PR #123:
URL: https://github.com/apache/skywalking-satellite/pull/123#discussion_r1033184782


##########
plugins/forwarder/forwarder_repository.go:
##########
@@ -56,14 +58,16 @@ func RegisterForwarderPlugins() {
 		new(grpc_nativecds.Forwarder),
 		new(grpc_nativeevent.Forwarder),
 		new(grpc_nativejvm.Forwarder),
-		new(grpc_nativeclr.Forwarder),
-		new(grpc_nativeprocess.Forwarder),
-		new(grpc_nativeebpfprofiling.Forwarder),

Review Comment:
   Why did you need to delete the existing forwarders? 



##########
plugins/forwarder/kafka/nativemanagement/forwarder.go:
##########
@@ -0,0 +1,110 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package nativemanagement
+
+import (
+	"fmt"
+	"reflect"
+
+	"github.com/Shopify/sarama"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/satellite/event"
+	"google.golang.org/protobuf/proto"
+	management "skywalking.apache.org/repo/goapi/collect/management/v3"
+
+	v1 "skywalking.apache.org/repo/goapi/satellite/data/v1"
+)
+
+const (
+	Name     = "nativemanagement-kafka-forwarder"
+	ShowName = "Native Management Kafka Forwarder"
+)
+
+// empty struct for set
+type void struct{}
+
+var empty void

Review Comment:
   I think these fields and struct are not used, why do you declare in there? 



##########
plugins/forwarder/kafka/nativemeter/forwarder.go:
##########
@@ -0,0 +1,115 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package nativemeter
+
+import (
+	"fmt"
+	"reflect"
+	"time"
+
+	"github.com/Shopify/sarama"
+	"google.golang.org/protobuf/proto"
+	"k8s.io/apimachinery/pkg/util/cache"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/satellite/event"
+
+	v3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
+	v1 "skywalking.apache.org/repo/goapi/satellite/data/v1"
+)
+
+const (
+	Name     = "nativemeter-kafka-forwarder"
+	ShowName = "Native Meter Kafka Forwarder"
+)
+
+type Forwarder struct {
+	config.CommonFields
+	RoutingRuleLRUCacheSize int `mapstructure:"routing_rule_lru_cache_size"`
+	// The TTL of the LRU cache size for hosting routine rules of service instance.
+	RoutingRuleLRUCacheTTL int    `mapstructure:"routing_rule_lru_cache_ttl"`
+	Topic                  string `mapstructure:"topic"` // The forwarder topic.
+	producer               sarama.SyncProducer
+	meterClient            v3.MeterReportServiceClient
+	upstreamCache          *cache.LRUExpireCache
+	upstreamCacheExpire    time.Duration
+}
+
+func (f *Forwarder) Name() string {
+	return Name
+}
+
+func (f *Forwarder) ShowName() string {
+	return ShowName
+}
+
+func (f *Forwarder) Description() string {
+	return "This is a synchronization Kafka forwarder with the SkyWalking native meter protocol."
+}
+
+func (f *Forwarder) DefaultConfig() string {
+	return `
+# The remote topic. 
+topic: "skywalking-meters"
+`
+}
+
+func (f *Forwarder) Prepare(connection interface{}) error {
+	client, ok := connection.(sarama.Client)
+	if !ok {
+		return fmt.Errorf("the %s is only accepet the kafka client, but receive a %s",
+			f.Name(), reflect.TypeOf(connection).String())
+	}
+	producer, err := sarama.NewSyncProducerFromClient(client)
+	f.upstreamCache = cache.NewLRUExpireCache(f.RoutingRuleLRUCacheSize)
+	f.upstreamCacheExpire = time.Second * time.Duration(f.RoutingRuleLRUCacheTTL)
+
+	if err != nil {
+		return err
+	}
+	f.producer = producer
+	return nil
+}
+
+func (f *Forwarder) Forward(batch event.BatchEvents) error {
+	var message []*sarama.ProducerMessage
+	for _, e := range batch {
+		data := e.GetData().(*v1.SniffData_Meter)
+		rawdata, ok := proto.Marshal(data.Meter)
+		if ok != nil {
+			return ok
+		}
+		message = append(message, &sarama.ProducerMessage{
+			Topic: f.Topic,
+			Value: sarama.ByteEncoder(rawdata),
+		})
+	}
+	return f.producer.SendMessages(message)

Review Comment:
   The meter data needs to be sent to the consistent backend address. Please follow the native gRPC Meter forwarder to get more information. 



##########
test/e2e/base/consumer/target/classes/application.yml:
##########
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with

Review Comment:
   Please don't add the files under the `target` directory. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org