@@ -938,8 +938,11 @@ func TestScrapeMetrics_MuteErrorFlags(t *testing.T) {
938
938
muteProcessNameError bool
939
939
muteProcessExeError bool
940
940
muteProcessIOError bool
941
+ muteProcessUserError bool
942
+ skipProcessNameError bool
941
943
omitConfigField bool
942
944
expectedError string
945
+ expectedCount int
943
946
}
944
947
945
948
testCases := []testCase {
@@ -948,6 +951,7 @@ func TestScrapeMetrics_MuteErrorFlags(t *testing.T) {
948
951
muteProcessNameError : true ,
949
952
muteProcessExeError : true ,
950
953
muteProcessIOError : true ,
954
+ muteProcessUserError : true ,
951
955
},
952
956
{
953
957
name : "Process Name Error Muted And Process Exe Error Enabled And Process IO Error Muted" ,
@@ -994,6 +998,23 @@ func TestScrapeMetrics_MuteErrorFlags(t *testing.T) {
994
998
fmt .Sprintf ("error reading process name for pid 1: %v" , processNameError )
995
999
}(),
996
1000
},
1001
+ {
1002
+ name : "Process User Error Muted" ,
1003
+ muteProcessUserError : true ,
1004
+ skipProcessNameError : true ,
1005
+ muteProcessExeError : true ,
1006
+ muteProcessNameError : true ,
1007
+ expectedCount : 4 ,
1008
+ },
1009
+ {
1010
+ name : "Process User Error Unmuted" ,
1011
+ muteProcessUserError : false ,
1012
+ skipProcessNameError : true ,
1013
+ muteProcessExeError : true ,
1014
+ muteProcessNameError : true ,
1015
+ expectedError : fmt .Sprintf ("error reading username for process \" processname\" (pid 1): %v" , processNameError ),
1016
+ expectedCount : 4 ,
1017
+ },
997
1018
}
998
1019
999
1020
for _ , test := range testCases {
@@ -1003,14 +1024,26 @@ func TestScrapeMetrics_MuteErrorFlags(t *testing.T) {
1003
1024
config .MuteProcessNameError = test .muteProcessNameError
1004
1025
config .MuteProcessExeError = test .muteProcessExeError
1005
1026
config .MuteProcessIOError = test .muteProcessIOError
1027
+ config .MuteProcessUserError = test .muteProcessUserError
1006
1028
}
1007
1029
scraper , err := newProcessScraper (receivertest .NewNopCreateSettings (), config )
1008
1030
require .NoError (t , err , "Failed to create process scraper: %v" , err )
1009
1031
err = scraper .start (context .Background (), componenttest .NewNopHost ())
1010
1032
require .NoError (t , err , "Failed to initialize process scraper: %v" , err )
1011
1033
1012
- handleMock := & processHandleMock {}
1013
- handleMock .On ("NameWithContext" , mock .Anything ).Return ("test" , processNameError )
1034
+ handleMock := newDefaultHandleMock ()
1035
+ if ! test .skipProcessNameError {
1036
+ handleMock .On ("NameWithContext" , mock .Anything ).Return ("test" , processNameError )
1037
+ } else {
1038
+ for _ , c := range handleMock .ExpectedCalls {
1039
+ if c .Method == "UsernameWithContext" {
1040
+ c .ReturnArguments = []interface {}{"processname" , processNameError }
1041
+ break
1042
+ }
1043
+ }
1044
+ handleMock .On ("NameWithContext" , mock .Anything ).Return ("processname" , nil )
1045
+ handleMock .On ("CreateTimeWithContext" , mock .Anything ).Return (time .Now ().UnixMilli (), nil )
1046
+ }
1014
1047
handleMock .On ("ExeWithContext" , mock .Anything ).Return ("test" , processNameError )
1015
1048
handleMock .On ("CmdlineWithContext" , mock .Anything ).Return ("test" , processNameError )
1016
1049
@@ -1023,9 +1056,9 @@ func TestScrapeMetrics_MuteErrorFlags(t *testing.T) {
1023
1056
}
1024
1057
md , err := scraper .scrape (context .Background ())
1025
1058
1026
- assert .Zero ( t , md .MetricCount ())
1059
+ assert .Equal ( t , test . expectedCount , md .MetricCount ())
1027
1060
1028
- if config .MuteProcessNameError && config .MuteProcessExeError {
1061
+ if config .MuteProcessNameError && config .MuteProcessExeError && config . MuteProcessUserError {
1029
1062
assert .Nil (t , err )
1030
1063
} else {
1031
1064
assert .EqualError (t , err , test .expectedError )
0 commit comments