Skip to content

Commit

Permalink
Phabricator queries are done in parallel, an ignore option is added f…
Browse files Browse the repository at this point in the history
…or blackbox
  • Loading branch information
Pouyan Azari committed Sep 9, 2019
1 parent 1db8b77 commit 55ba217
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## [0.0.11] 2019-09-09

- The phabricator queries are running parallel
- Added an ignore option for blackbox groups
- Some small fixes

## [0.0.10] 2019-08-28

- Fixed small Bug in the cache logic
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ The `module` is a parameter and it should be relabeled, the configuration would
replacement: 127.0.0.1:9115 # The blackbox exporter.
```

The blackbox mode can be called with help of `-b` and if some groups
should be ignored these can be added as comma separated values with `-i`.

## Build

You can build your own binaries from the source code, using golang standard
Expand All @@ -331,8 +334,6 @@ go build

There are several points that should be covered in the next couple of
releases:
- Parallel Queries: to make the queries to Phabricator faster parallel queries should be possible.
it should use the concurrency feature of Go.
- Test case: Add test cases for the application
- Native Packages: This has low priority, but will replace the binary
releases at some point.
Expand Down
41 changes: 28 additions & 13 deletions a2a.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package main
// It supports all the parameters and options detailed there.

import (
// "./alertmanager/config"
"app-a2a/alertmanager/config"
phabricator "app-a2a/api-phabricator-go"
"./alertmanager/config"
"encoding/json"
"errors"
"fmt"
"github.com/uniwue-rz/phabricator-go"
"github.com/urfave/cli"
"gopkg.in/gcfg.v1"
"gopkg.in/yaml.v2"
Expand All @@ -21,6 +20,7 @@ import (
"reflect"
"regexp"
"strconv"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -90,7 +90,7 @@ func manageAlertManager(p *phabricator.Phabricator, configPath string, jsonWrapp
}

func getGroupRouteReceivers(p *phabricator.Phabricator, jsonWrapper string) (routes []config.Route, receivers []config.Receiver) {
services, err := phabricator.GetServices(p)
services, err := p.GetServicesAsync()

if err != nil {
panic(err)
Expand Down Expand Up @@ -377,15 +377,21 @@ func (output *Output) Augment(p *phabricator.Phabricator, PassphraseWrapper stri
}

// GetBlackBoxData returns the blackbox targets and data.
func GetBlackBoxData(p *phabricator.Phabricator, JsonWrapper string) (allOutputs []PrometheusOutput, err error) {
services, err := phabricator.GetServices(p)
func GetBlackBoxData(p *phabricator.Phabricator, JsonWrapper string, ignoreArray []string) (allOutputs []PrometheusOutput, err error) {
services, err := p.GetServicesAsync()

allOutputs = make([]PrometheusOutput, 0)
if err != nil {
return allOutputs, err
}
for _, d := range services.Result.Data {
if len(d.Attachments.Bindings.Bindings) != 0 {
ignored := false
for _, b := range ignoreArray {
if b == d.Fields.Name && ignored == false {
ignored = true
}
}
if len(d.Attachments.Bindings.Bindings) != 0 && ignored == false {
blackBoxConfig := ""
for _, property := range d.Attachments.Properties.Properties {
if property.Key == "blackbox-config" {
Expand Down Expand Up @@ -437,7 +443,7 @@ func GetBlackBoxData(p *phabricator.Phabricator, JsonWrapper string) (allOutputs
// prometheus-config this will be used, when not the group settings will be used.
// The script will be used here to create the dynamic configuration in Prometheus
func GetPrometheusData(p *phabricator.Phabricator, JsonWrapper string) (allOutputs []PrometheusOutput, err error) {
services, err := phabricator.GetServices(p)
services, err := p.GetServicesAsync()

allOutputs = make([]PrometheusOutput, 0)
if err != nil {
Expand Down Expand Up @@ -511,7 +517,7 @@ func HandlePassphrase(p *phabricator.Phabricator, PassphraseWrapper string, prop
if len(passPhraseRegexMatching) > 1 {
isPassphrase = true
passPhraseKey := passPhraseRegexMatching[1]
passphraseObj, err := phabricator.GetPassPhraseWithId(p, passPhraseKey)
passphraseObj, err := p.GetPassPhraseWithId(passPhraseKey)
if err != nil {
passPhrase = ""
return passPhrase, false, err
Expand Down Expand Up @@ -539,7 +545,7 @@ func ListParallel(p *phabricator.Phabricator, playBookPath string, vagrant strin
groupList := make(map[string]Group)
hostVars := make(map[string]map[string]interface{})

services, err := phabricator.GetServices(p) // -> one request, not worth paralleling
services, err := p.GetServicesAsync() // -> one request, not worth paralleling

// Returns the List of services
if err != nil {
Expand Down Expand Up @@ -600,7 +606,7 @@ func ListBlocking(p *phabricator.Phabricator, playBookPath string, vagrant strin

groupList := make(map[string]Group)
hostVars := make(map[string]map[string]interface{})
services, err := phabricator.GetServices(p)
services, err := p.GetServicesAsync()

// Returns the List of services
if err != nil {
Expand Down Expand Up @@ -666,7 +672,7 @@ func ReplaceDotsToUnderscore(key string) string {
func CreateHost(p *phabricator.Phabricator, devName string) (values map[string]interface{}, err error) {
values = make(map[string]interface{})

device, err := phabricator.GetDevice(p, devName) // -> one request
device, err := p.GetDeviceAsync(devName) // -> one request
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -754,6 +760,10 @@ func CreateCommandLine() *cli.App {
Name: "prometheus, p",
Usage: "Returns the list of services supported by Prometheus for the given host",
},
cli.StringFlag{
Name: "ignore, i",
Usage: "Make the Prometheus or blackbox exporter, ignore the given group",
},
cli.BoolFlag{
Name: "no-cache, n",
Usage: "Run the application in no cache mode",
Expand Down Expand Up @@ -814,6 +824,7 @@ func main() {
prometheusIsOn := c.Bool("prometheus")
blackBoxIsOn := c.Bool("blackbox")
cacheIsOff := c.Bool("no-cache")
ignoreGroups := c.String("ignore")
if vagrant != "" {
cacheIsOff = true
}
Expand All @@ -840,7 +851,11 @@ func main() {
// Creates the blackbox settings with modules as labels.
// Should use relabeling to make parameter from the label.
if blackBoxIsOn {
blackBoxData, err := GetBlackBoxData(p, Config.Wrapper.Json)
var ignoreArray []string
if ignoreGroups != "" {
ignoreArray = strings.Split(ignoreGroups, ",")
}
blackBoxData, err := GetBlackBoxData(p, Config.Wrapper.Json, ignoreArray)
if err == nil {
jsonData, _ := json.Marshal(blackBoxData)
fmt.Println(string(jsonData))
Expand Down
16 changes: 1 addition & 15 deletions a2a_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
phabricator "app-a2a/api-phabricator-go"
"encoding/json"
"github.com/uniwue-rz/phabricator-go"
"testing"
)

Expand All @@ -16,20 +16,6 @@ func TestReadConfig(t *testing.T) {
}
}

// Test List function, mainly for profiling it
//func TestList(t *testing.T) {
// Config, err := ReadConfig()
// if err != nil {
// panic(err)
// }
// p := phabricator.NewPhabricator(Config.Phabricator.ApiURL, Config.Phabricator.ApiToken)
// vagrant := ""
// _, err = List(p, Config.Ansible.Playbook, vagrant)
// if err != nil {
// panic(err)
// }
//}

func TestListWithAugmentParallel(t *testing.T) {
Config, err := ReadConfig()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion api-phabricator-go
Submodule api-phabricator-go deleted from bd8f80

0 comments on commit 55ba217

Please sign in to comment.