mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 14:23:25 +00:00
Use default namespace in metrics exporter
Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
@ -23,17 +23,19 @@ import (
|
||||
|
||||
// Exporter is a prometheus exporter
|
||||
type Exporter struct {
|
||||
metricOptions MetricOptions
|
||||
services []types.FunctionStatus
|
||||
credentials *auth.BasicAuthCredentials
|
||||
metricOptions MetricOptions
|
||||
services []types.FunctionStatus
|
||||
credentials *auth.BasicAuthCredentials
|
||||
FunctionNamespace string
|
||||
}
|
||||
|
||||
// NewExporter creates a new exporter for the OpenFaaS gateway metrics
|
||||
func NewExporter(options MetricOptions, credentials *auth.BasicAuthCredentials) *Exporter {
|
||||
func NewExporter(options MetricOptions, credentials *auth.BasicAuthCredentials, namespace string) *Exporter {
|
||||
return &Exporter{
|
||||
metricOptions: options,
|
||||
services: []types.FunctionStatus{},
|
||||
credentials: credentials,
|
||||
metricOptions: options,
|
||||
services: []types.FunctionStatus{},
|
||||
credentials: credentials,
|
||||
FunctionNamespace: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,8 +93,7 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri
|
||||
}
|
||||
|
||||
if len(namespaces) == 0 {
|
||||
emptyNamespace := ""
|
||||
services, err := e.getFunctions(endpointURL, emptyNamespace)
|
||||
services, err := e.getFunctions(endpointURL, e.FunctionNamespace)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
@ -170,8 +171,9 @@ func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.
|
||||
|
||||
func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
|
||||
namespaces := []string{}
|
||||
endpointURL.Path = path.Join(endpointURL.Path, "system/namespaces")
|
||||
|
||||
get, _ := http.NewRequest(http.MethodGet, endpointURL.String()+"system/namespaces", nil)
|
||||
get, _ := http.NewRequest(http.MethodGet, endpointURL.String(), nil)
|
||||
if e.credentials != nil {
|
||||
get.SetBasicAuth(e.credentials.User, e.credentials.Password)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func readGauge(g prometheus.Metric) metricResult {
|
||||
|
||||
func Test_Describe_DescribesThePrometheusMetrics(t *testing.T) {
|
||||
metricsOptions := BuildMetricsOptions()
|
||||
exporter := NewExporter(metricsOptions, nil)
|
||||
exporter := NewExporter(metricsOptions, nil, "openfaas-fn")
|
||||
|
||||
ch := make(chan *prometheus.Desc)
|
||||
// defer close(ch)
|
||||
@ -65,7 +65,7 @@ func Test_Describe_DescribesThePrometheusMetrics(t *testing.T) {
|
||||
|
||||
func Test_Collect_CollectsTheNumberOfReplicasOfAService(t *testing.T) {
|
||||
metricsOptions := BuildMetricsOptions()
|
||||
exporter := NewExporter(metricsOptions, nil)
|
||||
exporter := NewExporter(metricsOptions, nil, "openfaas-fn")
|
||||
|
||||
expectedService := types.FunctionStatus{
|
||||
Name: "function_with_two_replica",
|
||||
|
Reference in New Issue
Block a user