11package  locker
22
33import  (
4- 	"fmt" 
5- 
64	"github.com/bivas/rivi/engine/actions" 
75	"github.com/bivas/rivi/types" 
86	"github.com/bivas/rivi/util/log" 
97	"github.com/mitchellh/mapstructure" 
108	"github.com/mitchellh/multistep" 
9+ 	"github.com/pkg/errors" 
10+ 	"github.com/prometheus/client_golang/prometheus" 
1111)
1212
1313type  LockableData  interface  {
@@ -29,13 +29,14 @@ func (a *action) Apply(state multistep.StateBag) {
2929		a .logger .WarningWith (
3030			log.MetaFields {log .F ("issue" , meta .GetShortName ())},
3131			"Event data does not support locking. Check your configurations" )
32- 		a .err  =  fmt . Errorf ( "Event  data does not support locking"
32+ 		a .err  =  errors . New ( "event  data does not support locking"
3333		return 
3434	}
3535	if  lockable .LockState () {
3636		a .logger .Debug ("Issue is locked" )
3737		if  a .rule .State  ==  "unlock"  ||  a .rule .State  ==  "change"  {
3838			a .logger .DebugWith (log.MetaFields {log .F ("issue" , meta .GetShortName ())}, "unlocking issue" )
39+ 			counter .Inc ()
3940			lockable .Unlock ()
4041		} else  if  a .rule .State  ==  "lock"  {
4142			a .logger .DebugWith (log.MetaFields {log .F ("issue" , meta .GetShortName ())}, "Issue is already locked - nothing changed" )
@@ -44,6 +45,7 @@ func (a *action) Apply(state multistep.StateBag) {
4445		a .logger .Debug ("Issue is unlocked" )
4546		if  a .rule .State  ==  "lock"  ||  a .rule .State  ==  "change"  {
4647			a .logger .DebugWith (log.MetaFields {log .F ("issue" , meta .GetShortName ())}, "Locking issue" )
48+ 			counter .Inc ()
4749			lockable .Lock ()
4850		} else  if  a .rule .State  ==  "lock"  {
4951			a .logger .DebugWith (log.MetaFields {log .F ("issue" , meta .GetShortName ())}, "Issue is already unlocked - nothing changed" )
@@ -64,6 +66,9 @@ func (*factory) BuildAction(config map[string]interface{}) actions.Action {
6466	return  & action {rule : & item , logger : logger }
6567}
6668
69+ var  counter  =  actions .NewCounter ("locker" )
70+ 
6771func  init () {
6872	actions .RegisterAction ("locker" , & factory {})
73+ 	prometheus .Register (counter )
6974}
0 commit comments