Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--acceptance_test.go1
-rw-r--r--app.go8
-rw-r--r--app_config.go7
-rw-r--r--internal/source/domains.go2
-rw-r--r--internal/source/domains_test.go2
-rw-r--r--internal/source/gitlab/client/client.go4
-rw-r--r--internal/source/gitlab/client/config.go2
-rw-r--r--main.go11
-rw-r--r--metrics/metrics.go7
9 files changed, 33 insertions, 11 deletions
diff --git a/acceptance_test.go b/acceptance_test.go
index 4e773566..79a9b275 100644
--- a/acceptance_test.go
+++ b/acceptance_test.go
@@ -403,6 +403,7 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) {
require.Contains(t, string(body), "gitlab_pages_domains_configuration_update_duration gauge")
require.Contains(t, string(body), "gitlab_pages_domains_source_cache_hit 0")
require.Contains(t, string(body), "gitlab_pages_domains_source_cache_miss 0")
+ require.Contains(t, string(body), "gitlab_pages_domains_source_failures_total 0")
require.Contains(t, string(body), "gitlab_pages_serverless_requests 0")
require.Contains(t, string(body), "gitlab_pages_serverless_latency_sum 0")
}
diff --git a/app.go b/app.go
index e0d2e1fa..ce78b097 100644
--- a/app.go
+++ b/app.go
@@ -13,8 +13,8 @@ import (
"github.com/rs/cors"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/labkit/errortracking"
- "gitlab.com/gitlab-org/labkit/metrics"
"gitlab.com/gitlab-org/labkit/monitoring"
+ labmetrics "gitlab.com/gitlab-org/labkit/metrics"
mimedb "gitlab.com/lupine/go-mimedb"
"gitlab.com/gitlab-org/gitlab-pages/internal/acme"
@@ -28,6 +28,7 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/netutil"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
"gitlab.com/gitlab-org/gitlab-pages/internal/source"
+ "gitlab.com/gitlab-org/gitlab-pages/metrics"
)
const (
@@ -74,7 +75,7 @@ func (a *theApp) ServeTLS(ch *tls.ClientHelloInfo) (*tls.Certificate, error) {
func (a *theApp) healthCheck(w http.ResponseWriter, r *http.Request, https bool) {
if a.isReady() {
- w.Write([]byte("success"))
+ w.Write([]byte("success\n"))
} else {
http.Error(w, "not yet ready", http.StatusServiceUnavailable)
}
@@ -162,6 +163,7 @@ func (a *theApp) routingMiddleware(handler http.Handler) http.Handler {
// middleware chain and simply respond with 502 after logging this
host, domain, err := a.getHostAndDomain(r)
if err != nil {
+ metrics.DomainsSourceFailures.Inc()
log.WithError(err).Error("could not fetch domain information from a source")
httperrors.Serve502(w)
@@ -334,7 +336,7 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
}
// Metrics
- metricsMiddleware := metrics.NewHandlerFactory(metrics.WithNamespace("gitlab_pages"))
+ metricsMiddleware := labmetrics.NewHandlerFactory(labmetrics.WithNamespace("gitlab_pages"))
handler = metricsMiddleware(handler)
handler = a.routingMiddleware(handler)
diff --git a/app_config.go b/app_config.go
index 245a9e0d..5d481bb6 100644
--- a/app_config.go
+++ b/app_config.go
@@ -29,6 +29,7 @@ type appConfig struct {
StoreSecret string
GitLabServer string
+ InternalGitLabServer string
GitLabAPISecretKey []byte
GitlabClientHTTPTimeout time.Duration
GitlabJWTTokenExpiration time.Duration
@@ -40,9 +41,9 @@ type appConfig struct {
CustomHeaders []string
}
-// GitlabServerURL returns URL to a GitLab instance.
-func (config appConfig) GitlabServerURL() string {
- return config.GitLabServer
+// InternalGitLabServerURL returns URL to a GitLab instance.
+func (config appConfig) InternalGitLabServerURL() string {
+ return config.InternalGitLabServer
}
// GitlabClientSecret returns GitLab server access token.
diff --git a/internal/source/domains.go b/internal/source/domains.go
index 11794b91..8de7c574 100644
--- a/internal/source/domains.go
+++ b/internal/source/domains.go
@@ -41,7 +41,7 @@ type Domains struct {
// not initialize `dm` as we later check the readiness by comparing it with a
// nil value.
func NewDomains(config Config) (*Domains, error) {
- if len(config.GitlabServerURL()) == 0 || len(config.GitlabAPISecret()) == 0 {
+ if len(config.InternalGitLabServerURL()) == 0 || len(config.GitlabAPISecret()) == 0 {
return &Domains{disk: disk.New()}, nil
}
diff --git a/internal/source/domains_test.go b/internal/source/domains_test.go
index 9afde412..ebafb6fc 100644
--- a/internal/source/domains_test.go
+++ b/internal/source/domains_test.go
@@ -16,7 +16,7 @@ type sourceConfig struct {
secret string
}
-func (c sourceConfig) GitlabServerURL() string {
+func (c sourceConfig) InternalGitLabServerURL() string {
return c.api
}
diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go
index afe9da6f..bfe425b9 100644
--- a/internal/source/gitlab/client/client.go
+++ b/internal/source/gitlab/client/client.go
@@ -27,7 +27,7 @@ type Client struct {
}
// NewClient initializes and returns new Client baseUrl is
-// appConfig.GitLabServer secretKey is appConfig.GitLabAPISecretKey
+// appConfig.InternalGitLabServer secretKey is appConfig.GitLabAPISecretKey
func NewClient(baseURL string, secretKey []byte, connectionTimeout, jwtTokenExpiry time.Duration) (*Client, error) {
if len(baseURL) == 0 || len(secretKey) == 0 {
return nil, errors.New("GitLab API URL or API secret has not been provided")
@@ -59,7 +59,7 @@ func NewClient(baseURL string, secretKey []byte, connectionTimeout, jwtTokenExpi
// NewFromConfig creates a new client from Config struct
func NewFromConfig(config Config) (*Client, error) {
- return NewClient(config.GitlabServerURL(), config.GitlabAPISecret(), config.GitlabClientConnectionTimeout(), config.GitlabJWTTokenExpiry())
+ return NewClient(config.InternalGitLabServerURL(), config.GitlabAPISecret(), config.GitlabClientConnectionTimeout(), config.GitlabJWTTokenExpiry())
}
// Resolve returns a VirtualDomain configuration wrapped into a Lookup for a
diff --git a/internal/source/gitlab/client/config.go b/internal/source/gitlab/client/config.go
index 4ed14267..19a87452 100644
--- a/internal/source/gitlab/client/config.go
+++ b/internal/source/gitlab/client/config.go
@@ -5,7 +5,7 @@ import "time"
// Config represents an interface that is configuration provider for client
// capable of comunicating with GitLab
type Config interface {
- GitlabServerURL() string
+ InternalGitLabServerURL() string
GitlabAPISecret() []byte
GitlabClientConnectionTimeout() time.Duration
GitlabJWTTokenExpiry() time.Duration
diff --git a/main.go b/main.go
index 9a316c5e..40aef813 100644
--- a/main.go
+++ b/main.go
@@ -61,6 +61,7 @@ var (
secret = flag.String("auth-secret", "", "Cookie store hash key, should be at least 32 bytes long.")
gitLabAuthServer = flag.String("auth-server", "", "DEPRECATED, use gitlab-server instead. GitLab server, for example https://www.gitlab.com")
gitLabServer = flag.String("gitlab-server", "", "GitLab server, for example https://www.gitlab.com")
+ internalGitLabServer = flag.String("internal-gitlab-server", "", "Internal GitLab server used for API requests, useful if you want to send that traffic over an internal load balancer, example value https://www.gitlab.com (defaults to value of gitlab-server)")
gitLabAPISecretKey = flag.String("api-secret-key", "", "File with secret key used to authenticate with the GitLab API")
gitlabClientHTTPTimeout = flag.Duration("gitlab-client-http-timeout", 10*time.Second, "GitLab API HTTP client connection timeout in seconds (default: 10s)")
gitlabClientJWTExpiry = flag.Duration("gitlab-client-jwt-expiry", 30*time.Second, "JWT Token expiry time in seconds (default: 30s)")
@@ -107,6 +108,14 @@ func gitlabServerFromFlags() string {
return host.FromString(url.Host)
}
+func internalGitLabServerFromFlags() string {
+ if *internalGitLabServer != "" {
+ return *internalGitLabServer
+ }
+
+ return gitlabServerFromFlags()
+}
+
func setArtifactsServer(artifactsServer string, artifactsServerTimeout int, config *appConfig) {
u, err := url.Parse(artifactsServer)
if err != nil {
@@ -181,6 +190,7 @@ func configFromFlags() appConfig {
}
config.GitLabServer = gitlabServerFromFlags()
+ config.InternalGitLabServer = internalGitLabServerFromFlags()
config.GitlabClientHTTPTimeout = *gitlabClientHTTPTimeout
config.GitlabJWTTokenExpiration = *gitlabClientJWTExpiry
config.StoreSecret = *secret
@@ -265,6 +275,7 @@ func loadConfig() appConfig {
"tls-max-version": *tlsMaxVersion,
"use-http-2": config.HTTP2,
"gitlab-server": config.GitLabServer,
+ "internal-gitlab-server": config.InternalGitLabServer,
"api-secret-key": *gitLabAPISecretKey,
"auth-redirect-uri": config.RedirectURI,
}).Debug("Start daemon with configuration")
diff --git a/metrics/metrics.go b/metrics/metrics.go
index 7ae50c81..bb14de04 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -47,6 +47,12 @@ var (
Help: "The number of GitLab domains API cache misses",
})
+ // DomainsSourceFailures is the number of GitLab API calls that failed
+ DomainsSourceFailures = prometheus.NewCounter(prometheus.CounterOpts{
+ Name: "gitlab_pages_domains_source_failures_total",
+ Help: "The number of GitLab API calls that failed",
+ })
+
// ServerlessRequests measures the amount of serverless invocations
ServerlessRequests = prometheus.NewCounter(prometheus.CounterOpts{
Name: "gitlab_pages_serverless_requests",
@@ -84,6 +90,7 @@ func MustRegister() {
DomainsSourceCacheMiss,
DomainsSourceAPIReqTotal,
DomainsSourceAPICallDuration,
+ DomainsSourceFailures,
ServerlessRequests,
ServerlessLatency,
)