<commit_before>package dashboard

import (
	"flag"
	"net"
	"sync"

	"github.com/golang/glog"

	"hkjn.me/prober"
	"hkjn.me/probes/dnsprobe"
	"hkjn.me/probes/webprobe"
)

var (
	proberDisabled = flag.Bool("no_probes", false, "disables probes")
	allProbes      = []*prober.Probe{}
	createOnce     = sync.Once{}
)

func getWebProbes() []*prober.Probe {
	probes := []*prober.Probe{}
	for _, p := range probecfg.WebProbes {
		probes = append(probes,
			webprobe.New(
				p.Target,
				"GET",
				p.WantStatus,
				webprobe.Name(p.Name),
				webprobe.InResponse(p.Want)))
	}
	return probes
}

func getDnsProbe() *prober.Probe {
	mxRecords := []*net.MX{}
	r := probecfg.DnsProbe.Records
	for _, mx := range r.Mx {
		mxRecords = append(mxRecords, &net.MX{
			Host: mx.Host,
			Pref: mx.Pref,
		})
	}
	nsRecords := []*net.NS{}
	for _, ns := range r.Ns {
		nsRecords = append(nsRecords, &net.NS{Host: ns})
	}
	return dnsprobe.New(
		probecfg.DnsProbe.Target, dnsprobe.MX(mxRecords), dnsprobe.A(r.A),
		dnsprobe.NS(nsRecords), dnsprobe.CNAME(r.Cname), dnsprobe.TXT(r.Txt))
}

// getProbes returns all probes in the dashboard.
func getProbes() []*prober.Probe {
	createOnce.Do(func() {
		if !flag.Parsed() {
			flag.Parse()
		}
		if *proberDisabled {
			glog.Infof("Probes are disabled with -no_probes\n")
		} else {
			allProbes = []*prober.Probe{
				getDnsProbe(),
			}
			allProbes = append(allProbes, getWebProbes()...)
		}
	})
	return allProbes
}<commit_msg>Sort probes before returning them<commit_after>package dashboard

import (
	"flag"
	"net"
	"sort"
	"sync"

	"github.com/golang/glog"

	"hkjn.me/prober"
	"hkjn.me/probes/dnsprobe"
	"hkjn.me/probes/webprobe"
)

var (
	proberDisabled = flag.Bool("no_probes", false, "disables probes")
	allProbes      = prober.Probes{}
	createOnce     = sync.Once{}
)

func getWebProbes() prober.Probes {
	probes := prober.Probes{}
	for _, p := range probecfg.WebProbes {
		probes = append(probes,
			webprobe.New(
				p.Target,
				"GET",
				p.WantStatus,
				webprobe.Name(p.Name),
				webprobe.InResponse(p.Want)))
	}
	return probes
}

func getDnsProbe() *prober.Probe {
	mxRecords := []*net.MX{}
	r := probecfg.DnsProbe.Records
	for _, mx := range r.Mx {
		mxRecords = append(mxRecords, &net.MX{
			Host: mx.Host,
			Pref: mx.Pref,
		})
	}
	nsRecords := []*net.NS{}
	for _, ns := range r.Ns {
		nsRecords = append(nsRecords, &net.NS{Host: ns})
	}
	return dnsprobe.New(
		probecfg.DnsProbe.Target, dnsprobe.MX(mxRecords), dnsprobe.A(r.A),
		dnsprobe.NS(nsRecords), dnsprobe.CNAME(r.Cname), dnsprobe.TXT(r.Txt))
}

// getProbes returns all probes in the dashboard.
func getProbes() prober.Probes {
	createOnce.Do(func() {
		if !flag.Parsed() {
			flag.Parse()
		}
		if *proberDisabled {
			glog.Infof("Probes are disabled with -no_probes\n")
		} else {
			allProbes = []*prober.Probe{
				getDnsProbe(),
			}
			allProbes = append(allProbes, getWebProbes()...)
		}
	})
	sort.Sort(allProbes)
	return allProbes
}
{'fraction_non_alphanumeric': 0.1640625, 'fraction_numerical': 0.0, 'mean_word_length': 3.5307692307692307, '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': '1711102', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1236, 'n_words': 216}