diff --git a/cmd/server/handler.go b/cmd/server/handler.go index c7da7e26991..5b5cf093cc1 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -50,9 +50,9 @@ import ( "github.com/ory/hydra/driver" "github.com/ory/hydra/driver/config" "github.com/ory/hydra/jwk" - "github.com/ory/hydra/metrics/prometheus" "github.com/ory/hydra/oauth2" "github.com/ory/hydra/x" + prometheus "github.com/ory/x/prometheusx" ) var _ = &consent.Handler{} @@ -94,6 +94,8 @@ func RunServeAdmin(cmd *cobra.Command, args []string) { admin, _, adminmw, _ := setup(d, cmd) cert := GetOrCreateTLSCertificate(cmd, d, config.AdminInterface) // we do not want to run this concurrently. + d.PrometheusManager().RegisterRouter(admin.Router) + var wg sync.WaitGroup wg.Add(1) @@ -118,6 +120,8 @@ func RunServePublic(cmd *cobra.Command, args []string) { _, public, _, publicmw := setup(d, cmd) cert := GetOrCreateTLSCertificate(cmd, d, config.PublicInterface) // we do not want to run this concurrently. + d.PrometheusManager().RegisterRouter(public.Router) + var wg sync.WaitGroup wg.Add(1) @@ -140,6 +144,9 @@ func RunServeAll(cmd *cobra.Command, args []string) { admin, public, adminmw, publicmw := setup(d, cmd) + d.PrometheusManager().RegisterRouter(admin.Router) + d.PrometheusManager().RegisterRouter(public.Router) + var wg sync.WaitGroup wg.Add(2) diff --git a/contrib/quickstart/5-min/hydra.yml b/contrib/quickstart/5-min/hydra.yml index df60e1f355e..8d69cc1d243 100644 --- a/contrib/quickstart/5-min/hydra.yml +++ b/contrib/quickstart/5-min/hydra.yml @@ -20,4 +20,3 @@ oidc: - public pairwise: salt: youReallyNeedToChangeThis - diff --git a/docs/docs/reference/api.mdx b/docs/docs/reference/api.mdx index fd73c01051f..f0c3ec58955 100644 --- a/docs/docs/reference/api.mdx +++ b/docs/docs/reference/api.mdx @@ -4608,28 +4608,28 @@ p JSON.parse(result) -### Get Snapshot Metrics from the Hydra Service. +### Get snapshot metrics from the Hydra service. If you're using k8s, you can then add annotations to + +your deployment like so: ``` GET /metrics/prometheus HTTP/1.1 ``` -If you're using k8s, you can then add annotations to your deployment like so: - ``` metadata: annotations: -prometheus.io/port: "4445" +prometheus.io/port: "4434" prometheus.io/path: "/metrics/prometheus" ``` -If the service supports TLS Edge Termination, this endpoint does not require the -`X-Forwarded-Proto` header to be set. - #### Responses - + ##### Overview @@ -8280,7 +8280,6 @@ _NullTime implements sql.NullTime functionality._ } ], "Interface": { - "ProtocolScheme": "string", "Socket": "string", "Types": [ { @@ -8388,7 +8387,6 @@ _PluginConfigArgs plugin config args_ ```json { - "ProtocolScheme": "string", "Socket": "string", "Types": [ { @@ -8404,11 +8402,10 @@ _PluginConfigInterface The interface between Docker and the plugin_ #### Properties -| Name | Type | Required | Restrictions | Description | -| -------------- | --------------------------------------------------- | -------- | ------------ | ----------------------------------------------------- | -| ProtocolScheme | string | false | none | Protocol to use for clients connecting to the plugin. | -| Socket | string | true | none | socket | -| Types | [[PluginInterfaceType](#schemaplugininterfacetype)] | true | none | types | +| Name | Type | Required | Restrictions | Description | +| ------ | --------------------------------------------------- | -------- | ------------ | ----------- | +| Socket | string | true | none | socket | +| Types | [[PluginInterfaceType](#schemaplugininterfacetype)] | true | none | types | @@ -8806,7 +8803,7 @@ _Volume volume_ | Name | string | true | none | Name of the volume. | | Options | object | true | none | The driver specific options used when creating the volume. | | ยป **additionalProperties** | string | false | none | none | -| Scope | string | true | none | The level at which the volume exists. Either `global` for cluster-wide,
or `local` for machine level. | +| Scope | string | true | none | The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level. | | Status | object | false | none | Low-level details about the volume, provided by the volume driver.
Details are returned as a map with key/value pairs:
`{"key":"value","key2":"value2"}`.

The `Status` field is optional, and is omitted if the volume driver
does not support this feature. | | UsageData | [VolumeUsageData](#schemavolumeusagedata) | false | none | VolumeUsageData Usage details about the volume. This information is used by the
`GET /system/df` endpoint, and omitted in other endpoints. | diff --git a/driver/registry.go b/driver/registry.go index a5b5ba2a3b1..e27e05ae11a 100644 --- a/driver/registry.go +++ b/driver/registry.go @@ -14,7 +14,7 @@ import ( "github.com/ory/hydra/persistence" - "github.com/ory/hydra/metrics/prometheus" + prometheus "github.com/ory/x/prometheusx" "github.com/ory/x/dbal" "github.com/ory/x/healthx" diff --git a/driver/registry_base.go b/driver/registry_base.go index 8f412b033d8..e1013c76729 100644 --- a/driver/registry_base.go +++ b/driver/registry_base.go @@ -8,6 +8,8 @@ import ( "strings" "time" + prometheus "github.com/ory/x/prometheusx" + "github.com/pkg/errors" "github.com/ory/hydra/x/oauth2cors" @@ -16,7 +18,6 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/ory/hydra/metrics/prometheus" "github.com/ory/x/logrusx" "github.com/gorilla/sessions" @@ -442,7 +443,7 @@ func (m *RegistryBase) Tracer(ctx context.Context) *tracing.Tracer { func (m *RegistryBase) PrometheusManager() *prometheus.MetricsManager { if m.pmm == nil { - m.pmm = prometheus.NewMetricsManager(m.buildVersion, m.buildHash, m.buildDate) + m.pmm = prometheus.NewMetricsManager("hydra", m.buildVersion, m.buildHash, m.buildDate) } return m.pmm } diff --git a/go.mod b/go.mod index e2c32cccef3..09423890825 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/ory/go-acc v0.2.6 github.com/ory/graceful v0.1.1 github.com/ory/herodot v0.9.3 - github.com/ory/x v0.0.233 + github.com/ory/x v0.0.237 github.com/pborman/uuid v1.2.1 github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/philhofer/fwd v1.1.1 // indirect diff --git a/go.sum b/go.sum index 5fd6e757159..9f4bc4d5872 100644 --- a/go.sum +++ b/go.sum @@ -1210,6 +1210,8 @@ github.com/ory/x v0.0.205/go.mod h1:A1s4iwmFIppRXZLF3J9GGWeY/HpREVm0Dk5z/787iek= github.com/ory/x v0.0.207/go.mod h1:sBgvUAcmc2lmtOBe5VMcV2vNAlADT4bkFHomG29y7N4= github.com/ory/x v0.0.233 h1:AiBvucFkE054XJ04OnUziM9Ect5nR/NbMe5101EBjVE= github.com/ory/x v0.0.233/go.mod h1:0mSGWLFgcqckIvgexka1GJK/sshYrFFkU7lPajzGTFw= +github.com/ory/x v0.0.237 h1:sFcWr8EcOYrPb30tsWk3BZM7jdzHeBAqaOSHveizmfs= +github.com/ory/x v0.0.237/go.mod h1:KPgNsUzpztH15EZdw5HjurtTe+mXQ34yqMCCTb5BZAc= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/internal/httpclient/client/admin/admin_client.go b/internal/httpclient/client/admin/admin_client.go index d22fd62c981..4f24f592597 100644 --- a/internal/httpclient/client/admin/admin_client.go +++ b/internal/httpclient/client/admin/admin_client.go @@ -972,19 +972,14 @@ func (a *Client) PatchOAuth2Client(params *PatchOAuth2ClientParams) (*PatchOAuth } /* - Prometheus gets snapshot metrics from the hydra service + Prometheus gets snapshot metrics from the hydra service if you re using k8s you can then add annotations to your deployment like so - If you're using k8s, you can then add annotations to your deployment like so: - -``` + ``` metadata: annotations: -prometheus.io/port: "4445" +prometheus.io/port: "4434" prometheus.io/path: "/metrics/prometheus" ``` - -If the service supports TLS Edge Termination, this endpoint does not require the -`X-Forwarded-Proto` header to be set. */ func (a *Client) Prometheus(params *PrometheusParams) (*PrometheusOK, error) { // TODO: Validate the params before sending diff --git a/internal/httpclient/client/public/public_client.go b/internal/httpclient/client/public/public_client.go index 83b631bd34e..c5e30ab557d 100644 --- a/internal/httpclient/client/public/public_client.go +++ b/internal/httpclient/client/public/public_client.go @@ -285,6 +285,10 @@ func (a *Client) RevokeOAuth2Token(params *RevokeOAuth2TokenParams, authInfo run the provided OAuth 2.0 Access Token. For more information please [refer to the spec](http://openid.net/specs/openid-connect-core-1_0.html#UserInfo). + +In the case of authentication error, a WWW-Authenticate header might be set in the response +with more information about the error. See [the spec](https://datatracker.ietf.org/doc/html/rfc6750#section-3) +for more details about header format. */ func (a *Client) Userinfo(params *UserinfoParams, authInfo runtime.ClientAuthInfoWriter) (*UserinfoOK, error) { // TODO: Validate the params before sending diff --git a/internal/httpclient/models/plugin_config_interface.go b/internal/httpclient/models/plugin_config_interface.go index 43b13c30c2e..ccf8fc422dc 100644 --- a/internal/httpclient/models/plugin_config_interface.go +++ b/internal/httpclient/models/plugin_config_interface.go @@ -19,9 +19,6 @@ import ( // swagger:model PluginConfigInterface type PluginConfigInterface struct { - // Protocol to use for clients connecting to the plugin. - ProtocolScheme string `json:"ProtocolScheme,omitempty"` - // socket // Required: true Socket *string `json:"Socket"` diff --git a/internal/httpclient/models/volume.go b/internal/httpclient/models/volume.go index d777e291958..f278b8ac30b 100644 --- a/internal/httpclient/models/volume.go +++ b/internal/httpclient/models/volume.go @@ -40,8 +40,7 @@ type Volume struct { // Required: true Options map[string]string `json:"Options"` - // The level at which the volume exists. Either `global` for cluster-wide, - // or `local` for machine level. + // The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level. // Required: true Scope *string `json:"Scope"` diff --git a/metrics/prometheus/doc.go b/metrics/prometheus/doc.go deleted file mode 100644 index dbdf42d3d3d..00000000000 --- a/metrics/prometheus/doc.go +++ /dev/null @@ -1,26 +0,0 @@ -package prometheus - -// Outputs Prometheus metrics -// -// swagger:route GET /metrics/prometheus admin prometheus -// -// Get Snapshot Metrics from the Hydra Service. -// -// If you're using k8s, you can then add annotations to your deployment like so: -// -// ``` -// metadata: -// annotations: -// prometheus.io/port: "4445" -// prometheus.io/path: "/metrics/prometheus" -// ``` -// -// If the service supports TLS Edge Termination, this endpoint does not require the -// `X-Forwarded-Proto` header to be set. -// -// Produces: -// - plain/text -// -// Responses: -// 200: emptyResponse -func swaggerPublicPrometheus() {} diff --git a/metrics/prometheus/metrics.go b/metrics/prometheus/metrics.go deleted file mode 100644 index 23a4d71f87c..00000000000 --- a/metrics/prometheus/metrics.go +++ /dev/null @@ -1,68 +0,0 @@ -package prometheus - -import "github.com/prometheus/client_golang/prometheus" - -const ( - MetricsPrometheusPath = "/metrics/prometheus" -) - -// Metrics prototypes -// Example: -// Counter *prometheus.CounterVec -// ResponseTime *prometheus.HistogramVec -type Metrics struct { - ResponseTime *prometheus.HistogramVec -} - -// Method for creation new custom Prometheus metrics -// Example: -// pm := &Metrics{ -// Counter: prometheus.NewCounterVec( -// prometheus.CounterOpts{ -// Name: "servicename_requests_total", -// Help: "Description", -// ConstLabels: map[string]string{ -// "version": version, -// "hash": hash, -// "buildTime": buildTime, -// }, -// }, -// []string{"endpoint"}, -// ), -// ResponseTime: prometheus.NewHistogramVec( -// prometheus.HistogramOpts{ -// Name: "servicename_response_time_seconds", -// Help: "Description", -// ConstLabels: map[string]string{ -// "version": version, -// "hash": hash, -// "buildTime": buildTime, -// }, -// }, -// []string{"endpoint"}, -// ), -// } -// prometheus.Register(pm.Counter) -// prometheus.Register(pm.ResponseTime) -func NewMetrics(version, hash, date string) *Metrics { - pm := &Metrics{ - ResponseTime: prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Name: "hydra_response_time_seconds", - Help: "Description", - ConstLabels: map[string]string{ - "version": version, - "hash": hash, - "buildTime": date, - }, - }, - []string{"endpoint"}, - ), - } - err := prometheus.Register(pm.ResponseTime) - - if err != nil { - panic(err) - } - return pm -} diff --git a/metrics/prometheus/middleware.go b/metrics/prometheus/middleware.go deleted file mode 100644 index 8973dc7cb4a..00000000000 --- a/metrics/prometheus/middleware.go +++ /dev/null @@ -1,31 +0,0 @@ -package prometheus - -import ( - "net/http" - "time" -) - -type MetricsManager struct { - prometheusMetrics *Metrics -} - -func NewMetricsManager(version, hash, buildTime string) *MetricsManager { - return &MetricsManager{ - prometheusMetrics: NewMetrics(version, hash, buildTime), - } -} - -// Main middleware method to collect metrics for Prometheus. -// Example: -// start := time.Now() -// next(rw, r) -// Request counter metric -// pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc() -// Response time metric -// pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds()) -func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - start := time.Now() - next(rw, r) - - pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds()) -} diff --git a/spec/api.json b/spec/api.json index c5b2f6a4c28..7c55ebf53a2 100755 --- a/spec/api.json +++ b/spec/api.json @@ -846,14 +846,14 @@ }, "/metrics/prometheus": { "get": { - "description": "If you're using k8s, you can then add annotations to your deployment like so:\n\n```\nmetadata:\nannotations:\nprometheus.io/port: \"4445\"\nprometheus.io/path: \"/metrics/prometheus\"\n```\n\nIf the service supports TLS Edge Termination, this endpoint does not require the\n`X-Forwarded-Proto` header to be set.", + "description": "```\nmetadata:\nannotations:\nprometheus.io/port: \"4434\"\nprometheus.io/path: \"/metrics/prometheus\"\n```", "produces": [ "plain/text" ], "tags": [ "admin" ], - "summary": "Get Snapshot Metrics from the Hydra Service.", + "summary": "Get snapshot metrics from the Hydra service. If you're using k8s, you can then add annotations to\nyour deployment like so:", "operationId": "prometheus", "responses": { "200": { @@ -2159,10 +2159,6 @@ "Types" ], "properties": { - "ProtocolScheme": { - "description": "Protocol to use for clients connecting to the plugin.", - "type": "string" - }, "Socket": { "description": "socket", "type": "string" @@ -2505,7 +2501,7 @@ } }, "Scope": { - "description": "The level at which the volume exists. Either `global` for cluster-wide,\nor `local` for machine level.", + "description": "The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level.", "type": "string" }, "Status": { diff --git a/x/tls_termination.go b/x/tls_termination.go index 7eb72d428a3..c9ba18b8281 100644 --- a/x/tls_termination.go +++ b/x/tls_termination.go @@ -10,8 +10,8 @@ import ( "github.com/pkg/errors" "github.com/urfave/negroni" - "github.com/ory/hydra/metrics/prometheus" "github.com/ory/x/healthx" + prometheus "github.com/ory/x/prometheusx" "github.com/ory/x/stringsx" )