Skip to content

Commit afc036c

Browse files
authored
Merge pull request #1066 from brave-intl/master
production 2021-12-21_1
2 parents 3a2230b + 3812e07 commit afc036c

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

payment/key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestGenerateSecret(t *testing.T) {
7171
if len(bareSecretKey) != 32 {
7272
t.Error("Secret key does not have correct length", err)
7373
}
74-
if len(k) < 0 {
74+
if len(k) <= 0 {
7575
t.Error("the key should be bigger than nothing")
7676
}
7777
}

promotion/avro.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const adminAttestationEventSchema = `{
4242
{ "name": "created_at", "type": "string" }
4343
]}`
4444

45+
// AdminAttestationEvent - kafka admin attestation event
4546
type AdminAttestationEvent struct {
4647
WalletID string `json:"wallet_id"`
4748
Service string `json:"service"`

promotion/drain.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,8 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U
335335
)
336336

337337
var (
338-
totalF64 float64
339-
depositID string
340-
transferID string
338+
totalF64 float64
339+
depositID string
341340
)
342341

343342
for _, v := range transfers {
@@ -358,7 +357,6 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U
358357
break
359358
}
360359
depositID = *v.DepositID
361-
transferID = transferID + v.ID.String()
362360
}
363361

364362
// collapse into one transaction, not multiples in a bulk upload
@@ -367,7 +365,7 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U
367365
CurrencyCode: "BAT",
368366
Amount: totalF64,
369367
DepositID: depositID,
370-
TransferID: transferID,
368+
TransferID: batchID.String(),
371369
SourceFrom: "userdrain",
372370
})
373371

@@ -726,13 +724,13 @@ func (service *Service) MintGrant(ctx context.Context, walletID uuid.UUID, total
726724
}
727725

728726
// FetchAdminAttestationWalletID - retrieves walletID from topic
729-
func (s *Service) FetchAdminAttestationWalletID(ctx context.Context) (*uuid.UUID, error) {
730-
message, err := s.kafkaAdminAttestationReader.ReadMessage(ctx)
727+
func (service *Service) FetchAdminAttestationWalletID(ctx context.Context) (*uuid.UUID, error) {
728+
message, err := service.kafkaAdminAttestationReader.ReadMessage(ctx)
731729
if err != nil {
732730
return nil, fmt.Errorf("read message: error reading kafka message %w", err)
733731
}
734732

735-
codec, ok := s.codecs[adminAttestationTopic]
733+
codec, ok := service.codecs[adminAttestationTopic]
736734
if !ok {
737735
return nil, fmt.Errorf("read message: could not find codec %s", adminAttestationTopic)
738736
}

promotion/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func SetAdminAttestationTopic(newTopic string) {
9898
adminAttestationTopic = newTopic
9999
}
100100

101+
// KafkaReader - reader interface
101102
type KafkaReader interface {
102103
ReadMessage(ctx context.Context) (kafka.Message, error)
103104
}

utils/clients/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func (c *SimpleHTTPClient) newRequest(
160160
})
161161

162162
// m, _ := json.MarshalIndent(body, "", " ")
163-
// fmt.Println(path, string(m))
164163
if body != nil && method != "GET" {
165164
buf = new(bytes.Buffer)
166165
err := json.NewEncoder(buf).Encode(body)
@@ -270,10 +269,9 @@ func (c *SimpleHTTPClient) do(
270269

271270
// helpful if you want to read the body as it is
272271
bodyBytes, _ := requestutils.Read(resp.Body)
273-
resp.Body.Close() // must close
272+
_ = resp.Body.Close() // must close
274273
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
275274

276-
// fmt.Println(req.URL.Host, req.URL.Path, string(bodyBytes))
277275
if status >= 200 && status <= 299 {
278276
if v != nil {
279277
err = json.Unmarshal(bodyBytes, v)
@@ -284,6 +282,8 @@ func (c *SimpleHTTPClient) do(
284282
return resp, nil
285283
}
286284

285+
logger.Warn().Int("response_status", status).Err(err).Msg("failed http client call")
286+
logger.Debug().Str("host", req.URL.Host).Str("path", req.URL.Path).Str("body", string(bodyBytes)).Msg("failed http client call")
287287
return resp, errors.Wrap(err, ErrProtocolError)
288288
}
289289

utils/kafka/dialer.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ import (
1414
"time"
1515

1616
"github.com/linkedin/goavro"
17-
kafka "github.com/segmentio/kafka-go"
17+
"github.com/segmentio/kafka-go"
1818

1919
appctx "github.com/brave-intl/bat-go/utils/context"
2020
errorutils "github.com/brave-intl/bat-go/utils/errors"
2121
"github.com/brave-intl/bat-go/utils/logging"
2222
)
2323

24-
type KafkaRead struct {
24+
// Reader - implements KafkaReader
25+
type Reader struct {
2526
kafkaReader *kafka.Reader
2627
kafkaDialer *kafka.Dialer
2728
}
2829

29-
func NewKafkaReader(ctx context.Context, groupID string, topic string) (*KafkaRead, error) {
30+
// NewKafkaReader - creates a new kafka reader for groupID and topic
31+
func NewKafkaReader(ctx context.Context, groupID string, topic string) (*Reader, error) {
3032
_, logger := logging.SetupLogger(ctx)
3133

3234
dialer, x509Cert, err := TLSDialer()
@@ -40,20 +42,23 @@ func NewKafkaReader(ctx context.Context, groupID string, topic string) (*KafkaRe
4042
kafkaBrokers := ctx.Value(appctx.KafkaBrokersCTXKey).(string)
4143

4244
kafkaReader := kafka.NewReader(kafka.ReaderConfig{
43-
Brokers: strings.Split(kafkaBrokers, ","),
44-
GroupID: groupID,
45-
Topic: topic,
46-
Dialer: dialer,
47-
Logger: kafka.LoggerFunc(logger.Printf), // FIXME
45+
Brokers: strings.Split(kafkaBrokers, ","),
46+
GroupID: groupID,
47+
Topic: topic,
48+
Dialer: dialer,
49+
StartOffset: 0,
50+
RetentionTime: 2 * time.Hour,
51+
Logger: kafka.LoggerFunc(logger.Printf), // FIXME
4852
})
4953

50-
return &KafkaRead{
54+
return &Reader{
5155
kafkaReader: kafkaReader,
5256
kafkaDialer: dialer,
5357
}, nil
5458
}
5559

56-
func (k *KafkaRead) ReadMessage(ctx context.Context) (kafka.Message, error) {
60+
// ReadMessage - reads kafka messages
61+
func (k *Reader) ReadMessage(ctx context.Context) (kafka.Message, error) {
5762
return k.kafkaReader.ReadMessage(ctx)
5863
}
5964

0 commit comments

Comments
 (0)