Add logs for start scan and checkpoints

This commit is contained in:
Harlow Ward 2017-11-22 17:52:41 -08:00
parent 3770136f64
commit 4ffe3ec55a
3 changed files with 8 additions and 10 deletions

View file

@ -3,8 +3,8 @@ package consumer
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os"
"sync" "sync"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -31,7 +31,7 @@ type Checkpoint interface {
type noopCheckpoint struct{} type noopCheckpoint struct{}
func (n noopCheckpoint) Set(string, string) error { return nil } func (n noopCheckpoint) Set(string, string) error { return nil }
func (n noopCheckpoint) Get(string) (string, error) { return "", nil } func (n noopCheckpoint) Get(string) (string, error) { return "", nil }
// Option is used to override defaults when creating a new Consumer // Option is used to override defaults when creating a new Consumer
@ -76,7 +76,8 @@ func New(app, stream string, opts ...Option) (*Consumer, error) {
appName: app, appName: app,
streamName: stream, streamName: stream,
checkpoint: &noopCheckpoint{}, checkpoint: &noopCheckpoint{},
counter: &noopCounter{}, counter: &noopCounter{},
logger: log.New(os.Stderr, "kinesis-consumer: ", log.LstdFlags),
} }
// set options // set options
@ -86,11 +87,6 @@ func New(app, stream string, opts ...Option) (*Consumer, error) {
} }
} }
// provide default logger
if c.logger == nil {
c.logger = log.New(ioutil.Discard, "", log.LstdFlags)
}
// provide a default kinesis client // provide a default kinesis client
if c.client == nil { if c.client == nil {
c.client = kinesis.New(session.New(aws.NewConfig())) c.client = kinesis.New(session.New(aws.NewConfig()))
@ -197,6 +193,8 @@ loop:
if err := c.checkpoint.Set(shardID, lastSeqNum); err != nil { if err := c.checkpoint.Set(shardID, lastSeqNum); err != nil {
c.logger.Printf("set checkpoint error: %v", err) c.logger.Printf("set checkpoint error: %v", err)
} }
c.logger.Println("checkpoint", shardID, len(resp.Records))
c.counter.Add("checkpoints", 1) c.counter.Add("checkpoints", 1)
} }

View file

@ -14,4 +14,4 @@ export AWS_SECRET_KEY=
### Run the consumer ### Run the consumer
$ go run main.go -a appName -s streamName $ go run main.go --app appName --stream streamName

View file

@ -17,4 +17,4 @@ export AWS_SECRET_KEY=
### Running the code ### Running the code
$ curl https://s3.amazonaws.com/kinesis.test/users.txt > /tmp/users.txt $ curl https://s3.amazonaws.com/kinesis.test/users.txt > /tmp/users.txt
$ go run main.go -s streamName $ go run main.go --stream streamName