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 a227af4

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

File tree

6 files changed

+68
-21
lines changed

6 files changed

+68
-21
lines changed
 

‎attributes/default.rb

+7
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@
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 settings automatically:
372+
# ['datadog']['extra_config']['system_probe']['network_enabled']
373+
# ['datadog']['system_probe']['enabled']
374+
default['datadog']['system_probe']['network_enabled'] = false
375+
# enable this switch will turn on network monitoring in system_probe.yaml file.
376+
default['datadog']['extra_config']['system_probe']['network_enabled'] = nil
370377

371378
# Logs functionality settings (Agent 6/7 only)
372379
# 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_7_26 = agent_major_version > 6 && (agent_minor_version.nil? || agent_minor_version > 26) || agent_major_version > 7
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 7.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_7_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

+40-9
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
@@ -35,21 +43,34 @@
3543
end
3644
end
3745

46+
if node['datadog']['system_probe']['network_enabled']
47+
# if network monitoring need to be enabled, enable it in the config yaml file.
48+
extra_config['network_enabled'] = true
49+
end
50+
3851
source 'system_probe.yaml.erb'
3952
variables(
40-
enabled: node['datadog']['system_probe']['enabled'],
53+
enabled: sysprobe_enabled,
4154
sysprobe_socket: node['datadog']['system_probe']['sysprobe_socket'],
4255
debug_port: node['datadog']['system_probe']['debug_port'],
4356
bpf_debug: node['datadog']['system_probe']['bpf_debug'],
4457
enable_conntrack: node['datadog']['system_probe']['enable_conntrack'],
4558
extra_config: extra_config
4659
)
47-
owner 'root'
48-
group 'dd-agent'
49-
mode '640'
50-
notifies :restart, 'service[datadog-agent-sysprobe]', :delayed if node['datadog']['system_probe']['enabled']
60+
61+
if is_windows
62+
owner 'Administrators'
63+
rights :full_control, 'Administrators'
64+
inherits false
65+
else
66+
owner 'root'
67+
group 'dd-agent'
68+
mode '640'
69+
end
70+
71+
notifies :restart, 'service[datadog-agent-sysprobe]', :delayed if sysprobe_enabled
5172
# 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']
73+
notifies :restart, 'service[datadog-agent]', :delayed if sysprobe_enabled
5374

5475
# System probe is not enabled and the file doesn't exists, don't create it
5576
not_if { !sysprobe_enabled && !system_probe_config_file_exists }
@@ -58,9 +79,19 @@
5879
# Common configuration
5980
service_provider = Chef::Datadog.service_provider(node)
6081

82+
service_name = is_windows ? 'datadog-system-probe' : 'datadog-agent-sysprobe'
83+
6184
service 'datadog-agent-sysprobe' do
85+
service_name service_name
6286
action [sysprobe_agent_start]
6387
provider service_provider unless service_provider.nil?
88+
if is_windows
89+
supports :restart => true, :start => true, :stop => true
90+
restart_command "powershell restart-service #{service_name} -Force"
91+
stop_command "powershell stop-service #{service_name} -Force"
92+
else
93+
supports :restart => true, :status => true, :start => true, :stop => true
94+
end
6495
supports :restart => true, :status => true, :start => true, :stop => true
65-
subscribes :restart, "template[#{system_probe_config_file}]", :delayed if node['datadog']['system_probe']['enabled']
96+
subscribes :restart, "template[#{system_probe_config_file}]", :delayed if sysprobe_enabled
6697
end

‎templates/default/system_probe.yaml.erb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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)
1111
}
1212
-%>
1313
# Generated by Chef, local modifications will be overwritten

0 commit comments

Comments
 (0)
Please sign in to comment.