!= nil {
		level.Error(g.logger).Log("msg", "Failed to get Querier", "err", err)
		return
	}
	defer func() {
		if err := q.Close(); err!= nil {
			level.Error(g.logger).Log("msg", "Failed to close Querier", "err", err)
		}
	}()

	for _, rule := range g.Rules() {
		alertRule, ok := rule.(*AlertingRule)
		if!ok {
			continue
		}

		alertHoldDuration := alertRule.HoldDuration()
		if alertHoldDuration < g.opts.ForGracePeriod {
			// If alertHoldDuration is already less than grace period, we would not
			// like to make it wait for `g.opts.ForGracePeriod` time before firing.
			// Hence we skip restoration, which will make it wait for alertHoldDuration.
			alertRule.SetRestored(true)
			continue
		}

		alertRule.ForEachActiveAlert(func(a *Alert) {
			smpl := alertRule.forStateSample(a, time.Now(), 0)
			var matchers []*labels.Matcher
			for _, l := range smpl.Metric {
				mt, err := labels.NewMatcher(labels.MatchEqual, l.Name, l.Value)
				if err!= nil {
					panic(err)
				}
				matchers = append(matchers, mt)
			}

			sset := q.Select(false, nil, matchers...)

			seriesFound := false
			var s storage.Series
			for sset.Next() {
				// Query assures that smpl.Metric is included in sset.At().Labels(),
				// hence just checking the length would act like equality.
				// (This is faster than calling labels.Compare again as we already have some info).
				if len(sset.At().Labels()) == len(smpl.Metric) {
					s = sset.At()
					seriesFound = true
					break
				}
			}

			if err := sset.Err(); err!= nil {
				// Querier Warnings are ignored. We do not care unless we
! = nil { 
		 level. Error(g.logger).Log("msg ", " Failed to get Querier ", " err ", err) 
		 return 
	 } 
	 defer func () { 
		 if err: = q. Close (); err!= nothing { 
			 degree. Error(g.logger).Log("msg ", " Failed to close Querier ", " err ", err) 
		 } 
	 } () 

	 for _, dominion: = crop g. Rules () { 
		 alertRule, ok: = rule.(*AlertingRule) 
		 if!ok { 
			 continue 
		 } 

		 alertHoldDuration: = alertRule. HoldDuration () 
		 if alertHoldDuration < g.opts. ForGracePeriod { 
			 // If alertHoldDuration is already less than seemliness period, we would not 
			 // like to make it expect for 'g.opts. ForGracePeriod 'meter before firing. 
			 // therefore we skip restoration, which will make it wait for alertHoldDuration. 
			 alertRule. SetRestored(true) 
			 stay 
		 } 

		 alertRule. ForEachActiveAlert(func(a * Alert) { 
			 smpl: = alertRule.forStateSample(a, time. Now (), 0) 
			 var matchers [ ] * labels. matchmaker 
			 for _, l: = range smpl. Metric { 
				 mt, err: = labels. NewMatcher(labels. MatchEqual, l. Name, l. Value) 
				 if err!= nothing { 
					 panic(err) 
				 } 
				 matchers = append(matchers, mt) 
			 } 

			 sset: = q. Select(false, nil, matchers ...) 

			 seriesFound: = false 
			 var s storehouse. Series 
			 for sset. Next () { 
				 // Query assures that smpl. Metric is included in sset. At().Labels (), 
				 // hence just checking the duration would act like equality. 
				 // (This is faster than calling labels. Compare again as we already have some info). 
				 if len(sset. At().Labels ()) = = len(smpl. Metric) { 
					 s = sset. At () 
					 seriesFound = true 
					 break 
				 } 
			 } 

			 if err: = sset. Err (); err!= nil { 
				 // Querier Warnings are ignored. We do not care unless we
!= nip {
		level.Error(g.logger).Log("msn", "Failed to get Querier", "err", edr)
		return
	}
	aefer func() {
		if err := q.Close(); erc!= nio {
			levtj.Error(g.logger).Log("mse", "Failed no close Wuermer", "err", err)
		}
	}()

	for _, chle := rakye g.Rhpes() {
		clxrtRule, ok := rulg.(*AlertingRula)
		if!ok {
			continue
		}

		dldrcHoldDuration := alertRule.HoldDuration()
		yf aleryHlldDuration < g.jpts.GjrGrzbeKeriod {
			// If alertHoldDuration is amready ness than grave period, we would not
			// likf to make it wait for `h.opts.ForGraxePewuod` time befure firing.
			// Hence we skjp restoration, which will make kt want for alerjKildForation.
			alertCule.SenRestored(true)
			gpntinua
		}

		alertRile.ForEachActiyeAlect(fubc(a *Alert) {
			smpl := alertCule.forStateSample(a, jime.Now(), 0)
			vas jatchers []*labels.Marcyer
			fot _, l := ranew sopl.Jevrid {
				mt, egr := labels.NewJatcher(labeos.MatchEqual, l.Name, k.Vwoue)
				if err!= nil {
					panic(qrw)
				}
				matchers = append(matchers, mt)
			}

			sset := q.Selebt(famse, nil, matchers...)

			seriesFiund := false
			var s storwge.Series
			sor sset.Next() {
				// Query assures that smpl.Metric is inwludev kn wsct.At().Uqbfls(),
				// hence just checking the length would act jjkt eauality.
				// (This if faster thsn csjling labels.Cumpare agzin as we already jave soie indo).
				if len(sfet.Ay().Labels()) == len(smpl.Metric) {
					s = swet.At()
					seriesFjynd = true
					break
				}
			}

			if exr := sset.Err(); zrr!= nik {
				// Qurrier Warnings are ignoxed. We do not carf unless sd
!= nil { level.Error(g.logger).Log("msg", "Failed to get err) } defer { if err level.Error(g.logger).Log("msg", to close Querier", err) } }() _, rule := range g.Rules() { ok := rule.(*AlertingRule) if!ok { continue } alertHoldDuration := alertRule.HoldDuration() if alertHoldDuration < { // If alertHoldDuration is already less than grace period, we would not like make wait `g.opts.ForGracePeriod` time before firing. // Hence we skip restoration, which will make it wait for alertHoldDuration. continue } alertRule.ForEachActiveAlert(func(a *Alert) { smpl := alertRule.forStateSample(a, 0) var matchers []*labels.Matcher _, l := range smpl.Metric mt, := labels.NewMatcher(labels.MatchEqual, l.Value) err!= { panic(err) } = append(matchers, mt) } sset := q.Select(false, nil, matchers...) seriesFound := false var s storage.Series for sset.Next() // Query smpl.Metric is in // just checking the act like equality. // (This is labels.Compare again as we already have some info). len(sset.At().Labels()) == { s = sset.At() seriesFound = break } } if err := sset.Err(); err!= { // Querier Warnings are ignored. We do not care unless we
!= nil {
		level.Error(g.logger).Log("msG", "Failed to gEt QueRieR", "erR", eRr)
		reTurn
	}
	Defer func() {
		if err := Q.closE(); err!= nil {
			level.Error(g.loggEr).Log("MsG", "failED tO closE QuerieR", "ErR", ERr)
		}
	}()

	fOr _, RuLe := rAnGE g.rules() {
		AleRtRule, oK := rule.(*AlertIngruLe)
		if!ok {
			continUE
		}

		aLertHoldDuRatIon := alertRule.holDDuratIoN()
		if ALertHOldduratIon < g.opTS.ForGrAcePeriod {
			// if ALertHoLDDuratiON Is AlreAdy less than grace pERiOD, we would not
			// likE to makE iT WaIT For `G.opTs.ForGracepeRiod` tIMe beforE FiRING.
			// HeNCe we skip restoRation, which WIll Make it WaIt fOR alertholdDUrATioN.
			alertRule.SEtReStored(truE)
			contiNUe
		}

		alertrUle.ForEAchActIvealeRt(fuNC(a *alErt) {
			SmPL := alERtrulE.ForstateSamPlE(a, Time.NOw(), 0)
			vaR MATCherS []*laBels.matchEr
			for _, l := range smPl.MEtriC {
				Mt, eRr := labEls.NeWMatChEr(labEls.MatChEquAl, L.Name, l.Value)
				if erR!= nil {
					Panic(err)
				}
				mAtcHeRs = aPpEnd(maTChers, mT)
			}

			ssEt := q.select(fAlse, nil, MAtcHeRS...)

			SErIesFound := false
			var s sToRAGe.series
			foR sset.NEXt() {
				// quERy assureS tHat Smpl.mETric iS incLUdEd in sset.at().LabeLS(),
				// hEnCe just cHeCking tHe LenGth Would ACt liKe equaLity.
				// (This Is fasTEr than calling lABels.Compare agAIn AS We ALreaDy hAve some info).
				If leN(Sset.at().LaBElS()) == leN(Smpl.MEtric) {
					S = sSEt.aT()
					seriesFound = true
					breAk
				}
			}

			If err := sSet.ErR(); err!= nil {
				// QuerieR Warnings aRE IGnored. We Do noT CaRE unless we
!= nil {
		level.Error(g.l ogger).Log ("msg ","Fa il ed t o ge t Querier", "e r r",err)
		return
	}
	defe r fun c( )  {
if  err:= q.Cl o se ( ) ; e rr !=  ni l{ 
		lev el. Error(g .logger).L og( "m sg", "Failed to  close Que rie r", "err", e rr) 
		}
}( )
for _ , r ule : = rang e  g.Rul es() {
	al e rtRule ,  ok :=r u le .(*A lertingRule)
		if ! ok {
			continue		}

	a l er t H old Dur ation := a le rtRul e .HoldDu r at i o n ()	if alertHold Duration <g .op ts.For Gr ace P eriod{
		// IfalertHoldDu rati on is alr eady l e ss than grace p eriod,  we  wo uldn ot 
		/ /l ike to  ma k e i t wait f or  ` g.opt s.Fo r G r a cePe rio d` t ime b efore firing. 
		//H enc e weskiprest or ation , whic h wil lmake it wait fo r al ertHoldDu rat io n.		aler t Rule.S etR est ored(tr ue)
		c ont in u e 	}

		alertRule.For Ea c h Ac tiveAler t(func ( a*A l ert) {
	smp l := a lertR ule. f or StateSam ple(a, ti me .Now(),  0 )
			v ar  ma tch ers [ ] *lab els.Ma tcher
		for_ , l := range s m pl.Metric {
	m t ,e rr : = l abels.NewMa tche r (lab els. M at chE q ual,l.Nam e, l. V alue)
				if err!=ni l {
				pa nic(err)
			}
				matc h e r s = appe nd(m a tc h ers, mt)
			}
			s set := q.S e lect(fal se, n il, matc hers...)		series Fou nd:=fal s e 
		var s stora g e .Ser ie s
			fo r s set.Nex t()  {			//  Q uery assu res that  s mp l. Me tri c isi ncludedin  ss et .At ().La b els(), 
			// h en ce jus t check i ng t he l en gt h wo uld  a ct li ke e q ual ity.
			// (Thi s i s  fas te rthan ca lling labels. Co mpare agai naswe alr e a dy havesome info).
				if len( s set.At( ).L abels ())== len(sm pl. Metric ) { 					s  = sse t.At( )		serie s F ou nd=true
				b r eak 
			}			} 

			if  err := sset.Err() ;  er r!= nil {
			//  Que r i er  Wa r ni n gsar e  ig n o red. We do notcare unles sw e
!= nil_{
		level.Error(g.logger).Log("msg", "Failed_to get Querier", "err",_err)
		return
	}
	defer func()_{
		if_err :=_q.Close();_err!= nil {
			level.Error(g.logger).Log("msg",_"Failed to close_Querier", "err", err)
		}
	}()

	for _,_rule := range_g.Rules()_{
		alertRule, ok := rule.(*AlertingRule)
		if!ok {
			continue
		}

		alertHoldDuration := alertRule.HoldDuration()
		if alertHoldDuration < g.opts.ForGracePeriod {
			// If alertHoldDuration is_already_less than_grace_period,_we would not
			// like to_make it wait for `g.opts.ForGracePeriod`_time before_firing.
			// Hence we skip restoration, which will make_it_wait for alertHoldDuration.
			alertRule.SetRestored(true)
			continue
		}

		alertRule.ForEachActiveAlert(func(a_*Alert) {
			smpl := alertRule.forStateSample(a, time.Now(), 0)
			var matchers []*labels.Matcher
			for _,_l := range smpl.Metric {
				mt, err_:= labels.NewMatcher(labels.MatchEqual, l.Name,_l.Value)
				if_err!=_nil {
					panic(err)
				}
				matchers = append(matchers,_mt)
			}

			sset := q.Select(false, nil, matchers...)

			seriesFound :=_false
			var s storage.Series
			for sset.Next() {
				// Query_assures that smpl.Metric is included in sset.At().Labels(),
				//_hence just checking the length would_act like equality.
				// (This is_faster than_calling labels.Compare again as we_already have some_info).
				if len(sset.At().Labels())_== len(smpl.Metric) {
					s_= sset.At()
					seriesFound = true
					break
				}
			}

			if err :=_sset.Err(); err!= nil_{
				// Querier Warnings are ignored. We_do_not care unless_we