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

Add dpdk_telemetry plugin #913

Merged
merged 1 commit into from
Mar 4, 2020
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ documentation for each plugin for configurable attributes.
* `disk` (see [collectd::plugin::disk](#class-collectdplugindisk) below)
* `dns` (see [collectd::plugin::dns](#class-collectdplugindns) below)
* `dcpmm` (see [collectd::plugin::dcpmm](#class-collectdplugindcpmm) below)
* `dpdk_telemetry` (see [collectd::plugin::dpdk_telemetry](#class-collectdplugindpdk_telemetry) below)
* `entropy` (see [collectd::plugin::entropy](#class-collectdpluginentropy) below)
* `exec` (see [collectd::plugin::exec](#class-collectdpluginexec) below)
* `ethstat` (see [collectd::plugin::ethstat](#class-collectdpluginethstat) below)
Expand Down Expand Up @@ -585,6 +586,15 @@ Boolean for SelectNumericQueryTypes configuration option.

- *Default*: true

#### Class: `collectd::plugin::dpdk_telemetry`

```puppet
class { 'collectd::plugin::dpdk_telemetry':
client_socket_path => '/var/run/.client',
dpdk_socket_path => '/var/run/dpdk/rte/telemetry',
}
```

#### Class: `collectd::plugin::dcpmm`

```puppet
Expand Down
28 changes: 28 additions & 0 deletions manifests/plugin/dpdk_telemetry.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Class to manage dpdk_telemetry plugin for collectd.
#
# The dpdk_telemetry plugin collects DPDK ethernet device metrics via
# dpdk_telemetry library.
#
# Plugin retrieves metrics from a DPDK packet forwarding application
# by sending the JSON formatted message via a UNIX domain socket.
# DPDK telemetry component will respond with a JSON formatted reply
# delivering the requested metrics. Plugin parses the JSON data
# and publishes the metric values to collectd for further use.
#
# @param ensure Ensure param for collectd::plugin type.
# @param client_socket_path UNIX domain client socket to receive messages from DPDK telemetry library.
# @param dpdk_socket_path UNIX domain DPDK telemetry socket to be connected to send messages.
#
class collectd::plugin::dpdk_telemetry (
Enum['present', 'absent'] $ensure = 'present',
Stdlib::Absolutepath $client_socket_path = '/var/run/.client',
Stdlib::Absolutepath $dpdk_socket_path = '/var/run/dpdk/rte/telemetry',
) {

include collectd

collectd::plugin { 'dpdk_telemetry':
ensure => $ensure,
content => epp('collectd/plugin/dpdk_telemetry.conf.epp'),
}
}
81 changes: 81 additions & 0 deletions spec/classes/collectd_plugin_dpdk_telemetry_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
require 'spec_helper'

describe 'collectd::plugin::dpdk_telemetry', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

options = os_specific_options(facts)

context ':ensure => present, default params' do
content = <<EOS
# Generated by Puppet
<LoadPlugin dpdk_telemetry>
Globals false
</LoadPlugin>

<Plugin dpdk_telemetry>
ClientSocketPath "/var/run/.client"
DpdkSocketPath "/var/run/dpdk/rte/telemetry"
</Plugin>

EOS

it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
is_expected.to compile.with_all_deps
is_expected.to contain_file('dpdk_telemetry.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
content: content
)
end
end

context ':ensure => absent' do
let :params do
{ ensure: 'absent' }
end

it "Will not create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
is_expected.to compile.with_all_deps
is_expected.to contain_file('dpdk_telemetry.load').with(
ensure: 'absent',
path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf"
)
end
end

context ':ensure => present and :client_socket_path => /test/path/.client' do
let :params do
{ client_socket_path: '/test/path/.client' }
end

it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
is_expected.to compile.with_all_deps
is_expected.to contain_file('dpdk_telemetry.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
content: %r{ClientSocketPath "/test/path/.client"}m
)
end
end

context ':ensure => present and :dpdk_socket_path => /test/path/telemetry' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a context for ensure => absent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case with "ensure => absent" added.

let :params do
{ dpdk_socket_path: '/test/path/telemetry' }
end

it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since client_socket_path can be undef, there should be a test that shows the content when the param is undef. Same for dpdk_socket_path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking into creating test case that you described but I stumbled upon obstacle. I wrote following test:

      context ':ensure => present, :client_socket_path => undef and :dpdk_socket_path => undef' do
        let :params do
          { client_socket_path: :undef,
            dpdk_socket_path: :undef }
        end

        sth = <<EOS
# Generated by Puppet
<LoadPlugin dpdk_telemetry>
  Globals false
</LoadPlugin>

<Plugin dpdk_telemetry>
</Plugin>

EOS

        it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('dpdk_telemetry.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
            content: sth
          )
        end
      end

Configuration is generated using specified default values rather than assuming that no value was provided.
I found interesting message by jcbollinger here, suggesting that assigning undef doesn't actually assign undef, only implies that no specified value is being assigned, and therefore default should be used.

I'm relatively new to Puppet, RSpec and Ruby so I can't be sure, however my observations suggests that it in fact might work that way. Additionally, I couldn't find this kind of test case in this repository. Are you sure that test case you described is possible to write? If so, could you give any suggestion how to proceed?

is_expected.to compile.with_all_deps
is_expected.to contain_file('dpdk_telemetry.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
content: %r{DpdkSocketPath "/test/path/telemetry"}m
)
end
end
end
end
end
8 changes: 8 additions & 0 deletions templates/plugin/dpdk_telemetry.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Plugin dpdk_telemetry>
<% if $collectd::plugin::dpdk_telemetry::client_socket_path { -%>
ClientSocketPath "<%= $collectd::plugin::dpdk_telemetry::client_socket_path %>"
<% } -%>
<% if $collectd::plugin::dpdk_telemetry::dpdk_socket_path { -%>
DpdkSocketPath "<%= $collectd::plugin::dpdk_telemetry::dpdk_socket_path %>"
<% } -%>
</Plugin>