Skip to content

Commit 44f336d

Browse files
authored
Improvements fixes #157 (#163)
1 parent 6164bef commit 44f336d

File tree

12 files changed

+62
-684
lines changed

12 files changed

+62
-684
lines changed

README.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ The entry point of the framework is the `Service`. The `Service` uses `Component
1414
- synchronous processing (HTTP)
1515
- metrics and tracing
1616
- logging
17-
- configuration management
1817

1918
`Patron` provides same defaults for making the usage as simple as possible.
2019

@@ -218,36 +217,3 @@ type Factory interface {
218217
Two methods are supported:
219218

220219
- Create, which creates a logger with the specified fields (or nil)
221-
222-
## Config
223-
224-
The config package defines a interface that has to be implemented in order to be used inside the application.
225-
226-
```go
227-
type Config interface {
228-
Set(key string, value interface{}) error
229-
Get(key string) (interface{}, error)
230-
GetBool(key string) (bool, error)
231-
GetInt64(key string) (int64, error)
232-
GetString(key string) (string, error)
233-
GetFloat64(key string) (float64, error)
234-
}
235-
```
236-
237-
After implementing the interface a instance has to be provided to the `Setup` method of the package in order to be used directly from the package eg `config.GetBool()`.
238-
239-
The following implementations are provided as sub-packages:
240-
241-
- env, support for env files and env vars
242-
243-
By default the service will use the `env` implementation and look for a `.env` file when starting up in order to set some env vars from a file. This is especially helpful for development.
244-
245-
### env
246-
247-
The env package supports getting env vars from the system. It allows further to provide a file that contain env vars, separated by a equal sign `=`, which are then set up on the environment. In order to setup config just do the following:
248-
249-
```go
250-
c,err := env.New({reader to the config file})
251-
// error checking
252-
config.Setup(c)
253-
```

async/kafka/kafka.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"strconv"
87

98
"github.com/Shopify/sarama"
109
"github.com/mantzas/patron/async"
@@ -13,12 +12,6 @@ import (
1312
"github.com/mantzas/patron/trace"
1413
opentracing "github.com/opentracing/opentracing-go"
1514
"github.com/pkg/errors"
16-
"github.com/prometheus/client_golang/prometheus"
17-
)
18-
19-
var (
20-
topicPartitionOffsetDiff *prometheus.GaugeVec
21-
messagesConsumedCounter *prometheus.CounterVec
2215
)
2316

2417
type message struct {
@@ -111,7 +104,6 @@ func New(name, ct, topic string, brokers []string, oo ...OptionFunc) (*Consumer,
111104
}
112105
}
113106

114-
initMetrics(name)
115107
return c, nil
116108
}
117109

@@ -140,7 +132,6 @@ func (c *Consumer) Consume(ctx context.Context) (<-chan async.Message, <-chan er
140132
chErr <- consumerError
141133
case msg := <-consumer.Messages():
142134
c.log.Debugf("data received from topic %s", msg.Topic)
143-
reportStats(msg.Topic, msg.Partition, consumer.HighWaterMarkOffset(), msg.Offset)
144135
go func() {
145136
sp, chCtx := trace.StartConsumerSpan(ctx, c.name, trace.KafkaConsumerComponent, mapHeader(msg.Headers))
146137

@@ -226,34 +217,3 @@ func mapHeader(hh []*sarama.RecordHeader) map[string]string {
226217
}
227218
return mp
228219
}
229-
230-
func initMetrics(namespace string) {
231-
232-
topicPartitionOffsetDiff = prometheus.NewGaugeVec(
233-
prometheus.GaugeOpts{
234-
Namespace: namespace,
235-
Subsystem: "kafka_consumer",
236-
Name: "offset_diff",
237-
Help: "Message offset classified by topic and partition",
238-
},
239-
[]string{"topic", "partition"},
240-
)
241-
242-
messagesConsumedCounter = prometheus.NewCounterVec(
243-
prometheus.CounterOpts{
244-
Namespace: namespace,
245-
Subsystem: "kafka_consumer",
246-
Name: "messages_consumed_total",
247-
Help: "Total messages consumed, classified by topic and queue service",
248-
},
249-
[]string{"topic"},
250-
)
251-
prometheus.RegisterOrGet(messagesConsumedCounter)
252-
prometheus.RegisterOrGet(topicPartitionOffsetDiff)
253-
}
254-
255-
func reportStats(topic string, partition int32, highwaterMark, offset int64) {
256-
messagesConsumedCounter.WithLabelValues(topic).Inc()
257-
topicPartitionOffsetDiff.WithLabelValues(topic, strconv.FormatInt(int64(partition), 10)).
258-
Set(float64(highwaterMark - offset))
259-
}

async/kafka/kafka_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ func TestNew(t *testing.T) {
5454
if tt.wantErr {
5555
assert.Error(err)
5656
assert.Nil(got)
57-
assert.Nil(messagesConsumedCounter)
58-
assert.Nil(topicPartitionOffsetDiff)
5957
} else {
6058
assert.NoError(err)
6159
assert.NotNil(got)
62-
assert.NotNil(messagesConsumedCounter)
63-
assert.NotNil(topicPartitionOffsetDiff)
6460
}
6561
})
6662
}

config/config.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

config/config_test.go

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)