コード例 #1
0
ファイル: forwarder.go プロジェクト: heroku/log-iss
func newForwarderSet(config IssConfig) *forwarderSet {
	return &forwarderSet{
		Config:  config,
		Inbox:   make(chan payload, 1000),
		timeout: metrics.GetOrRegisterCounter("log-iss.forwardset.deliver.timeout", config.MetricsRegistry),
		full:    metrics.GetOrRegisterCounter("log-iss.forwardset.deliver.full", config.MetricsRegistry),
	}
}
コード例 #2
0
ファイル: mmcontroller.go プロジェクト: tixu/mmjira
//Inform send message to the right channel in MM
func (c *Controller) Inform(update jira.IssueEvent) <-chan Response {

	c.l.Info("about to inform")
	count := metrics.GetOrRegisterCounter("inform.request.total", c.reg)
	count.Inc(1)
	ch := make(chan Response)
	go func() {
		response := Response{Project: strings.ToLower(update.Project), ID: update.ID}
		count := metrics.GetOrRegisterCounter("inform.request."+response.Project, c.reg)
		count.Inc(1)

		purl := c.hooks[strings.ToLower(update.Project)]
		if purl == "" {
			response.Status = "1002 - not mapped"
			response.StatusCode = 1002
			ch <- response
			return
		}
		response.EndPoint = purl
		c.l.Debug("about to post", zap.String("post url", purl))
		buff, err := c.converter.Convert(update)
		if err != nil {
			response.Error = err.Error()
			response.Status = "1003 - not templated"
			response.StatusCode = 1003
			ch <- response
			return
		}

		s2, _ := json.Marshal(&Request{User: c.name, Icon: c.icon, Text: string(buff.Bytes())})
		req, err := http.NewRequest("POST", purl, bytes.NewBuffer(s2))
		req.Header.Set("Content-Type", "application/json")

		client := &http.Client{}

		resp, err := client.Do(req)

		if err != nil {
			response.Error = err.Error()
			ch <- response
			return
		}
		response.Error = ""
		response.Status = resp.Status
		response.StatusCode = resp.StatusCode

		ch <- response
		close(ch)
	}()
	return ch
}
コード例 #3
0
// waitForAnalysis waits for files that need to be analyzed (from forAnalysis) and makes a copy of
// them in config.Aggregator.BinaryFuzzPath with their hash as a file name.
// It then analyzes it using the supplied AnalysisPackage and then signals the results should be
// uploaded. If any unrecoverable errors happen, this method terminates.
func (agg *BinaryAggregator) waitForAnalysis(identifier int, analysisPackage AnalysisPackage) {
	defer agg.pipelineWaitGroup.Done()
	defer go_metrics.GetOrRegisterCounter("analysis_process_count", go_metrics.DefaultRegistry).Dec(int64(1))
	glog.Infof("Spawning analyzer %d", identifier)

	// our own unique working folder
	executableDir := filepath.Join(config.Aggregator.ExecutablePath, fmt.Sprintf("analyzer%d", identifier))
	if err := analysisPackage.Setup(executableDir); err != nil {
		glog.Errorf("Analyzer %d terminated due to error: %s", identifier, err)
		return
	}
	for {
		select {
		case badBinaryPath := <-agg.forAnalysis:
			atomic.AddInt64(&agg.analysisCount, int64(1))
			err := agg.analysisHelper(executableDir, badBinaryPath, analysisPackage)
			if err != nil {
				glog.Errorf("Analyzer %d terminated due to error: %s", identifier, err)
				return
			}
		case <-agg.pipelineShutdown:
			glog.Infof("Analyzer %d recieved shutdown signal", identifier)
			return
		}
	}
}
コード例 #4
0
ファイル: http.go プロジェクト: heroku/log-iss
func newHTTPServer(config IssConfig, auth authenticater.Authenticater, fixerFunc FixerFunc, deliverer deliverer) *httpServer {
	return &httpServer{
		auth:           auth,
		Config:         config,
		FixerFunc:      fixerFunc,
		deliverer:      deliverer,
		shutdownCh:     make(shutdownCh),
		posts:          metrics.GetOrRegisterTimer("log-iss.http.logs", config.MetricsRegistry),
		healthChecks:   metrics.GetOrRegisterTimer("log-iss.http.healthchecks", config.MetricsRegistry),
		pErrors:        metrics.GetOrRegisterCounter("log-iss.http.logs.errors", config.MetricsRegistry),
		pSuccesses:     metrics.GetOrRegisterCounter("log-iss.http.logs.successes", config.MetricsRegistry),
		pAuthErrors:    metrics.GetOrRegisterCounter("log-iss.auth.errors", config.MetricsRegistry),
		pAuthSuccesses: metrics.GetOrRegisterCounter("log-iss.auth.successes", config.MetricsRegistry),
		isShuttingDown: false,
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: tixu/mmjira
func (b MMJira) getHandler(w http.ResponseWriter, r *http.Request) {
	b.l.Debug("got a request to the hetHandler")
	//increasing the counter
	c := metrics.GetOrRegisterCounter("hooks.get", b.reg)
	c.Inc(1)
	// computing the map
	cv := make(map[string]int64)
	anom := func(k string, v interface{}) {
		if tmp, ok := v.(metrics.Counter); ok {
			cv[k] = tmp.Count()
		}
	}
	b.reg.Each(anom)
	//t:=template.New("info")
	var err error
	t, err := template.ParseFiles("templates/info.html")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	p := Page{T: "Overview", C: cv}
	if err := t.Execute(w, p); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
コード例 #6
0
// waitForUploads waits for uploadPackages to be sent through the forUpload channel
// and then uploads them.  If any unrecoverable errors happen, this method terminates.
func (agg *BinaryAggregator) waitForUploads(identifier int) {
	defer agg.pipelineWaitGroup.Done()
	defer go_metrics.GetOrRegisterCounter("upload_process_count", go_metrics.DefaultRegistry).Dec(int64(1))
	glog.Infof("Spawning uploader %d", identifier)
	for {
		select {
		case p := <-agg.forUpload:
			atomic.AddInt64(&agg.uploadCount, int64(1))
			if !agg.UploadGreyFuzzes && p.FuzzType == GREY_FUZZ {
				glog.Infof("Skipping upload of grey fuzz %s", p.Name)
				continue
			}
			if err := agg.upload(p); err != nil {
				glog.Errorf("Uploader %d terminated due to error: %s", identifier, err)
				return
			}
			agg.forBugReporting <- bugReportingPackage{
				FuzzName:   p.Name,
				CommitHash: config.Generator.SkiaVersion.Hash,
				IsBadFuzz:  p.FuzzType == BAD_FUZZ,
			}
		case <-agg.pipelineShutdown:
			glog.Infof("Uploader %d recieved shutdown signal", identifier)
			return
		}
	}
}
コード例 #7
0
ファイル: mmcontroller.go プロジェクト: tixu/mmjira
//Analyse the response from mm
func (c *Controller) Analyse(in <-chan Response) {

	count := metrics.GetOrRegisterCounter("analyse.response.total", c.reg)
	count.Inc(1)

	response := <-in
	if response.StatusCode != 200 {
		n := "analyse.response." + response.Project + ".error"
		count := metrics.GetOrRegisterCounter(n, c.reg)
		count.Inc(1)
	} else {
		n := "analyse.response." + response.Project + ".ok"
		count := metrics.GetOrRegisterCounter(n, c.reg)
		count.Inc(1)
	}
	c.l.Info("response received", zap.Object("response", response))
}
コード例 #8
0
ファイル: local_db.go プロジェクト: saltmueller/skia-buildbot
// startTx monitors when a transaction starts.
func (d *localDB) startTx(name string) int64 {
	d.txMutex.Lock()
	defer d.txMutex.Unlock()
	go_metrics.GetOrRegisterCounter("buildbot.txcount", go_metrics.DefaultRegistry).Inc(1)
	id := d.txNextId
	d.txActive[id] = name
	d.txNextId++
	return id
}
コード例 #9
0
// monitorStatus sets up the monitoring routine, which reports how big the work queues are
// and how many processes are up.
func (agg *BinaryAggregator) monitorStatus(numAnalysisProcesses, numUploadProcesses int) {
	defer agg.monitoringWaitGroup.Done()
	analysisProcessCount := go_metrics.GetOrRegisterCounter("analysis_process_count", go_metrics.DefaultRegistry)
	analysisProcessCount.Clear()
	analysisProcessCount.Inc(int64(numAnalysisProcesses))
	uploadProcessCount := go_metrics.GetOrRegisterCounter("upload_process_count", go_metrics.DefaultRegistry)
	uploadProcessCount.Clear()
	uploadProcessCount.Inc(int64(numUploadProcesses))

	t := time.Tick(config.Aggregator.StatusPeriod)
	for {
		select {
		case <-agg.monitoringShutdown:
			glog.Infof("aggregator monitor got signal to shut down")
			return
		case <-t:
			go_metrics.GetOrRegisterGauge("binary_analysis_queue_size", go_metrics.DefaultRegistry).Update(int64(len(agg.forAnalysis)))
			go_metrics.GetOrRegisterGauge("binary_upload_queue_size", go_metrics.DefaultRegistry).Update(int64(len(agg.forUpload)))
			go_metrics.GetOrRegisterGauge("binary_bug_report_queue_size", go_metrics.DefaultRegistry).Update(int64(len(agg.forBugReporting)))
		}
	}
}
コード例 #10
0
ファイル: main.go プロジェクト: tixu/mmjira
// GetTarget retrieve the hook assigned to a projet, return an error in anyother case
func (b MMJira) postHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hookid := strings.ToLower(vars["hookid"])
	b.l.Info("project", zap.String("hook", hookid))
	if b.c.Hooks[hookid] == "" {
		c := metrics.GetOrRegisterCounter("hooks.post.unknown.project", b.reg)
		c.Inc(1)
		http.Error(w, "unknwon project", http.StatusBadRequest)
		return
	}
	b.l.Debug("received a request")
	c := metrics.GetOrRegisterCounter("hooks.received."+hookid, b.reg)
	c.Inc(1)
	if b.c.Debug {
		if err := utils.DumpRequest(r, b.c.DumpDir); err != nil {
			b.l.Info("unable to dump the request in the directory", zap.String("Directory", b.c.DumpDir))
		}
	}
	issue, err := b.m.Create(r.Body)
	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
		return
	}

	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
		return
	}

	// We only know our top-level keys are strings

	b.l.Debug("sending", zap.Object("issue", issue))

	ch := b.m.Inform(issue)
	go b.m.Analyse(ch)
}
コード例 #11
0
ファイル: ingest.go プロジェクト: 1394/skia-buildbot
// insertBuilds inserts a batch of builds into the database. In the case of
// failure, it continually retries until it succeeds.
func insertBuilds(builds []*Build) {
	defer metrics.NewTimer("buildbot.insertBuilds").Stop()
	for {
		// Insert the builds.
		glog.Infof("Inserting %d builds.", len(builds))
		if err := ReplaceMultipleBuildsIntoDB(builds); err != nil {
			glog.Errorf("Failed to insert builds, retrying: %s", err)
			time.Sleep(100 * time.Millisecond)
		} else {
			break
		}
	}
	glog.Infof("Finished inserting %d builds.", len(builds))
	go_metrics.GetOrRegisterCounter("buildbot.NumInsertedBuilds", go_metrics.DefaultRegistry).Inc(int64(len(builds)))
}
コード例 #12
0
func TestCloudwatchReporter(t *testing.T) {
	mock := &MockPutMetricsClient{}
	cfg := &config.Config{
		Client: mock,
		Filter: &config.NoFilter{},
	}
	registry := metrics.NewRegistry()
	for i := 0; i < 30; i++ {
		count := metrics.GetOrRegisterCounter(fmt.Sprintf("count-%d", i), registry)
		count.Inc(1)
	}

	emitMetrics(registry, cfg)

	if mock.metricsPut < 30 || mock.requests < 2 {
		t.Fatal("No Metrics Put")
	}
}
コード例 #13
0
ファイル: ingest.go プロジェクト: saltmueller/skia-buildbot
// IngestBuild retrieves the given build from the build master's JSON interface
// and pushes it into the database.
func IngestBuild(db DB, b *Build, repos *gitinfo.RepoMap) error {
	defer metrics.NewTimer("buildbot.IngestBuild").Stop()
	defer go_metrics.GetOrRegisterCounter("buildbot.NumIngestedBuilds", go_metrics.DefaultRegistry).Inc(1)
	// Find the commits for this build.
	commits, stoleFrom, stolen, err := FindCommitsForBuild(db, b, repos)
	if err != nil {
		return err
	}
	b.Commits = commits

	// Log the case where we found no revisions for the build.
	if !(IsTrybot(b.Builder) || strings.Contains(b.Builder, "Housekeeper")) && len(b.Commits) == 0 {
		glog.Infof("Got build with 0 revs: %s #%d GotRev=%s", b.Builder, b.Number, b.GotRevision)
	}

	// Insert the build.
	if stoleFrom >= 0 && stolen != nil && len(stolen) > 0 {
		// Remove the commits we stole from the previous owner.
		oldBuild, err := db.GetBuildFromDB(b.Master, b.Builder, stoleFrom)
		if err != nil {
			return err
		}
		if oldBuild == nil {
			return fmt.Errorf("Attempted to retrieve %s #%d, but got a nil build from the DB.", b.Builder, stoleFrom)
		}
		newCommits := make([]string, 0, len(oldBuild.Commits))
		for _, c := range oldBuild.Commits {
			keep := true
			for _, s := range stolen {
				if c == s {
					keep = false
					break
				}
			}
			if keep {
				newCommits = append(newCommits, c)
			}
		}
		oldBuild.Commits = newCommits
		return db.PutBuilds([]*Build{b, oldBuild})
	} else {
		return db.PutBuild(b)
	}
}
コード例 #14
0
ファイル: forwarder.go プロジェクト: heroku/log-iss
func newForwarder(config IssConfig, inbox chan payload, id int) *forwarder {
	me := fmt.Sprintf("log-iss.forwarder.%d", id)
	return &forwarder{
		ID:           id,
		Config:       config,
		Inbox:        inbox,
		duration:     metrics.GetOrRegisterTimer(me+".duration", config.MetricsRegistry),
		cDisconnects: metrics.GetOrRegisterCounter(me+".disconnects", config.MetricsRegistry),
		cSuccesses:   metrics.GetOrRegisterCounter(me+".connect.successes", config.MetricsRegistry),
		cErrors:      metrics.GetOrRegisterCounter(me+".connect.errors", config.MetricsRegistry),
		wErrors:      metrics.GetOrRegisterCounter(me+".write.errors", config.MetricsRegistry),
		wSuccesses:   metrics.GetOrRegisterCounter(me+".write.successes", config.MetricsRegistry),
		wBytes:       metrics.GetOrRegisterCounter(me+".write.bytes", config.MetricsRegistry),
	}
}
コード例 #15
0
ファイル: gometrics.go プロジェクト: hilerchyn/fabio
func (p *gmRegistry) GetCounter(name string) Counter {
	return gm.GetOrRegisterCounter(name, p.r)
}
コード例 #16
0
ファイル: accounting_gm.go プロジェクト: jmptrader/query
func (g *goMetricRegistry) Counter(name string) accounting.Counter {
	return metrics.GetOrRegisterCounter(name, metrics.DefaultRegistry)
}
コード例 #17
0
ファイル: local_db.go プロジェクト: saltmueller/skia-buildbot
// endTx monitors when a transaction ends.
func (d *localDB) endTx(id int64) {
	d.txMutex.Lock()
	defer d.txMutex.Unlock()
	go_metrics.GetOrRegisterCounter("buildbot.txcount", go_metrics.DefaultRegistry).Dec(1)
	delete(d.txActive, id)
}
コード例 #18
0
ファイル: metrics.go プロジェクト: Automattic/pinghub
func (m metrics) decr(name string, i int64) {
	gometrics.GetOrRegisterCounter(name, m.reg).Dec(i)
}