@@ -1003,6 +1003,147 @@ def test_set_from_bool(
10031003 assert self .standart_options .span_filters == {"exclude" : INTERNAL_SPAN_FILTERS }
10041004 assert not self .standart_options .extra_http_headers
10051005
1006+ def test_default_poll_rate (self ) -> None :
1007+ """Test that default poll_rate is 1 second"""
1008+ self .standart_options = StandardOptions ()
1009+ assert self .standart_options .poll_rate == 1
1010+
1011+ def test_set_from_with_valid_poll_rate_1 (
1012+ self ,
1013+ caplog : pytest .LogCaptureFixture ,
1014+ ) -> None :
1015+ """Test setting poll_rate to 1 from announce response"""
1016+ caplog .set_level (logging .DEBUG , logger = "instana" )
1017+ caplog .clear ()
1018+
1019+ self .standart_options = StandardOptions ()
1020+ test_res_data = {"plugin" : {"python" : {"poll_rate" : 1 }}}
1021+ self .standart_options .set_from (test_res_data )
1022+
1023+ assert self .standart_options .poll_rate == 1
1024+ assert "Poll rate set to 1 seconds from agent configuration" in caplog .messages
1025+
1026+ def test_set_from_with_valid_poll_rate_5 (
1027+ self ,
1028+ caplog : pytest .LogCaptureFixture ,
1029+ ) -> None :
1030+ """Test setting poll_rate to 5 from announce response"""
1031+ caplog .set_level (logging .DEBUG , logger = "instana" )
1032+ caplog .clear ()
1033+
1034+ self .standart_options = StandardOptions ()
1035+ test_res_data = {"plugin" : {"python" : {"poll_rate" : 5 }}}
1036+ self .standart_options .set_from (test_res_data )
1037+
1038+ assert self .standart_options .poll_rate == 5
1039+ assert "Poll rate set to 5 seconds from agent configuration" in caplog .messages
1040+
1041+ def test_set_from_with_invalid_poll_rate_defaults_to_1 (
1042+ self ,
1043+ caplog : pytest .LogCaptureFixture ,
1044+ ) -> None :
1045+ """Test that invalid poll_rate values default to 1"""
1046+ caplog .set_level (logging .DEBUG , logger = "instana" )
1047+
1048+ # Test with poll_rate = 10
1049+ caplog .clear ()
1050+ self .standart_options = StandardOptions ()
1051+ test_res_data = {"plugin" : {"python" : {"poll_rate" : 10 }}}
1052+ self .standart_options .set_from (test_res_data )
1053+ assert self .standart_options .poll_rate == 1
1054+ assert "Invalid poll_rate value 10, defaulting to 1" in caplog .messages
1055+
1056+ # Test with poll_rate = 0
1057+ caplog .clear ()
1058+ self .standart_options = StandardOptions ()
1059+ test_res_data = {"plugin" : {"python" : {"poll_rate" : 0 }}}
1060+ self .standart_options .set_from (test_res_data )
1061+ assert self .standart_options .poll_rate == 1
1062+ assert "Invalid poll_rate value 0, defaulting to 1" in caplog .messages
1063+
1064+ # Test with poll_rate = -5
1065+ caplog .clear ()
1066+ self .standart_options = StandardOptions ()
1067+ test_res_data = {"plugin" : {"python" : {"poll_rate" : - 5 }}}
1068+ self .standart_options .set_from (test_res_data )
1069+ assert self .standart_options .poll_rate == 1
1070+ assert "Invalid poll_rate value -5, defaulting to 1" in caplog .messages
1071+
1072+ # Test with poll_rate = 3
1073+ caplog .clear ()
1074+ self .standart_options = StandardOptions ()
1075+ test_res_data = {"plugin" : {"python" : {"poll_rate" : 3 }}}
1076+ self .standart_options .set_from (test_res_data )
1077+ assert self .standart_options .poll_rate == 1
1078+ assert "Invalid poll_rate value 3, defaulting to 1" in caplog .messages
1079+
1080+ def test_set_from_with_invalid_poll_rate_type (
1081+ self ,
1082+ caplog : pytest .LogCaptureFixture ,
1083+ ) -> None :
1084+ """Test that non-integer poll_rate values default to 1"""
1085+ caplog .set_level (logging .DEBUG , logger = "instana" )
1086+
1087+ # Test with string
1088+ caplog .clear ()
1089+ self .standart_options = StandardOptions ()
1090+ test_res_data = {"plugin" : {"python" : {"poll_rate" : "invalid" }}}
1091+ self .standart_options .set_from (test_res_data )
1092+ assert self .standart_options .poll_rate == 1
1093+ assert "Invalid poll_rate type, defaulting to 1" in caplog .messages
1094+
1095+ # Test with None
1096+ caplog .clear ()
1097+ self .standart_options = StandardOptions ()
1098+ test_res_data = {"plugin" : {"python" : {"poll_rate" : None }}}
1099+ self .standart_options .set_from (test_res_data )
1100+ assert self .standart_options .poll_rate == 1
1101+
1102+ def test_set_from_without_poll_rate (self ) -> None :
1103+ """Test that poll_rate remains default when not in response"""
1104+ self .standart_options = StandardOptions ()
1105+ test_res_data = {
1106+ "secrets" : {"matcher" : "sample-match" , "list" : ["sample" , "list" ]}
1107+ }
1108+ self .standart_options .set_from (test_res_data )
1109+ assert self .standart_options .poll_rate == 1
1110+
1111+ def test_set_from_with_poll_rate_and_other_config (
1112+ self ,
1113+ caplog : pytest .LogCaptureFixture ,
1114+ ) -> None :
1115+ """Test that poll_rate works alongside other configuration"""
1116+ caplog .set_level (logging .DEBUG , logger = "instana" )
1117+ caplog .clear ()
1118+
1119+ self .standart_options = StandardOptions ()
1120+ test_res_data = {
1121+ "plugin" : {"python" : {"poll_rate" : 5 }},
1122+ "secrets" : {"matcher" : "sample-match" , "list" : ["sample" , "list" ]},
1123+ "tracing" : {
1124+ "filter" : {
1125+ "exclude" : [
1126+ {
1127+ "name" : "service1" ,
1128+ "attributes" : [
1129+ {
1130+ "key" : "service" ,
1131+ "values" : ["service1" ],
1132+ "match_type" : "strict" ,
1133+ }
1134+ ],
1135+ }
1136+ ]
1137+ }
1138+ },
1139+ }
1140+ self .standart_options .set_from (test_res_data )
1141+
1142+ assert self .standart_options .poll_rate == 5
1143+ assert self .standart_options .secrets_matcher == "sample-match"
1144+ assert self .standart_options .secrets_list == ["sample" , "list" ]
1145+ assert "Poll rate set to 5 seconds from agent configuration" in caplog .messages
1146+
10061147
10071148class TestServerlessOptions :
10081149 @pytest .fixture (autouse = True )
0 commit comments