This repository was archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_factory.go
More file actions
45 lines (41 loc) · 1.4 KB
/
client_factory.go
File metadata and controls
45 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package configuration
import (
"github.com/containerssh/http"
"github.com/containerssh/log"
"github.com/containerssh/metrics"
)
// MetricNameConfigBackendRequests is the number of requests to the config server
const MetricNameConfigBackendRequests = "containerssh_config_server_requests"
// MetricNameConfigBackendFailure is the number of request failures to the configuration backend.
const MetricNameConfigBackendFailure = "containerssh_config_server_failures"
// NewClient creates a new configuration client that can be used to fetch a user-specific configuration.
func NewClient(
config ClientConfig,
logger log.Logger,
metricsCollector metrics.Collector,
) (Client, error) {
var httpClient http.Client
var err error
if config.ClientConfiguration.URL != "" {
httpClient, err = http.NewClient(config.ClientConfiguration, logger)
if err != nil {
return nil, err
}
}
backendRequestsMetric := metricsCollector.MustCreateCounter(
MetricNameConfigBackendRequests,
"requests",
"The number of requests sent to the configuration server.",
)
backendFailureMetric := metricsCollector.MustCreateCounter(
MetricNameConfigBackendFailure,
"requests",
"The number of request failures to the configuration server.",
)
return &client{
httpClient: httpClient,
logger: logger,
backendRequestsMetric: backendRequestsMetric,
backendFailureMetric: backendFailureMetric,
}, nil
}