@@ -289,18 +289,18 @@ func (p *Plugin) Init(instanceId string) error {
289289 in := & dcspb.SubscriptionRequest {
290290 InstanceId : instanceId ,
291291 }
292-
292+
293293 // Always start the goroutine, even if initial subscription fails
294294 go func () {
295295 var evStream dcspb.Configurator_SubscribeClient
296296 var err error
297-
297+
298298 for {
299299 // Try to establish subscription if we don't have one
300300 if evStream == nil {
301301 log .WithField ("endpoint" , viper .GetString ("dcsServiceEndpoint" )).
302302 Debug ("attempting to subscribe to DCS service" )
303-
303+
304304 evStream , err = p .dcsClient .Subscribe (context .Background (), in , grpc.EmptyCallOption {})
305305 if err != nil {
306306 log .WithField ("endpoint" , viper .GetString ("dcsServiceEndpoint" )).
@@ -699,7 +699,7 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
699699
700700 var stream dcspb.Configurator_StartOfRunClient
701701 timeout := callable .AcquireTimeout (DCS_GENERAL_OP_TIMEOUT , varStack , "PFR" , envId )
702- ctx , cancel := context . WithTimeout ( context . Background () , timeout )
702+ ctx , cancel := integration . NewContext ( envId , varStack , timeout )
703703 defer cancel ()
704704
705705 detectorStatusMap := make (map [dcspb.Detector ]dcspb.DetectorState )
@@ -746,7 +746,8 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
746746 return
747747 }
748748
749- err , payloadJson = PFRgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream , detectorStatusMap , callFailedStr , payload )
749+ err , payloadJson = PFRgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream ,
750+ detectorStatusMap , callFailedStr , payload , integration .ExtractRunTypeOrUndefined (varStack ))
750751
751752 dcsFailedEcsDetectors := make ([]string , 0 )
752753 dcsopOk := true
@@ -1064,7 +1065,7 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
10641065
10651066 var stream dcspb.Configurator_StartOfRunClient
10661067 timeout := callable .AcquireTimeout (DCS_GENERAL_OP_TIMEOUT , varStack , "SOR" , envId )
1067- ctx , cancel := context . WithTimeout ( context . Background () , timeout )
1068+ ctx , cancel := integration . NewContext ( envId , varStack , timeout )
10681069 defer cancel ()
10691070
10701071 detectorStatusMap := make (map [dcspb.Detector ]dcspb.DetectorState )
@@ -1112,7 +1113,8 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
11121113 }
11131114 p .pendingEORs [envId ] = runNumber64 // make sure the corresponding EOR runs sooner or later
11141115
1115- err , payloadJson = SORgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream , detectorStatusMap , callFailedStr , payload )
1116+ err , payloadJson = SORgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream ,
1117+ detectorStatusMap , callFailedStr , payload , integration .ExtractRunTypeOrUndefined (varStack ))
11161118
11171119 dcsFailedEcsDetectors := make ([]string , 0 )
11181120 dcsopOk := true
@@ -1298,7 +1300,7 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
12981300
12991301 var stream dcspb.Configurator_EndOfRunClient
13001302 timeout := callable .AcquireTimeout (DCS_GENERAL_OP_TIMEOUT , varStack , "EOR" , envId )
1301- ctx , cancel := context . WithTimeout ( context . Background () , timeout )
1303+ ctx , cancel := integration . NewContext ( envId , varStack , timeout )
13021304 defer cancel ()
13031305
13041306 payload := map [string ]interface {}{
@@ -1356,7 +1358,8 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
13561358 detectorStatusMap [v ] = dcspb .DetectorState_NULL_STATE
13571359 }
13581360
1359- err , payloadJson = EORgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream , detectorStatusMap , callFailedStr , payload )
1361+ err , payloadJson = EORgRPCCommunicationLoop (ctx , timeout , call , envId , payloadJson , stream ,
1362+ detectorStatusMap , callFailedStr , payload , integration .ExtractRunTypeOrUndefined (varStack ))
13601363
13611364 dcsFailedEcsDetectors := make ([]string , 0 )
13621365 dcsopOk := true
@@ -1452,17 +1455,19 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
14521455 return
14531456}
14541457
1455- func newMetric (method string ) monitoring.Metric {
1458+ func newMetric (runType , envId , method string ) monitoring.Metric {
14561459 metric := monitoring .NewMetric ("dcsecs" )
14571460 metric .AddTag ("method" , method )
1461+ metric .AddTag ("envId" , envId )
1462+ metric .AddTag ("runtype" , runType )
14581463 return metric
14591464}
14601465
14611466func EORgRPCCommunicationLoop (ctx context.Context , timeout time.Duration , call * callable.Call , envId string ,
14621467 payloadJsonForKafka []byte , stream dcspb.Configurator_EndOfRunClient , detectorStatusMap map [dcspb.Detector ]dcspb.DetectorState ,
1463- callFailedStr string , payload map [string ]interface {},
1468+ callFailedStr string , payload map [string ]interface {}, runType string ,
14641469) (error , []byte ) {
1465- metric := newMetric ("EOR" )
1470+ metric := newMetric (runType , envId , "EOR" )
14661471 defer monitoring .TimerSendSingle (& metric , monitoring .Millisecond )()
14671472
14681473 var dcsEvent * dcspb.RunEvent
@@ -1692,9 +1697,9 @@ func EORgRPCCommunicationLoop(ctx context.Context, timeout time.Duration, call *
16921697
16931698func SORgRPCCommunicationLoop (ctx context.Context , timeout time.Duration , call * callable.Call , envId string ,
16941699 payloadJsonForKafka []byte , stream dcspb.Configurator_StartOfRunClient , detectorStatusMap map [dcspb.Detector ]dcspb.DetectorState ,
1695- callFailedStr string , payload map [string ]interface {},
1700+ callFailedStr string , payload map [string ]interface {}, runType string ,
16961701) (error , []byte ) {
1697- metric := newMetric ("SOR" )
1702+ metric := newMetric (runType , envId , "SOR" )
16981703 defer monitoring .TimerSendSingle (& metric , monitoring .Millisecond )()
16991704
17001705 var dcsEvent * dcspb.RunEvent
@@ -1961,9 +1966,9 @@ func SORgRPCCommunicationLoop(ctx context.Context, timeout time.Duration, call *
19611966
19621967func PFRgRPCCommunicationLoop (ctx context.Context , timeout time.Duration , call * callable.Call , envId string ,
19631968 payloadJsonForKafka []byte , stream dcspb.Configurator_StartOfRunClient , detectorStatusMap map [dcspb.Detector ]dcspb.DetectorState ,
1964- callFailedStr string , payload map [string ]interface {},
1969+ callFailedStr string , payload map [string ]interface {}, runType string ,
19651970) (error , []byte ) {
1966- metric := newMetric ("PFR" )
1971+ metric := newMetric (runType , envId , "PFR" )
19671972 defer monitoring .TimerSendSingle (& metric , monitoring .Millisecond )()
19681973
19691974 var err error
0 commit comments