Skip to content

Commit a4bd599

Browse files
committed
Make origin detection methods private
1 parent 29f4f08 commit a4bd599

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/datadog/statsd/origin_detection.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module Datadog
22
class Statsd
3+
private
4+
35
CGROUPV1BASECONTROLLER = "memory"
46
HOSTCGROUPNAMESPACEINODE = 0xEFFFFFFB
57

6-
def is_host_cgroup_namespace?
8+
def host_cgroup_namespace?
79
stat = File.stat("/proc/self/ns/cgroup") rescue nil
810
return false unless stat
911
stat.ino == HOSTCGROUPNAMESPACEINODE
@@ -48,8 +50,6 @@ def get_cgroup_inode(cgroup_mount_path, proc_self_cgroup_path)
4850
nil
4951
end
5052

51-
private
52-
5353
def inode_for_path(path)
5454
stat = File.stat(path) rescue nil
5555
return nil unless stat
@@ -74,8 +74,6 @@ def parse_container_id(handle)
7474
nil
7575
end
7676

77-
public
78-
7977
def read_container_id(fpath)
8078
handle = File.open(fpath, 'r') rescue nil
8179
return nil unless handle
@@ -148,7 +146,7 @@ def get_container_id(user_provided_id, cgroup_fallback)
148146
container_id = read_mount_info("/proc/self/mountinfo")
149147
return container_id unless container_id.nil?
150148

151-
return nil if is_host_cgroup_namespace?
149+
return nil if host_cgroup_namespace?
152150

153151
get_cgroup_inode("/sys/fs/cgroup", "/proc/self/cgroup")
154152
end

spec/statsd/origin_detection_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def ino
3636
4:blkio:/kubepods/burstable/podfd52ef25-a87d-11e9-9423-0800271a638e/8c046cb0b72cd4c99f51b5591cd5b095967f58ee003710a45280c28ee1a9c7fa
3737
CGROUP
3838

39-
container_id = subject.get_container_id(nil, true)
39+
container_id = subject.send(:get_container_id, nil, true)
4040
end
4141

4242
expect(container_id).to eq('8c046cb0b72cd4c99f51b5591cd5b095967f58ee003710a45280c28ee1a9c7fa')
@@ -103,7 +103,7 @@ def ino
103103
FileUtils.mkdir_p('/proc/self')
104104
File.write('/proc/self/cgroup', test_case[:input])
105105

106-
result = subject.read_container_id('/proc/self/cgroup')
106+
result = subject.send(:read_container_id, '/proc/self/cgroup')
107107
end
108108
expect(result).to eq(test_case[:expected])
109109
end
@@ -123,7 +123,7 @@ def ino
123123

124124
File.write('/proc/self/cgroup', "")
125125

126-
container_id = subject.get_container_id(nil, true)
126+
container_id = subject.send(:get_container_id, nil, true)
127127
end
128128

129129
expect(container_id).to eq("fc7038bc73a8d3850c66ddbfb0b2901afa378bfcbb942cc384b051767e4ac6b0")
@@ -305,7 +305,7 @@ def ino
305305
FakeFS.with_fresh do
306306
FileUtils.mkdir_p('/proc/self')
307307
File.write('/proc/self/mountinfo', test_case[:input])
308-
result = subject.read_mount_info('/proc/self/mountinfo')
308+
result = subject.send(:read_mount_info, '/proc/self/mountinfo')
309309
end
310310

311311
expect(result).to eq(test_case[:expected])
@@ -347,7 +347,7 @@ def ino
347347
File.write('/proc/self/mountinfo', mountinfo_contents)
348348
File.write('/proc/self/cgroup', '') # Needed if get_container_id uses it
349349

350-
container_id = subject.get_container_id(nil, true)
350+
container_id = subject.send(:get_container_id, nil, true)
351351
end
352352

353353
expect(container_id).to eq(cid)
@@ -386,7 +386,7 @@ def ino
386386

387387
test_cases.each do |test_case|
388388
it "parses correctly for: #{test_case[:name]}" do
389-
result = subject.parse_cgroup_node_path(test_case[:content])
389+
result = subject.send(:parse_cgroup_node_path, test_case[:content])
390390
expect(result).to eq(test_case[:expected])
391391
end
392392
end
@@ -463,7 +463,7 @@ def ino
463463
test_case[:expected_result] = test_case[:expected_result].gsub("{inode}", inode.to_s)
464464
end
465465

466-
result = subject.get_cgroup_inode('/sys/fs/cgroup', '/proc/self/cgroup')
466+
result = subject.send(:get_cgroup_inode, '/sys/fs/cgroup', '/proc/self/cgroup')
467467
end
468468

469469
expect(result).to eq(test_case[:expected_result])
@@ -518,7 +518,7 @@ def ino
518518
File.write('/proc/self/cgroup', test_case[:proc_self_cgroup_content].to_s)
519519
File.write('/proc/self/mountinfo', test_case[:mount_info_content].to_s)
520520

521-
allow(subject).to receive(:is_host_cgroup_namespace?)
521+
allow(subject).to receive(:host_cgroup_namespace?)
522522
.and_return(test_case[:is_host_cgroup_ns] || false)
523523

524524
if test_case[:cgroup_node_dir]
@@ -532,7 +532,7 @@ def ino
532532
end
533533
end
534534

535-
container_id = subject.get_container_id(nil, true)
535+
container_id = subject.send(:get_container_id, nil, true)
536536
end
537537

538538
expect(container_id).to eq(test_case[:expected_result])

0 commit comments

Comments
 (0)