Skip to content

Basic instrumentation for shards #4006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ With this release InfluxDB is moving to Go 1.5.
- [#4003](https://github.com/influxdb/influxdb/pull/4033): Add logrotate configuration.
- [#4043](https://github.com/influxdb/influxdb/pull/4043): Add stats and batching to openTSDB input
- [#4042](https://github.com/influxdb/influxdb/pull/4042): Add pending batches control to batcher
- [#4006](https://github.com/influxdb/influxdb/pull/4006): Add basic statistics for shards

### Bugfixes
- [#4042](https://github.com/influxdb/influxdb/pull/4042): Set UDP input batching defaults as needed.
Expand Down
32 changes: 31 additions & 1 deletion tsdb/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ import (
"encoding/binary"
"encoding/json"
"errors"
"expvar"
"fmt"
"io"
"math"
"os"
"sync"

"github.com/influxdb/influxdb"
"github.com/influxdb/influxdb/influxql"
"github.com/influxdb/influxdb/tsdb/internal"

"github.com/boltdb/bolt"
"github.com/gogo/protobuf/proto"
)

const (
statWriteReq = "write_req"
statSeriesCreate = "series_create"
statFieldsCreate = "fields_create"
statWritePointsFail = "write_points_fail"
statWritePointsOK = "write_points_ok"
statWriteBytes = "write_bytes"
)

var (
// ErrFieldOverflow is returned when too many fields are created on a measurement.
ErrFieldOverflow = errors.New("field overflow")
Expand Down Expand Up @@ -49,12 +60,20 @@ type Shard struct {
mu sync.RWMutex
measurementFields map[string]*MeasurementFields // measurement name to their fields

// expvar-based stats.
statMap *expvar.Map

// The writer used by the logger.
LogOutput io.Writer
}

// NewShard returns a new initialized Shard. walPath doesn't apply to the b1 type index
func NewShard(id uint64, index *DatabaseIndex, path string, walPath string, options EngineOptions) *Shard {
// Configure statistics collection.
key := fmt.Sprintf("shard:%s:%d", path, id)
tags := map[string]string{"path": path, "id": fmt.Sprintf("%d", id), "engine": options.EngineVersion}
statMap := influxdb.NewStatistics(key, "shard", tags)

return &Shard{
index: index,
path: path,
Expand All @@ -63,6 +82,7 @@ func NewShard(id uint64, index *DatabaseIndex, path string, walPath string, opti
options: options,
measurementFields: make(map[string]*MeasurementFields),

statMap: statMap,
LogOutput: os.Stderr,
}
}
Expand Down Expand Up @@ -172,10 +192,14 @@ type SeriesCreate struct {

// WritePoints will write the raw data points and any new metadata to the index in the shard
func (s *Shard) WritePoints(points []Point) error {
s.statMap.Add(statWriteReq, 1)

seriesToCreate, fieldsToCreate, seriesToAddShardTo, err := s.validateSeriesAndFields(points)
if err != nil {
return err
}
s.statMap.Add(statSeriesCreate, int64(len(seriesToCreate)))
s.statMap.Add(statFieldsCreate, int64(len(fieldsToCreate)))

// add any new series to the in-memory index
if len(seriesToCreate) > 0 {
Expand Down Expand Up @@ -229,8 +253,10 @@ func (s *Shard) WritePoints(points []Point) error {

// Write to the engine.
if err := s.engine.WritePoints(points, measurementFieldsToSave, seriesToCreate); err != nil {
s.statMap.Add(statWritePointsFail, 1)
return fmt.Errorf("engine: %s", err)
}
s.statMap.Add(statWritePointsOK, int64(len(points)))

return nil
}
Expand Down Expand Up @@ -402,7 +428,11 @@ func (s *Shard) validateSeriesAndFields(points []Point) ([]*SeriesCreate, []*Fie
func (s *Shard) SeriesCount() (int, error) { return s.engine.SeriesCount() }

// WriteTo writes the shard's data to w.
func (s *Shard) WriteTo(w io.Writer) (int64, error) { return s.engine.WriteTo(w) }
func (s *Shard) WriteTo(w io.Writer) (int64, error) {
n, err := s.engine.WriteTo(w)
s.statMap.Add(statWriteBytes, int64(n))
return n, err
}

type MeasurementFields struct {
Fields map[string]*Field `json:"fields"`
Expand Down