Skip to content

Commit

Permalink
📖 Add API documentation for metrics endpoint (#380)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam authored Jun 8, 2023
1 parent 47c345a commit 709437f
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 150 deletions.
19 changes: 19 additions & 0 deletions api/metric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package api

import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)

// MetricsHandler godoc
// @summary Get Prometheus metrics.
// @description Get Prometheus metrics.
// @description Wrapper for Prometheus-supplied handler.
// @description Served on port defined by METRICS_PORT environment variable.
// @tags metrics
// @produce text/plain
// @success 200
// @router /metrics [get]
func MetricsHandler() http.Handler {
return promhttp.Handler()
}
3 changes: 1 addition & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/konveyor/tackle2-hub/settings"
"github.com/konveyor/tackle2-hub/task"
"github.com/konveyor/tackle2-hub/tracker"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gorm.io/gorm"
"k8s.io/client-go/kubernetes/scheme"
"net/http"
Expand Down Expand Up @@ -180,7 +179,7 @@ func main() {
// Metrics
if Settings.Metrics.Enabled {
log.Info("Serving Prometheus metrics", "port", Settings.Metrics.Port)
http.Handle("/metrics", promhttp.Handler())
http.Handle("/metrics", api.MetricsHandler())
go func() {
_ = http.ListenAndServe(Settings.Metrics.Address(), nil)
}()
Expand Down
33 changes: 19 additions & 14 deletions docs/binding.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ func (h *Adapter) Client() *Client

func (h *Adapter) Run(addon func() error)
Run addon. Reports:

- Started
- Succeeded
- Failed (when addon returns error).
- Started
- Succeeded
- Failed (when addon returns error).

type Analysis struct {
// Has unexported fields.
}
Analysis API.

func (h *Analysis) Create(issues, deps string) (analysis *api.Analysis, err error)
func (h *Analysis) Create(r *api.Analysis, encoding string, issues, deps io.Reader) (err error)
Create an analysis report.

type AppFacts struct {
Expand Down Expand Up @@ -176,15 +175,15 @@ func (r *Client) BucketPut(source, destination string) (err error)
func (r *Client) Delete(path string, params ...Param) (err error)
Delete a resource.

func (r *Client) FileForm(path, method string, files []FileField, object interface{}) (err error)
FileForm upload files.

func (r *Client) FileGet(path, destination string) (err error)
FileGet downloads a file.

func (r *Client) FilePut(path, source string, object interface{}) (err error)
FilePut uploads a file. Returns the created File resource.

func (r *Client) FileSend(path, method string, fields []Field, object interface{}) (err error)
FileSend sends file upload from.

func (r *Client) Get(path string, object interface{}, params ...Param) (err error)
Get a resource.

Expand All @@ -210,6 +209,18 @@ func (e Conflict) Error() string

func (e *Conflict) Is(err error) (matched bool)

type Field struct {
Name string
Path string
Reader io.Reader
Encoding string
}
Field file upload form field.

func (f *Field) Write(writer io.Writer) (err error)
Write the field content. When Reader is not set, the path is opened and
copied.

type File struct {
// Has unexported fields.
}
Expand All @@ -224,12 +235,6 @@ func (h *File) Get(id uint, destination string) (err error)
func (h *File) Put(source string) (r *api.File, err error)
Put uploads a file.

type FileField struct {
Name string
Path string
}
FileField form file fields.

type Identity struct {
// Has unexported fields.
}
Expand Down
23 changes: 20 additions & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const docTemplate = `{
},
"/analyses/issues": {
"get": {
"description": "List all issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels\n- application.(id|name)\n- tag.id",
"description": "List all issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels\n- application.id\n- application.name\n- tag.id",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -350,7 +350,7 @@ const docTemplate = `{
},
"/application/{id}/analysis/dependencies": {
"get": {
"description": "List application dependencies.\nfilters:\n- id\n- name\n- version\n- type\n- sha\n- indirect",
"description": "List application dependencies.\nfilters:\n- name\n- version\n- sha\n- indirect\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -382,7 +382,7 @@ const docTemplate = `{
},
"/application/{id}/analysis/issues": {
"get": {
"description": "List application issues.\nfilters:\n- id\n- ruleid\n- name\n- category\n- effort",
"description": "List application issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2251,6 +2251,23 @@ const docTemplate = `{
}
}
},
"/metrics": {
"get": {
"description": "Get Prometheus metrics.\nWrapper for Prometheus-supplied handler.\nServed on port defined by METRICS_PORT environment variable.",
"produces": [
"text/plain"
],
"tags": [
"metrics"
],
"summary": "Get Prometheus metrics.",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/migrationwaves": {
"get": {
"description": "List all migration waves.",
Expand Down
359 changes: 236 additions & 123 deletions docs/index.html

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
},
"/analyses/issues": {
"get": {
"description": "List all issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels\n- application.(id|name)\n- tag.id",
"description": "List all issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels\n- application.id\n- application.name\n- tag.id",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -338,7 +338,7 @@
},
"/application/{id}/analysis/dependencies": {
"get": {
"description": "List application dependencies.\nfilters:\n- id\n- name\n- version\n- type\n- sha\n- indirect",
"description": "List application dependencies.\nfilters:\n- name\n- version\n- sha\n- indirect\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -370,7 +370,7 @@
},
"/application/{id}/analysis/issues": {
"get": {
"description": "List application issues.\nfilters:\n- id\n- ruleid\n- name\n- category\n- effort",
"description": "List application issues.\nfilters:\n- ruleset\n- rule\n- name\n- category\n- effort\n- labels",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2239,6 +2239,23 @@
}
}
},
"/metrics": {
"get": {
"description": "Get Prometheus metrics.\nWrapper for Prometheus-supplied handler.\nServed on port defined by METRICS_PORT environment variable.",
"produces": [
"text/plain"
],
"tags": [
"metrics"
],
"summary": "Get Prometheus metrics.",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/migrationwaves": {
"get": {
"description": "List all migration waves.",
Expand Down
25 changes: 20 additions & 5 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,8 @@ paths:
- category
- effort
- labels
- application.(id|name)
- application.id
- application.name
- tag.id
produces:
- application/json
Expand Down Expand Up @@ -1227,12 +1228,11 @@ paths:
description: |-
List application dependencies.
filters:
- id
- name
- version
- type
- sha
- indirect
- labels
parameters:
- description: Application ID
in: path
Expand All @@ -1256,11 +1256,12 @@ paths:
description: |-
List application issues.
filters:
- id
- ruleid
- ruleset
- rule
- name
- category
- effort
- labels
parameters:
- description: Application ID
in: path
Expand Down Expand Up @@ -2510,6 +2511,20 @@ paths:
summary: Update a job function.
tags:
- jobfunctions
/metrics:
get:
description: |-
Get Prometheus metrics.
Wrapper for Prometheus-supplied handler.
Served on port defined by METRICS_PORT environment variable.
produces:
- text/plain
responses:
"200":
description: OK
summary: Get Prometheus metrics.
tags:
- metrics
/migrationwaves:
get:
description: List all migration waves.
Expand Down

0 comments on commit 709437f

Please sign in to comment.