Skip to content

Commit

Permalink
Merge pull request #25 from delta10/chore/remove-logging-from-filter-…
Browse files Browse the repository at this point in the history
…proxy

Remove logging from filter-proxy
  • Loading branch information
bartjkdp authored Dec 10, 2023
2 parents 7dc15b4 + ecd042f commit e2f8cf9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 136 deletions.
33 changes: 1 addition & 32 deletions cmd/filter-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/itchyny/gojq"

"github.com/delta10/filter-proxy/internal/config"
"github.com/delta10/filter-proxy/internal/logs"
"github.com/delta10/filter-proxy/internal/route"
"github.com/delta10/filter-proxy/internal/utils"
)
Expand Down Expand Up @@ -54,7 +53,7 @@ func main() {

utils.DelHopHeaders(r.Header)

authorizationStatusCode, authorizationResponse := authorizeRequestWithService(config, path, r)
authorizationStatusCode, _ := authorizeRequestWithService(config, path, r)
if authorizationStatusCode != http.StatusOK {
writeError(w, authorizationStatusCode, "unauthorized request")
return
Expand Down Expand Up @@ -182,36 +181,6 @@ func main() {
return
}

if path.LogBackend != "" {
logBackendName, ok := config.LogBackends[path.LogBackend]
if !ok {
writeError(w, http.StatusInternalServerError, "could not find log backend: "+path.LogBackend)
return
}

logBackend := logs.NewLogBackend(logBackendName)

labels := map[string]string{
"system": "filter-proxy",
"backend": path.Backend.Slug,
}

logLine := map[string]string{
"method": r.Method,
"path": r.URL.String(),
"status": proxyResp.Status,
"user_id": fmt.Sprint(authorizationResponse.User.Id),
"user_username": authorizationResponse.User.Username,
"ip": utils.ReadUserIP(r),
}

err := logBackend.WriteLog(labels, logLine)
if err != nil {
writeError(w, http.StatusInternalServerError, "could not write log to backend")
return
}
}

defer proxyResp.Body.Close()

if path.ResponseRewrite != "" && proxyResp.StatusCode == http.StatusOK {
Expand Down
8 changes: 0 additions & 8 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ authorizationServiceUrl: http://localhost:8000/atlas/api/v1/authorize

paths:
- path: /api/ows
logBackend: loki
backend:
slug: geoserver
path: /ows
Expand Down Expand Up @@ -40,7 +39,6 @@ paths:
backend:
slug: haal-centraal-brk
path: /kadastraalonroerendezaken/{kadastraalOnroerendeZaakIdentificatie:[0-9]+}
logBackend: loki
responseRewrite: |
{
aardCultuurBebouwd: .aardCultuurBebouwd,
Expand All @@ -60,7 +58,6 @@ paths:
backend:
slug: haal-centraal-brk
path: /kadastraalonroerendezaken/{kadastraalOnroerendeZaakIdentificatie:[0-9]+}/zakelijkgerechtigden
logBackend: loki
responseRewrite: |
{
"_embedded": {
Expand Down Expand Up @@ -102,7 +99,6 @@ paths:
backend:
slug: haal-centraal-brk
path: /publiekrechtelijkebeperkingen
logBackend: loki
responseRewrite: |
{
"_embedded": {
Expand Down Expand Up @@ -153,7 +149,3 @@ backends:
rootCertificates: .vscode/pki-o-g1.crt
header:
apikey: ${KVK_API_KEY}

logBackends:
loki:
baseUrl: http://localhost:3100/loki
14 changes: 4 additions & 10 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,20 @@ type Path struct {
Slug string `yaml:"slug"`
Path string `yaml:"path"`
} `yaml:"backend"`
LogBackend string `yaml:"logBackend"`
RequestRewrite string `yaml:"requestRewrite"`
ResponseRewrite string `yaml:"responseRewrite"`
}

type LogBackend struct {
BaseURL string `yaml:"baseUrl"`
}

type Config struct {
ListenAddress string `yaml:"listenAddress"`
ListenTLS struct {
Certificate string `yaml:"certificate"`
Key string `yaml:"key"`
} `yaml:"listenTls"`
AuthorizationServiceURL string `yaml:"authorizationServiceUrl"`
JwksURL string `yaml:"jwksUrl"`
Paths []Path `yaml:"paths"`
Backends map[string]Backend `yaml:"backends"`
LogBackends map[string]LogBackend `yaml:"logBackends"`
AuthorizationServiceURL string `yaml:"authorizationServiceUrl"`
JwksURL string `yaml:"jwksUrl"`
Paths []Path `yaml:"paths"`
Backends map[string]Backend `yaml:"backends"`
}

// NewConfig returns a new decoded Config struct
Expand Down
86 changes: 0 additions & 86 deletions internal/logs/logs.go

This file was deleted.

0 comments on commit e2f8cf9

Please sign in to comment.