Skip to content

Commit

Permalink
fix(fmt&statsd): fix import fmt and remove stastsd bucket host name
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi Jia committed Apr 19, 2018
1 parent 800f288 commit 3c8e1e3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
19 changes: 10 additions & 9 deletions kafka/kafka.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package kafka

import (
"time"

"github.com/Shopify/sarama"
"github.com/lingmiaotech/tonic/configs"
"time"
)

type Class struct {
Expand All @@ -25,15 +26,15 @@ func InitKafka() (err error) {

brokers := configs.GetStringSlice("kafka.brokers")

configs := sarama.NewConfig()
configs.Producer.RequiredAcks = sarama.WaitForLocal // Only wait for the leader to ack
configs.Producer.Compression = sarama.CompressionNone // Compress messages
configs.Producer.Flush.Frequency = 500 * time.Millisecond // Flush batches every 500ms
configs.Producer.Retry.Max = 3
configs.Producer.Return.Errors = true
configs.Producer.Return.Successes = true
cfg := sarama.NewConfig()
cfg.Producer.RequiredAcks = sarama.WaitForLocal // Only wait for the leader to ack
cfg.Producer.Compression = sarama.CompressionNone // Compress messages
cfg.Producer.Flush.Frequency = 500 * time.Millisecond // Flush batches every 500ms
cfg.Producer.Retry.Max = 3
cfg.Producer.Return.Errors = true
cfg.Producer.Return.Successes = true

producer, err := sarama.NewSyncProducer(brokers, configs)
producer, err := sarama.NewSyncProducer(brokers, cfg)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion logging/kafka_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package logging

import (
"errors"
"time"

"github.com/Shopify/sarama"
"github.com/lingmiaotech/tonic/kafka"
"github.com/sirupsen/logrus"
"time"
)

type KafkaHook struct {
Expand Down
1 change: 1 addition & 0 deletions redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"fmt"

"github.com/go-redis/redis"
"github.com/lingmiaotech/tonic/configs"
)
Expand Down
3 changes: 2 additions & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package request
import (
"bytes"
"encoding/json"
"github.com/levigross/grequests"
"net/http"

"github.com/levigross/grequests"
)

type Opts grequests.RequestOptions
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tonic
import (
"errors"
"fmt"
"io/ioutil"

"github.com/CrowdSurge/banner"
"github.com/gin-gonic/gin"
"github.com/lingmiaotech/tonic/configs"
Expand All @@ -12,7 +14,6 @@ import (
"github.com/lingmiaotech/tonic/redis"
"github.com/lingmiaotech/tonic/sentry"
"github.com/lingmiaotech/tonic/statsd"
"io/ioutil"
)

type Server struct {
Expand Down
14 changes: 7 additions & 7 deletions statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package statsd

import (
"fmt"
"time"

"github.com/lingmiaotech/tonic/configs"
"github.com/lingmiaotech/tonic/logging"
"gopkg.in/alexcesaro/statsd.v2"
"os"
"time"
)

type InstanceClass struct {
Expand Down Expand Up @@ -59,17 +59,17 @@ func Gauge(bucket string, n int) {
}

func getBucket(bucket string) string {
hostName, err := os.Hostname()
if err != nil {
hostName = "UNKNOWNHOST"
}
return fmt.Sprintf("%v.%v.%v", hostName, Instance.AppName, bucket)
return fmt.Sprintf("%v.%v", Instance.AppName, bucket)
}

func NewTimer() Timer {
return Timer{start: time.Now()}
}

func NewCustomTimer(t time.Time) Timer {
return Timer{start: t}
}

// Send sends the time elapsed since the creation of the Timing.
func (t Timer) Send(bucket string) {
Timing(bucket, int(t.Duration()/time.Millisecond))
Expand Down

0 comments on commit 3c8e1e3

Please sign in to comment.