Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPTS 0.7.2 #13

Merged
merged 6 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions application/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ var (
// HealthchecksPort determines the port number on which liveness & readiness endpoints will be running (defaults to 8081)
HealthchecksPort = getIntegerFromEnvironment("GPTS_HEALTHCHECKS_PORT", 8081)

// DefaultConfigOnStartup determines if default config should be loaded when application starts
// ConfigurationEndpoint determines the path of the configuration endpoint (defaults to /config)
ConfigurationEndpoint = getStringFromEnvironment("GPTS_CONFIG_ENDPOINT", "/config")

// DefaultConfigOnStartup determines if default config should be loaded when application starts (defaults to false)
DefaultConfigOnStartup = getBooleanFromEnvironment("GPTS_DEFAULT_CONFIG_ON_STARTUP", false)

// PrettyLog determines if pretty logging should be enabled
// PrettyLog determines if pretty logging should be enabled (defaults to false)
PrettyLog = getBooleanFromEnvironment("GPTS_PRETTY_LOG", false)

// LogLevel determines the level of application log
// LogLevel determines the level of application log (defaults to "info")
LogLevel = getStringFromEnvironment("GPTS_LOG_LEVEL", "info")
)
2 changes: 1 addition & 1 deletion application/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
4 changes: 2 additions & 2 deletions application/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
6 changes: 4 additions & 2 deletions application/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func init() {
flag.IntVar(&common.ServicePort, "service-port", common.ServicePort, "Port on which the service will be running")
flag.IntVar(&common.HealthchecksPort, "health-port", common.HealthchecksPort, "Port on which the healthchecks will be running")
flag.StringVar(&common.ConfigurationEndpoint, "config-endpoint", common.ConfigurationEndpoint, "Path of the configuration endpoint")
flag.BoolVar(&common.DefaultConfigOnStartup, "default-config", common.DefaultConfigOnStartup, "Enables loading the default configuration on startup")
flag.BoolVar(&common.PrettyLog, "pretty-log", common.PrettyLog, "Enables the pretty logger")
flag.StringVar(&common.LogLevel, "log-level", common.LogLevel, "Global log level; one of [debug, info, warn, error, fatal, panic, trace]")
Expand All @@ -39,7 +40,8 @@ func main() {
l.Info().
Int("servicePort", common.ServicePort).
Int("healthchecksPort", common.HealthchecksPort).
Msg("starting application")
Str("configurationEndpoint", common.ConfigurationEndpoint).
Msg("starting application with provided configuration")

healthServer := health.PrepareHealthEndpoints(log, common.HealthchecksPort)
go func() {
Expand All @@ -62,7 +64,7 @@ func main() {
health.ServiceStatus.SetStatus(true)
if err := server.ListenAndServe(); err != nil {
if service.ExpectingShutdown && err == http.ErrServerClosed {
l.Info().Msg("service has been shut down for planned maintenance")
l.Info().Msg("service has been shut down for configuration change")
} else {
l.Fatal().Err(err).Msg("service has been shut down unexpectedly")
}
Expand Down
2 changes: 1 addition & 1 deletion application/service/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func PrepareServer(log zerolog.Logger, port int) *http.Server {
Addr: fmt.Sprintf(":%d", port),
}

r.HandleFunc("/config", getConfigHandlerFunction(l, server))
r.HandleFunc(common.ConfigurationEndpoint, getConfigHandlerFunction(l, server))

entries := config.CurrentConfiguration.GetConfiguration()
sortedRoutes := getSortedRoutes(entries)
Expand Down
4 changes: 2 additions & 2 deletions application/service/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func TestPrepareServer(t *testing.T) {
method: http.MethodGet,
path: "/",
expectedStatus: http.StatusOK,
expectedKeys: &[]string{"host", "path", "method", "headers"},
expectedKeys: &[]string{"host", "path", "method", "headers", "queries"},
},
"get default endpoint on other path": {
method: http.MethodGet,
path: "/a/b/c",
expectedStatus: http.StatusOK,
expectedKeys: &[]string{"host", "path", "method", "headers"},
expectedKeys: &[]string{"host", "path", "method", "headers", "queries"},
},
"get on multiple-methods route": {
method: http.MethodGet,
Expand Down
15 changes: 13 additions & 2 deletions application/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getConfigHandlerFunction(log zerolog.Logger, server *http.Server) func(w ht
Dict(
"endpoint",
zerolog.Dict().
Str("path", "/config").
Str("path", common.ConfigurationEndpoint).
Str("type", "builtin"),
).
Logger()
Expand Down Expand Up @@ -121,11 +121,22 @@ func getDefaultHandler(log zerolog.Logger) http.Handler {
).
Logger()

headers := map[string]string{}
for key, value := range r.Header {
headers[key] = strings.Join(value, ",")
}

queries := map[string]string{}
for key, value := range r.URL.Query() {
queries[key] = strings.Join(value, ",")
}

response := defaultResponse{
Host: r.Host,
Path: r.URL.Path,
Method: r.Method,
Headers: r.Header,
Headers: headers,
Queries: queries,
}

mediaType := r.Header.Get("Accept")
Expand Down
9 changes: 5 additions & 4 deletions application/service/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package service

type defaultResponse struct {
Host string `json:"host" yaml:"host"`
Path string `json:"path" yaml:"path"`
Method string `json:"method" yaml:"method"`
Headers map[string][]string `json:"headers" yaml:"headers"`
Host string `json:"host" yaml:"host"`
Path string `json:"path" yaml:"path"`
Method string `json:"method" yaml:"method"`
Headers map[string]string `json:"headers" yaml:"headers"`
Queries map[string]string `json:"queries" yaml:"queries"`
}
12 changes: 11 additions & 1 deletion chart/gpts/Chart.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
apiVersion: v2
name: gpts
description: GPTS - General Purpose Test Service
keywords:
- golang
- testing tools
- test service
type: application
version: [[GPTS_VERSION]]
appVersion: "[[GPTS_VERSION]]"
icon: https://github.com/Icikowski/GPTS/raw/master/.assets/helm_icon.png
home: https://icikowski.github.io/GPTS
icon: https://github.com/Icikowski/GPTS/raw/master/.assets/helm_icon.png
sources:
- https://github.com/Icikowski/GPTS
maintainers:
- name: Piotr Icikowski
url: https://icikowski.pl
10 changes: 5 additions & 5 deletions chart/gpts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Expand the name of the chart.
*/}}
{{- define "gpts.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- default .Chart.Name .Values.overrides.name | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Expand All @@ -11,10 +11,10 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
If release name contains chart name it will be used as a full name.
*/}}
{{- define "gpts.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- if .Values.overrides.fullname }}
{{- .Values.overrides.fullname | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- $name := default .Chart.Name .Values.overrides.name }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand Down Expand Up @@ -48,4 +48,4 @@ Selector labels
{{- define "gpts.selectorLabels" -}}
app.kubernetes.io/name: {{ include "gpts.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- end }}
16 changes: 14 additions & 2 deletions chart/gpts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
labels:
{{- include "gpts.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -27,13 +27,15 @@ spec:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
image: "{{ .Values.overrides.repository | default "ghcr.io" }}/{{ .Values.overrides.image | default "icikowski/gpts" }}:{{ .Values.overrides.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: GPTS_SERVICE_PORT
value: {{ .Values.gpts.servicePort | default 8080 | quote }}
- name: GPTS_HEALTHCHECKS_PORT
value: {{ .Values.gpts.healthchecksPort | default 8081 | quote }}
- name: GPTS_CONFIG_ENDPOINT
value: {{ .Values.gpts.configEndpoint | default "/config" | quote }}
- name: GPTS_DEFAULT_CONFIG_ON_STARTUP
value: {{ .Values.gpts.defaultConfigOnStartup | default "false" | quote }}
- name: GPTS_LOG_LEVEL
Expand All @@ -44,14 +46,24 @@ spec:
- name: http
containerPort: {{ .Values.gpts.servicePort | default 8080 }}
protocol: TCP
startupProbe:
httpGet:
path: /health
port: {{ .Values.gpts.healthcheckPort | default 8081 }}
failureThreshold: 6
periodSeconds: 5
livenessProbe:
httpGet:
path: /live
port: {{ .Values.gpts.healthcheckPort | default 8081 }}
failureThreshold: 3
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: {{ .Values.gpts.healthcheckPort | default 8081 }}
failureThreshold: 3
periodSeconds: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
30 changes: 17 additions & 13 deletions chart/gpts/values.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
image:
repository: ghcr.io/icikowski/gpts
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
overrides:
name: ""
fullname: ""

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
# Overrides the image repository whose default is "ghcr.io"
repository: ""
# Overrides the image name whose default is "icikowski/gpts"
image: ""
# Overrides the image tag whose default is the chart appVersion
tag: ""

# This section allows to configure the GPTS application. Please refer to the
# documentation for more information about available values:
# https://icikowski.github.io/GPTS/installation/k8s/#changing-configuration-values-in-chart
gpts:
servicePort: 8080
healthchecksPort: 8081
configEndpoint: /config
defaultConfigOnStartup: false
logLevel: info
# Available log levels:
# debug, info, warn, error, fatal, panic, trace

# Enabling pretty log can make the logs more user-friendly
# but is NOT RECOMMENDED as it impacts the performance a lot
prettyLog: false

image:
pullPolicy: IfNotPresent
pullSecrets: []

service:
type: ClusterIP
port: 80
Expand Down
16 changes: 16 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Project changelog

## GPTS 0.7.2

- Updated chart definition
- Added startup probe
- Changed default values of `failureThreshold` and `periodSeconds` of all probes
- Added `overrides` section to override name, fullname, image repository, image name & image tag
- Added reference for GPTS' documentation for charts' values
- Added metadata to Chart.yaml
- Added support for configurable configuration endpoint's address
- Upgraded project's dependencies
- Changed default handler's response structure
- Headers' values are now returned as single comma-separated string instead of list
- Added query values logging
- Updated OpenAPI specification
- Updated documentation

## GPTS 0.7.1

- Upgraded project's dependencies
Expand Down
3 changes: 2 additions & 1 deletion docs/installation/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can use one of following commands in order to get the application up and run

???- summary "Example command execution & output"
```bash
docker run --rm -it -p 80:80 -p 8000:8000 ghcr.io/icikowski/gpts:0.1.0
docker run --rm -it -p 80:80 -p 8000:8000 ghcr.io/icikowski/gpts:0.6.2
```
```
Unable to find image 'ghcr.io/icikowski/gpts:0.6.2' locally
Expand Down Expand Up @@ -89,6 +89,7 @@ services:
# environment:
# - GPTS_SERVICE_PORT=80
# - GPTS_HEALTHCHECKS_PORT=8081
# - GPTS_CONFIG_ENDPOINT=/config
# - GPTS_DEFAULT_CONFIG_ON_STARTUP=false
# - GPTS_LOG_LEVEL=info
# - GPTS_PRETTY_LOG=false
Expand Down
Loading