<commit_before>package main

import (
	"bufio"
	"encoding/json"
	"log"
	"net/http"
	"runtime"
	"strings"
	"time"

	"github.com/ContaAzul/hystrix-to-librato/internal/config"
	"github.com/ContaAzul/hystrix-to-librato/internal/models"
	"github.com/ContaAzul/hystrix-to-librato/internal/report"
)

var waitTime = 5 * time.Second

func main() {
	config := config.Get()
	report := report.Librato(config.User, config.Token)
	for _, cluster := range config.Clusters {
		go read(config.URL, cluster, report)
	}
	// sleep forever
	for {
		time.Sleep(waitTime)
		log.Println(runtime.NumGoroutine(), "goroutines running...")
	}
}

func read(url, cluster string, report report.Report) {
	time.Sleep(waitTime)
	log.Println("Starting", cluster)
	resp, err := http.Get(url + "?cluster=" + cluster)
	if err != nil {
		log.Println(err)
		read(url, cluster, report)
		return
	}
	scanner := bufio.NewScanner(resp.Body)
	for scanner.Scan() {
		line := scanner.Text()
		if !isData(line) || !isCircuitReport(line) {
			continue
		}
		doReport(report, cluster, line)
	}
}

func doReport(report report.Report, cluster, line string) {
	line = strings.TrimPrefix(line, "data:")<commit_msg>restart when done<commit_after>package main

import (
	"bufio"
	"encoding/json"
	"log"
	"net/http"
	"runtime"
	"strings"
	"time"

	"github.com/ContaAzul/hystrix-to-librato/internal/config"
	"github.com/ContaAzul/hystrix-to-librato/internal/models"
	"github.com/ContaAzul/hystrix-to-librato/internal/report"
)

var waitTime = 5 * time.Second

func main() {
	config := config.Get()
	report := report.Librato(config.User, config.Token)
	for _, cluster := range config.Clusters {
		go read(config.URL, cluster, report)
	}
	// sleep forever
	for {
		time.Sleep(waitTime)
		log.Println(runtime.NumGoroutine(), "goroutines running...")
	}
}

func read(url, cluster string, report report.Report) {
	time.Sleep(waitTime)
	log.Println("Starting", cluster)
	resp, err := http.Get(url + "?cluster=" + cluster)
	if err != nil {
		log.Println(err)
		read(url, cluster, report)
		return
	}
	scanner := bufio.NewScanner(resp.Body)
	for scanner.Scan() {
		line := scanner.Text()
		if !isData(line) || !isCircuitReport(line) {
			continue
		}
		doReport(report, cluster, line)
	}
	read(url, cluster, report)
}

func doReport(report report.Report, cluster, line string) {
	line = strings.TrimPrefix(line, "data:")
{'fraction_non_alphanumeric': 0.15534804753820033, 'fraction_numerical': 0.0008488964346349745, 'mean_word_length': 4.320541760722348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6654585', 'n_tokens_mistral': 938, 'n_tokens_neox': 895, 'n_words': 170}