Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
feat: add reporter plugins: kafka sarama (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
matianjun1 authored Oct 10, 2021
1 parent 2175b8c commit ee26026
Show file tree
Hide file tree
Showing 16 changed files with 1,306 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/plugin_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
resty/test/go_resty_plugin_test.yaml: resty/**
kratos/test/go_kratos_plugin_test.yaml: kratos/**
sql/test/sql_plugin_test.yaml: sql/**
kafkareporter/test/go_kafka_reporter_plugin_test.yaml: kafkareporter/**
PluginsTest:
name: Plugin
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ The plugins of [go2sky](https://github.com/SkyAPM/go2sky)

## Plugin Summary

### Reporter Plugins

1. [kafkareporter](kafkareporter/README.md)

### Trace Plugins

1. [http server & client](http/README.md)
1. [gin](gin/README.md)
1. [gear](gear/README.md)
Expand All @@ -17,5 +22,6 @@ The plugins of [go2sky](https://github.com/SkyAPM/go2sky)
1. [sql](sql/README.md)

### Log Plugins

1. [logrus](logrus/README.md)
1. [zap](zap/README.md)
18 changes: 18 additions & 0 deletions kafkareporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Go2sky with kafka reporter

## Installation

```go
go get -u github.com/SkyAPM/go2sky-plugins/kafkareporter
```

## Usage

```go
r, err := kafkareporter.New([]string{"localhost:9092"})
if err != nil {
log.Fatalf("new kafka reporter error %v \n", err)
}
defer r.Close()
tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r))
```
18 changes: 18 additions & 0 deletions kafkareporter/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright 2021 SkyAPM org
//
// Licensed 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 sarama is a plugin that can be one kafka reporter as go2sky.Reporter.
package kafkareporter
10 changes: 10 additions & 0 deletions kafkareporter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/SkyAPM/go2sky-plugins/kafkareporter

go 1.16

require (
github.com/Shopify/sarama v1.29.1
github.com/SkyAPM/go2sky v1.2.0
google.golang.org/protobuf v1.27.1
skywalking.apache.org/repo/goapi v0.0.0-20210820070710-e10b78bbf481
)
225 changes: 225 additions & 0 deletions kafkareporter/go.sum

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions kafkareporter/internal/tool/os_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Copyright 2021 SkyAPM org
//
// Licensed 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 tool

import (
"net"
"os"
"runtime"
"strconv"
)

func ProcessNo() string {
if os.Getpid() > 0 {
return strconv.Itoa(os.Getpid())
}
return ""
}

func HostName() string {
if hs, err := os.Hostname(); err == nil {
return hs
}
return "unknown"
}

func OSName() string {
return runtime.GOOS
}

func AllIPV4() (ipv4s []string) {
adders, err := net.InterfaceAddrs()
if err != nil {
return
}

for _, addr := range adders {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ipv4 := ipNet.IP.String()
if ipv4 == "127.0.0.1" || ipv4 == "localhost" {
continue
}
ipv4s = append(ipv4s, ipv4)
}
}
}
return
}

func IPV4() string {
ipv4s := AllIPV4()
if len(ipv4s) > 0 {
return ipv4s[0]
}
return "no-hostname"
}
Loading

0 comments on commit ee26026

Please sign in to comment.