Move to a modules/probers model, like the blackbox_exporter. (#34)

There are a number of reasons for this change:
- Modules allow a single instance of the exporter to be configured with numerous
different tls configs. Previously you had to run a different exporter for each
combination.
- Adding new and more complicated options to the exporter should be easier with
modules than if I was to go down the route of accepting configuration directly through url params
- I prefer defining a specific prober (https,tcp) over using the URL to guess
what the user wants
This commit is contained in:
Rob Best
2020-06-17 16:29:21 +01:00
committed by GitHub
parent 5ca5c8ccb9
commit 801179eae7
711 changed files with 200195 additions and 95508 deletions
+42
View File
@@ -0,0 +1,42 @@
package test
import (
"crypto/tls"
"fmt"
"net/http"
"net/http/httptest"
"os"
"time"
)
// SetupHTTPSServer sets up a server for testing with a generated cert and key
// pair. It returns the server, the cert and key, the path to the ca file and a
// function to clean up the server.
func SetupHTTPSServer() (*httptest.Server, []byte, []byte, string, func(), error) {
var teardown func()
testcertPEM, testkeyPEM := GenerateTestCertificate(time.Now().AddDate(0, 0, 1))
caFile, err := WriteFile("certfile.pem", testcertPEM)
if err != nil {
return nil, testcertPEM, testkeyPEM, caFile, teardown, err
}
teardown = func() {
os.Remove(caFile)
}
// Create server
testcert, err := tls.X509KeyPair(testcertPEM, testkeyPEM)
if err != nil {
return nil, testcertPEM, testkeyPEM, caFile, teardown, err
}
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello world")
}))
server.TLS = &tls.Config{
Certificates: []tls.Certificate{testcert},
}
return server, testcertPEM, testkeyPEM, caFile, teardown, nil
}