Skip to content

Commit

Permalink
add doc to context for issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
rwynn committed May 11, 2019
1 parent 25bc1d4 commit 4a6d750
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ fields = ["sales", "price"]
retention = "RP1"
# override the measurement name which defaults to the name of the MongoDB collection
measure = "sales"
# the measurement name can be calculated from the Fields or Tags in a golang template
# measure = "{{.Tags.category}}_{{.Fields.price}}"
# the measurement name can be calculated from the Fields, Tags, or Doc in a golang template
# measure = "{{.Tags.category}}_{{.Fields.price}}_{{.Doc.name}}"
# override the influx database name which default to the name of the MongoDB database
database = "salesdb"

Expand Down
7 changes: 4 additions & 3 deletions mongofluxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,13 @@ func (m *InfluxDataMap) loadKV(k string, v interface{}) {
}
}

func (m *InfluxDataMap) resolveName(tags map[string]string, fields map[string]interface{}) error {
func (m *InfluxDataMap) resolveName(tags map[string]string, fields, doc map[string]interface{}) error {
if m.nameTpl != nil {
var b bytes.Buffer
env := map[string]interface{}{
"Tags": tags,
"Fields": fields,
"Doc": doc,
}
if err := m.nameTpl.Execute(&b, env); err != nil {
return err
Expand Down Expand Up @@ -455,7 +456,7 @@ func (ctx *InfluxCtx) addPoint(op *gtm.Op) error {
return err
}
for _, pt := range points {
if err := mapper.resolveName(pt.Tags, pt.Fields); err != nil {
if err := mapper.resolveName(pt.Tags, pt.Fields, op.Data); err != nil {
return err
}
pt, err := client.NewPoint(mapper.name, pt.Tags, pt.Fields, pt.Timestamp)
Expand All @@ -468,7 +469,7 @@ func (ctx *InfluxCtx) addPoint(op *gtm.Op) error {
if err := mapper.loadData(); err != nil {
return err
}
if err := mapper.resolveName(mapper.tags, mapper.fields); err != nil {
if err := mapper.resolveName(mapper.tags, mapper.fields, op.Data); err != nil {
return err
}
pt, err := client.NewPoint(mapper.name, mapper.tags, mapper.fields, mapper.t)
Expand Down

0 comments on commit 4a6d750

Please sign in to comment.