Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c51c8a4

Browse files
author
Mike Zhu
committedMar 24, 2021
Support NPM installation switch
1 parent 7d6e3e0 commit c51c8a4

File tree

7 files changed

+66
-20
lines changed

7 files changed

+66
-20
lines changed
 

‎attributes/default.rb

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@
367367
default['datadog']['system_probe']['debug_port'] = 0
368368
default['datadog']['system_probe']['bpf_debug'] = false
369369
default['datadog']['system_probe']['enable_conntrack'] = false
370+
# Enable this switch will install NPM driver and sysprobe, as well as generate the config file.
371+
# Turning on this setting will effectively turn on the setting(s) automatically:
372+
# ['datadog']['system_probe']['enabled']
373+
default['datadog']['system_probe']['network_enabled'] = false
370374

371375
# Logs functionality settings (Agent 6/7 only)
372376
# Set `enable_logs_agent` to:

‎libraries/recipe_helpers.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def ddagentuser_password(node)
9595
end
9696

9797
def npm_install(node)
98-
run_state_or_attribute(node, 'windows_npm_install')
98+
run_state_or_attribute(node, 'windows_npm_install') || run_state_or_attribute_system_probe(node, 'network_enabled')
9999
end
100100

101101
def cookbook_version(run_context)
@@ -130,6 +130,14 @@ def run_state_or_attribute(node, attribute)
130130
node['datadog'][attribute]
131131
end
132132
end
133+
134+
def run_state_or_attribute_system_probe(node, attribute)
135+
if node.run_state.key?('datadog') && node.run_state['datadog'].key?('system_probe') && node.run_state['datadog']['system_probe'].key?(attribute)
136+
node.run_state['datadog']['system_probe'][attribute]
137+
else
138+
node['datadog']['system_probe'][attribute]
139+
end
140+
end
133141
end
134142

135143
module WindowsInstallHelpers

‎recipes/_install-windows.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def unmute_host(context)
105105
install_options.concat(' DDAGENTUSER_NAME=%DDAGENTUSER_NAME%') if ddagentuser_name
106106
install_options.concat(' DDAGENTUSER_PASSWORD=%DDAGENTUSER_PASSWORD%') if ddagentuser_password
107107

108-
install_options.concat(" NPM=#{dd_agent_install_npm}") if dd_agent_install_npm
108+
install_options.concat(' ADDLOCAL=MainApplication,NPM') if dd_agent_install_npm
109109
end
110110

111111
package 'Datadog Agent removal' do

‎recipes/dd-agent.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ def template_vars
158158

159159
system_probe_managed = node['datadog']['system_probe']['manage_config']
160160
agent_version_greater_than_6_11 = agent_major_version > 5 && (agent_minor_version.nil? || agent_minor_version > 11) || agent_major_version > 6
161+
agent_version_greater_than_6_26 = agent_major_version > 5 && (agent_minor_version.nil? || agent_minor_version > 26) || agent_major_version > 6
161162

162-
# System probe requires at least agent 6.12, before that it was called the network-tracer
163-
system_probe_supported = agent_version_greater_than_6_11 && !is_windows
163+
# System probe requires at least agent 6.12 on Linux or 6.27 on Windows, before that it was called the network-tracer or unsupported.
164+
system_probe_supported = (agent_version_greater_than_6_11 && !is_windows) || (agent_version_greater_than_6_26 && is_windows)
164165

165-
# system-probe is a dependency of the agent on Linux
166+
# system-probe is a dependency of the agent on Linux or Windows
166167
include_recipe 'datadog::system-probe' if system_probe_managed && system_probe_supported
167168

168169
# Installation metadata to let know the agent about installation method and its version

‎recipes/system-probe.rb

+34-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717
# limitations under the License.
1818
#
1919

20+
is_windows = platform_family?('windows')
21+
2022
# Set the correct agent startup action
21-
sysprobe_enabled = node['datadog']['system_probe']['enabled']
23+
sysprobe_enabled = node['datadog']['system_probe']['enabled'] || node['datadog']['system_probe']['network_enabled']
2224
sysprobe_agent_start = sysprobe_enabled ? :start : :stop
2325

2426
#
2527
# Configures system-probe agent
26-
system_probe_config_file = '/etc/datadog-agent/system-probe.yaml'
28+
system_probe_config_file =
29+
if is_windows
30+
'C:/ProgramData/Datadog/system-probe.yaml'
31+
else
32+
'/etc/datadog-agent/system-probe.yaml'
33+
end
34+
2735
system_probe_config_file_exists = ::File.exist?(system_probe_config_file)
2836

2937
template system_probe_config_file do
@@ -44,12 +52,20 @@
4452
enable_conntrack: node['datadog']['system_probe']['enable_conntrack'],
4553
extra_config: extra_config
4654
)
47-
owner 'root'
48-
group 'dd-agent'
49-
mode '640'
50-
notifies :restart, 'service[datadog-agent-sysprobe]', :delayed if node['datadog']['system_probe']['enabled']
55+
56+
if is_windows
57+
owner 'Administrators'
58+
rights :full_control, 'Administrators'
59+
inherits false
60+
else
61+
owner 'root'
62+
group 'dd-agent'
63+
mode '640'
64+
end
65+
66+
notifies :restart, 'service[datadog-agent-sysprobe]', :delayed if sysprobe_enabled
5167
# since process-agent collects network info through system-probe, enabling system-probe should also restart process-agent
52-
notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['system_probe']['enabled']
68+
notifies :restart, 'service[datadog-agent]', :delayed if sysprobe_enabled
5369

5470
# System probe is not enabled and the file doesn't exists, don't create it
5571
not_if { !sysprobe_enabled && !system_probe_config_file_exists }
@@ -58,9 +74,19 @@
5874
# Common configuration
5975
service_provider = Chef::Datadog.service_provider(node)
6076

77+
service_name = is_windows ? 'datadog-system-probe' : 'datadog-agent-sysprobe'
78+
6179
service 'datadog-agent-sysprobe' do
80+
service_name service_name
6281
action [sysprobe_agent_start]
6382
provider service_provider unless service_provider.nil?
83+
if is_windows
84+
supports :restart => true, :start => true, :stop => true
85+
restart_command "powershell restart-service #{service_name} -Force"
86+
stop_command "powershell stop-service #{service_name} -Force"
87+
else
88+
supports :restart => true, :status => true, :start => true, :stop => true
89+
end
6490
supports :restart => true, :status => true, :start => true, :stop => true
65-
subscribes :restart, "template[#{system_probe_config_file}]", :delayed if node['datadog']['system_probe']['enabled']
91+
subscribes :restart, "template[#{system_probe_config_file}]", :delayed if sysprobe_enabled
6692
end

‎spec/system-probe_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565

6666
it 'contains expected YAML configuration' do
6767
expected_yaml = <<-EOF
68+
network_config:
69+
enabled: false
6870
system_probe_config:
6971
bpf_debug: true
7072
debug_port: 123
@@ -114,6 +116,8 @@
114116

115117
it 'contains expected YAML configuration' do
116118
expected_yaml = <<-EOF
119+
network_config:
120+
enabled: false
117121
system_probe_config:
118122
bpf_debug: false
119123
debug_port: 0

‎templates/default/system_probe.yaml.erb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<%
22
## Populate system_probe_config ##
33
system_probe_config = {
4-
system_probe_config: @extra_config.merge({
5-
enabled: node['datadog']['system_probe']["enabled"],
6-
sysprobe_socket: node['datadog']['system_probe']['sysprobe_socket'],
7-
debug_port: node['datadog']['system_probe']['debug_port'],
8-
bpf_debug: node['datadog']['system_probe']['bpf_debug'],
9-
enable_conntrack: node['datadog']['system_probe']['enable_conntrack'],
10-
})
4+
system_probe_config: {
5+
enabled: @enabled,
6+
sysprobe_socket: @sysprobe_socket,
7+
debug_port: @debug_port,
8+
bpf_debug: @bpf_debug,
9+
enable_conntrack: @enable_conntrack,
10+
}.merge(@extra_config),
11+
network_config: {
12+
enabled: node['datadog']['system_probe']['network_enabled'],
13+
}
1114
}
1215
-%>
1316
# Generated by Chef, local modifications will be overwritten

0 commit comments

Comments
 (0)
Please sign in to comment.