1
- =begin
2
- This file is part of Hopsworks
3
- Copyright (C) 2021, Logical Clocks AB. All rights reserved
1
+ # This file is part of Hopsworks
2
+ # Copyright (C) 2024, Hopsworks AB. All rights reserved
3
+ #
4
+ # Hopsworks is free software: you can redistribute it and/or modify it under the terms of
5
+ # the GNU Affero General Public License as published by the Free Software Foundation,
6
+ # either version 3 of the License, or (at your option) any later version.
7
+ #
8
+ # Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9
+ # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
+ # PURPOSE. See the GNU Affero General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Affero General Public License along with this program.
13
+ # If not, see <https://www.gnu.org/licenses/>.
14
+ #
4
15
5
- Hopsworks is free software: you can redistribute it and/or modify it under the terms of
6
- the GNU Affero General Public License as published by the Free Software Foundation,
7
- either version 3 of the License, or (at your option) any later version.
16
+ describe "On #{ ENV [ 'OS' ] } " do
8
17
9
- Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11
- PURPOSE. See the GNU Affero General Public License for more details.
18
+ before :all do
19
+ # ensure feature monitoring is enabled
20
+ @enable_feature_monitoring = getVar ( 'enable_feature_monitoring' )
21
+ setVar ( 'enable_feature_monitoring' , "true" )
22
+ end
12
23
13
- You should have received a copy of the GNU Affero General Public License along with this program.
14
- If not, see <https://www.gnu.org/licenses/>.
15
- =end
24
+ after :all do
25
+ # revert feature monitoring flag
26
+ setVar ( 'enable_feature_monitoring' , @enable_feature_monitoring [ :value ] )
27
+ clean_all_test_projects ( spec : "fg_alert" )
28
+ end
16
29
17
- describe "On #{ ENV [ 'OS' ] } " do
18
- after ( :all ) { clean_all_test_projects ( spec : "fg_alert" ) }
19
30
describe 'Alert' do
20
31
context 'without authentication' do
21
32
before :all do
31
42
create_fg_alert ( @project , @featuregroup , get_fg_alert_success ( @project ) )
32
43
expect_status_details ( 401 )
33
44
end
45
+ it "should fail to create feature monitoring status" do
46
+ create_fg_alert ( @project , @featuregroup , get_fm_alert_success ( @project ) )
47
+ expect_status_details ( 401 )
48
+ end
34
49
end
35
50
context 'with authentication' do
36
51
before :all do
37
52
with_valid_project
38
53
@featuregroup = with_valid_fg ( @project )
54
+ json_result = create_feature_view_from_feature_group ( @project . id , get_featurestore_id ( @project . id ) , @featuregroup )
55
+ @feature_view = JSON . parse ( json_result )
39
56
create_fg_alerts ( @project , @featuregroup )
57
+ create_fm_alerts ( @project , @featuregroup , @feature_view )
58
+
40
59
end
41
60
it "should get" do
42
61
get_fg_alerts ( @project , @featuregroup )
43
62
expect_status_details ( 200 )
44
- expect ( json_body [ :count ] ) . to eq ( 2 )
63
+ expect ( json_body [ :count ] ) . to eq ( 3 )
45
64
end
46
65
it "should update" do
47
66
get_fg_alerts ( @project , @featuregroup )
68
87
expect_status_details ( 201 )
69
88
check_route_created ( @project , alert [ :receiver ] , alert [ :status ] , fg : @featuregroup )
70
89
get_fg_alerts ( @project , @featuregroup )
71
- expect ( json_body [ :count ] ) . to eq ( 3 )
90
+ expect ( json_body [ :count ] ) . to eq ( 4 )
72
91
end
73
92
it "should fail to create duplicate" do
74
93
create_fg_alert ( @project , @featuregroup , get_fg_alert_warning ( @project ) )
81
100
expect_status_details ( 204 )
82
101
check_route_deleted ( @project , alert [ :receiver ] , alert [ :status ] , fg : @featuregroup )
83
102
get_fg_alerts ( @project , @featuregroup )
84
- expect ( json_body [ :count ] ) . to eq ( 2 )
103
+ expect ( json_body [ :count ] ) . to eq ( 3 )
104
+ end
105
+ it "should create alert with feature monitoring status" do
106
+ alert_data = get_fm_alert_success ( @project )
107
+ json_result = create_fg_alert ( @project , @featuregroup , alert_data )
108
+ parsed_alert_json = JSON . parse ( json_result )
109
+ expect_status_details ( 201 )
110
+ check_route_created_fm ( @project , alert_data [ :receiver ] , alert_data [ :status ] , fg : @featuregroup )
111
+ expect ( parsed_alert_json [ 'status' ] ) . to eql ( alert_data [ :status ] )
112
+ expect ( parsed_alert_json [ 'receiver' ] ) . to eql ( alert_data [ :receiver ] )
113
+ expect ( parsed_alert_json [ 'severity' ] ) . to eql ( alert_data [ :severity ] )
114
+ expect ( parsed_alert_json [ 'featureGroupId' ] ) . to eql ( @featuregroup [ "id" ] )
115
+ end
116
+ it "should create feature view monitoring alert" do
117
+ alert_data = get_fm_alert_success ( @project )
118
+ json_result = create_feature_view_alert ( @project , @feature_view , alert_data )
119
+ parsed_alert_json = JSON . parse ( json_result )
120
+ expect_status_details ( 201 )
121
+ expect ( parsed_alert_json [ 'status' ] ) . to eql ( alert_data [ :status ] )
122
+ expect ( parsed_alert_json [ 'receiver' ] ) . to eql ( alert_data [ :receiver ] )
123
+ expect ( parsed_alert_json [ 'severity' ] ) . to eql ( alert_data [ :severity ] )
124
+ expect ( parsed_alert_json [ 'featureViewName' ] ) . to eql ( @feature_view [ "name" ] )
125
+ expect ( parsed_alert_json [ 'featureViewVersion' ] ) . to eql ( @feature_view [ "version" ] )
126
+ check_route_created_fm ( @project , alert_data [ :receiver ] , alert_data [ :status ] , fv : @feature_view )
127
+ end
128
+ it "should get and update feature view monitoring alert" do
129
+ get_featureview_alerts ( @project , @feature_view )
130
+ expect_status_details ( 200 )
131
+ alert = json_body [ :items ] . detect { |a | a [ :status ] == "FEATURE_MONITOR_SHIFT_UNDETECTED" && a [ :featureViewId ]
132
+ . present? }
133
+ receiver_original = alert [ :receiver ]
134
+ alert [ :receiver ] = "#{ @project [ :projectname ] } __slack1"
135
+ json_result = update_featureview_alert ( @project , @feature_view , alert [ :id ] , alert )
136
+ expect_status_details ( 200 )
137
+ parsed_updated_alert = JSON . parse ( json_result )
138
+ expect ( parsed_updated_alert [ 'status' ] ) . to eql ( alert [ :status ] )
139
+ expect ( parsed_updated_alert [ 'receiver' ] ) . to eql ( alert [ :receiver ] )
140
+ expect ( parsed_updated_alert [ 'severity' ] ) . to eql ( alert [ :severity ] )
141
+ expect ( parsed_updated_alert [ 'featureViewName' ] ) . to eql ( @feature_view [ "name" ] )
142
+ expect ( parsed_updated_alert [ 'featureViewVersion' ] ) . to eql ( @feature_view [ "version" ] )
143
+ check_route_created_fm ( @project , alert [ :receiver ] , alert [ :status ] , fv : @feature_view )
144
+ check_route_deleted_fm ( @project , receiver_original , alert [ :status ] , fv : @feature_view )
85
145
end
86
146
it "should cleanup receivers and routes when deleting project" do
87
147
delete_project ( @project )
102
162
featuregroup = with_valid_fg ( project )
103
163
create_fg_alerts_global ( project , featuregroup )
104
164
get_fg_alerts ( project , featuregroup )
105
- expect ( json_body [ :count ] ) . to eq ( 3 )
165
+ expect ( json_body [ :count ] ) . to eq ( 5 )
106
166
alert_receiver = AlertReceiver . where ( "name LIKE '#{ project [ :projectname ] } __%'" )
107
167
expect ( alert_receiver . length ( ) ) . to eq ( 0 )
108
168
get_routes_admin ( )
161
221
end
162
222
end
163
223
end
164
- end
224
+ end
0 commit comments