@@ -86,9 +86,7 @@ handle_event(internal, #xmlel{name = <<"handshake">>} = El, wait_for_handshake,
86
86
handle_event (internal , # xmlel {} = El , stream_established , StateData ) ->
87
87
execute_element_event (component_element_in , El , StateData ),
88
88
handle_stream_established (StateData , El );
89
- handle_event (internal , # xmlstreamend {name = Name }, _ , StateData ) ->
90
- StreamEnd = # xmlel {name = Name },
91
- execute_element_event (component_element_in , StreamEnd , StateData ),
89
+ handle_event (internal , # xmlstreamend {}, _ , StateData ) ->
92
90
send_trailer (StateData ),
93
91
{stop , {shutdown , stream_end }};
94
92
handle_event (internal , # xmlstreamstart {}, _ , StateData ) ->
@@ -203,7 +201,6 @@ handle_stream_start(S0, Attrs) ->
203
201
IsSubdomain = <<" true" >> =:= maps :get (<<" is_subdomain" >>, Attrs , <<>>),
204
202
S1 = S0 # component_data {lserver = LServer , is_subdomain = IsSubdomain },
205
203
send_header (S1 ),
206
- execute_element_event (component_element_in , Attrs , S1 ),
207
204
{next_state , wait_for_handshake , S1 , state_timeout (S1 )};
208
205
{? NS_COMPONENT_ACCEPT , error } ->
209
206
stream_start_error (S0 , mongoose_xmpp_errors :host_unknown ());
@@ -408,12 +405,12 @@ close_parser(#component_data{parser = Parser}) ->
408
405
-spec send_xml (data (), exml_stream :element () | [exml_stream :element ()]) -> maybe_ok ().
409
406
send_xml (Data , XmlElement ) when is_tuple (XmlElement ) ->
410
407
send_xml (Data , [XmlElement ]);
411
- send_xml (# component_data {lserver = LServer , socket = Socket } = StateData , XmlElements ) when is_list (XmlElements ) ->
412
- [ begin
413
- execute_element_event (component_element_out , El , StateData ),
414
- mongoose_instrument :execute (
415
- xmpp_element_size_out , labels (), #{byte_size => exml :xml_size (El ), lserver => LServer })
416
- end || El <- XmlElements ],
408
+ send_xml (# component_data {lserver = LServer , socket = Socket }, XmlElements ) when is_list (XmlElements ) ->
409
+ [begin
410
+ execute_element_event (component_element_out , Element , LServer ),
411
+ mongoose_instrument :execute (
412
+ xmpp_element_size_out , labels (), #{byte_size => exml :xml_size (Element ), lserver => LServer })
413
+ end || Element = # xmlel {} <- XmlElements ],
417
414
mongoose_xmpp_socket :send_xml (Socket , XmlElements ).
418
415
419
416
state_timeout (# component_data {listener_opts = LOpts }) ->
@@ -443,35 +440,10 @@ unregister_routes(#component_data{component = Component}) ->
443
440
mongoose_component :unregister_component (Component ).
444
441
445
442
% %% Instrumentation helpers
446
- -spec execute_element_event (
447
- mongoose_instrument :event_name (), exml :attrs () | exml_stream :element (), data ()) -> ok .
448
- execute_element_event (EventName , # xmlel {name = Name } = El , # component_data {lserver = LServer }) ->
449
- Metrics = measure_element (Name , exml_query :attr (El , <<" type" >>)),
450
- Measurements = Metrics #{element => El , lserver => LServer },
451
- mongoose_instrument :execute (EventName , #{}, Measurements );
452
- execute_element_event (EventName , El , # component_data {lserver = LServer }) ->
453
- Measurements = #{count => 1 , element => El , lserver => LServer },
454
- mongoose_instrument :execute (EventName , #{}, Measurements );
455
- execute_element_event (_ , _ , _ ) ->
456
- ok .
457
-
458
- -spec measure_element (binary (), binary () | undefined ) -> mongoose_instrument :measurements ().
459
- measure_element (<<" message" >>, <<" error" >>) ->
460
- #{count => 1 , stanza_count => 1 , error_count => 1 , message_error_count => 1 };
461
- measure_element (<<" iq" >>, <<" error" >>) ->
462
- #{count => 1 , stanza_count => 1 , error_count => 1 , iq_error_count => 1 };
463
- measure_element (<<" presence" >>, <<" error" >>) ->
464
- #{count => 1 , stanza_count => 1 , error_count => 1 , presence_error_count => 1 };
465
- measure_element (<<" message" >>, _Type ) ->
466
- #{count => 1 , stanza_count => 1 , message_count => 1 };
467
- measure_element (<<" iq" >>, _Type ) ->
468
- #{count => 1 , stanza_count => 1 , iq_count => 1 };
469
- measure_element (<<" presence" >>, _Type ) ->
470
- #{count => 1 , stanza_count => 1 , presence_count => 1 };
471
- measure_element (<<" stream:error" >>, _Type ) ->
472
- #{count => 1 , error_count => 1 };
473
- measure_element (_Name , _Type ) ->
474
- #{count => 1 }.
443
+ -spec execute_element_event (mongoose_instrument :event_name (), exml :element (), jid :lserver ()) -> ok .
444
+ execute_element_event (EventName , Element , LServer ) ->
445
+ Measurements = mongoose_measurements :measure_element (Element ),
446
+ mongoose_instrument :execute (EventName , #{}, Measurements #{lserver => LServer }).
475
447
476
448
-spec labels () -> mongoose_instrument :labels ().
477
449
labels () ->
0 commit comments