Browse Source

add run go neb script

forest-feature-rebase-2
forest 9 months ago
parent
commit
1b53f62eb1
  1. 6
      README.md
  2. 4
      run-go-neb.sh
  3. 18
      services/alertmanager/alertmanager.go

6
README.md

@ -1,4 +1,8 @@
### Forest's Go-NEB fork which attempts to re-write promql on alerts into actual graphs
### Forest's Go-NEB fork which attempts to re-write alerts' promql alert conditions into actual graphs
run it with `./run-go-neb.sh`
--------
Testing process:

4
run-go-neb.sh

@ -0,0 +1,4 @@
#!/bin/sh
CONFIG_FILE=config.yaml BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=go-neb.db?_busy_timeout=5000 BASE_URL=http://localhost:4050 ./go-neb

18
services/alertmanager/alertmanager.go

@ -179,11 +179,11 @@ func (s *Service) fixupPrometheusGeneratorURL(urlString string, alertLabels map[
if expressionString != "" {
newExpressionString, err := s.fixupPrometheusExpression(expressionString, alertLabels)
errString := "nil"
if err != nil {
errString = fmt.Sprintf("%+v", err)
}
log.Infof("newExpressionString: %s, err: %s", newExpressionString, errString)
// errString := "nil"
// if err != nil {
// errString = fmt.Sprintf("%+v", err)
// }
// log.Infof("newExpressionString: %s, err: %s", newExpressionString, errString)
if err != nil {
return "", err
}
@ -262,14 +262,14 @@ func (s *Service) fixupPrometheusExpression(expressionString string, alertLabels
_, isComparison := comparisonOperators[typedNode.Op]
isOutermost := len(path) == 0
log.Infof("BinaryExpr: Op: %d. isComparison: %t. isOutermost: %t", int(typedNode.Op), isComparison, isOutermost)
//log.Infof("BinaryExpr: Op: %d. isComparison: %t. isOutermost: %t", int(typedNode.Op), isComparison, isOutermost)
// if the outermost Node is a binary comparison op like x > y, a <= b, etc
if isComparison && isOutermost {
// now we have to figure out which side is dynamic and which side is static (only contains literals)
lhsIsLiteral := isLiteral(typedNode.LHS)
rhsIsLiteral := isLiteral(typedNode.RHS)
log.Infof("BinaryExpr: lhsIsLiteral: %t. rhsIsLiteral: %t", lhsIsLiteral, rhsIsLiteral)
//log.Infof("BinaryExpr: lhsIsLiteral: %t. rhsIsLiteral: %t", lhsIsLiteral, rhsIsLiteral)
// if one side is dynamic, make that side be the new root of the expression (trim the comparison off the outside)
if !lhsIsLiteral && rhsIsLiteral {
setNewRootOfExpr(&(typedNode.LHS))
@ -288,12 +288,12 @@ func (s *Service) fixupPrometheusExpression(expressionString string, alertLabels
}
bytes, _ := json.MarshalIndent(alreadyQualifiedLabels, "", " ")
log.Infof("VectorSelector: alreadyQualifiedLabels: %s", string(bytes))
//log.Infof("VectorSelector: alreadyQualifiedLabels: %s", string(bytes))
// qualify any vectorSelector in the query with the labels that we know matched the alert condition
// as long as this specific label is not already matched on
for k, v := range alertLabels {
log.Infof("alertLabels: %s=%s, apply = %t", k, v, !alreadyQualifiedLabels[k])
//log.Infof("alertLabels: %s=%s, apply = %t", k, v, !alreadyQualifiedLabels[k])
if !alreadyQualifiedLabels[k] {
typedNode.LabelMatchers = append(typedNode.LabelMatchers, &promlabels.Matcher{
Type: promlabels.MatchEqual,

Loading…
Cancel
Save