@@ -667,6 +667,14 @@ func TestSelfMonitor_reportOutputHealthyState(t *testing.T) {
667
667
}
668
668
return doc .Message == "" && doc .State == client .UnitStateHealthy .String ()
669
669
}), mock .Anything ).Return ("" , nil )
670
+ bulker .On ("Search" , mock .Anything , dl .FleetPolicies , mock .Anything , mock .Anything ).Return (
671
+ & es.ResultT {
672
+ HitsT : es.HitsT {
673
+ Hits : []es.HitT {
674
+ {Source : []byte (`{"data": {"outputs":{"remote":{"type":"remote_elasticsearch","hosts":["http://localhost:9200"]}}}}` )},
675
+ },
676
+ },
677
+ }, nil )
670
678
671
679
reportOutputHealth (ctx , bulker , logger )
672
680
@@ -696,6 +704,58 @@ func TestSelfMonitor_reportOutputDegradedState(t *testing.T) {
696
704
}
697
705
return doc .Message == "remote ES is not reachable due to error: error connecting" && doc .State == client .UnitStateDegraded .String ()
698
706
}), mock .Anything ).Return ("" , nil )
707
+ bulker .On ("Search" , mock .Anything , dl .FleetPolicies , mock .Anything , mock .Anything ).Return (
708
+ & es.ResultT {
709
+ HitsT : es.HitsT {
710
+ Hits : []es.HitT {
711
+ {Source : []byte (`{"data": {"outputs":{"remote":{"type":"remote_elasticsearch","hosts":["http://localhost:9200"]}}}}` )},
712
+ },
713
+ },
714
+ }, nil )
715
+
716
+ reportOutputHealth (ctx , bulker , logger )
717
+
718
+ bulker .AssertExpectations (t )
719
+ outputBulker .AssertExpectations (t )
720
+ }
721
+
722
+ func TestSelfMonitor_reportOutputSkipIfOutdated (t * testing.T ) {
723
+ ctx , cancel := context .WithCancel (context .Background ())
724
+ defer cancel ()
725
+ logger := testlog .SetLogger (t )
726
+
727
+ bulker := ftesting .NewMockBulk ()
728
+ bulkerMap := make (map [string ]bulk.Bulk )
729
+ outputBulker := ftesting .NewMockBulk ()
730
+ bulkerMap ["outdated" ] = outputBulker
731
+ bulker .On ("GetBulkerMap" ).Return (bulkerMap )
732
+ bulker .On ("Search" , mock .Anything , dl .FleetPolicies , mock .Anything , mock .Anything ).Return (
733
+ & es.ResultT {
734
+ HitsT : es.HitsT {
735
+ Hits : []es.HitT {
736
+ {Source : []byte (`{"data": {"outputs":{"outdated":{"type":"remote_elasticsearch","hosts":["http://localhost:9200"]}}}}` )},
737
+ },
738
+ },
739
+ }, nil )
740
+
741
+ reportOutputHealth (ctx , bulker , logger )
742
+
743
+ bulker .AssertExpectations (t )
744
+ outputBulker .AssertExpectations (t )
745
+ }
746
+
747
+ func TestSelfMonitor_reportOutputSkipIfNotFound (t * testing.T ) {
748
+ ctx , cancel := context .WithCancel (context .Background ())
749
+ defer cancel ()
750
+ logger := testlog .SetLogger (t )
751
+
752
+ bulker := ftesting .NewMockBulk ()
753
+ bulkerMap := make (map [string ]bulk.Bulk )
754
+ outputBulker := ftesting .NewMockBulk ()
755
+ bulkerMap ["outdated" ] = outputBulker
756
+ bulker .On ("GetBulkerMap" ).Return (bulkerMap )
757
+ bulker .On ("Search" , mock .Anything , dl .FleetPolicies , mock .Anything , mock .Anything ).Return (
758
+ & es.ResultT {}, errors .New ("output not found" ))
699
759
700
760
reportOutputHealth (ctx , bulker , logger )
701
761
0 commit comments