Skip to content
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

Package plugin: populate ValueList.DSNames when calling write callbacks. #91

Open
pleimer opened this issue Jun 11, 2020 · 3 comments
Open

Comments

@pleimer
Copy link

pleimer commented Jun 11, 2020

Plugin writes do not include new dsnames but instead default to value. To confirm this issue, I used the following code from the docs but changed the dsname. I listened for the messages using the amqp1.

package main

import (
        "context"
        "fmt"
        "time"

        "collectd.org/api"
        "collectd.org/plugin"
)

type examplePlugin struct{}

func (examplePlugin) Read(ctx context.Context) error {
        vl := &api.ValueList{
                Identifier: api.Identifier{
                        Host:   "example.com",
                        Plugin: "goplug",
                        Type:   "gauge",
                },
                Time:     time.Now(),
                Interval: 10 * time.Second,
                Values:   []api.Value{api.Gauge(42)},
                DSNames:  []string{"read"},
        }
        if err := plugin.Write(ctx, vl); err != nil {
                return fmt.Errorf("plugin.Write: %w", err)
        }

        return nil
}

func init() {
	plugin.RegisterRead("example", examplePlugin{})
}

func main() {}

Received Message

[
  {
    "values": [
      42
    ],
    "dstypes": [
      "gauge"
    ],
    "dsnames": [
      "value"
    ],
    "time": 1591894480.918,
    "interval": 10,
    "host": "example.com",
    "plugin": "goplug",
    "plugin_instance": "",
    "type": "gauge",
    "type_instance": ""
  }
]

Expected Message

[
  {
    "values": [
      42
    ],
    "dstypes": [
      "gauge"
    ],
    "dsnames": [
      "read"
    ],
    "time": 1591894480.918,
    "interval": 10,
    "host": "example.com",
    "plugin": "goplug",
    "plugin_instance": "",
    "type": "gauge",
    "type_instance": ""
  }
]

The dsnames field of the message does not container read, but rather the default string value

@octo
Copy link
Member

octo commented Jun 15, 2020

Hi @pleimer, thank you for bringing this up!

This is a limitation of collectd's C API – the "DS names" are not included in the value_list_t struct. This data structure will change significantly with the next major version of collectd, which we're planning to release later this year. So it's more than unlikely that we'll patch the "DS names" through the entire daemon – it's significant work and soon to be obsolete.

We should, however, populate the ValueList.DSNames field when calling write callbacks. You would not (necessarily) get the names passed to plugin.Write, but the names configured in the types.db(5) file. Ideally those two would be the same.

Hope this helps!
—octo

@octo octo changed the title plugin write does not include dsnames Package plugin: populate ValueList.DSNames when calling write callbacks. Jun 15, 2020
@octo
Copy link
Member

octo commented Jun 15, 2020

I just now saw that you were using the AMQP plugin to verify: that is not going to get fixed, sorry. You'll have to add a entry to the types.db file using the expected data source names.

@pleimer
Copy link
Author

pleimer commented Jun 15, 2020

This is a limitation of collectd's C API – the "DS names" are not included in the value_list_t struct. This data structure will change significantly with the next major version of collectd, which we're planning to release later this year. So it's more than unlikely that we'll patch the "DS names" through the entire daemon – it's significant work and soon to be obsolete.

I see thanks for pointing that out, I did not notice that in my original research.

We should, however, populate the ValueList.DSNames field when calling write callbacks. You would not (necessarily) get the names passed to plugin.Write, but the names configured in the types.db(5) file. Ideally those two would be the same.

I did some additional experimentation by including the extra types in a custom types.db file and now I do see the new data source names. It seems that anything specified in ValueList.DSNames is simply ignored, however. Is the purpose of the field purely a convenient way to track the names when writing a plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants