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

Remove logging from filter-proxy #25

Merged
merged 1 commit into from
Dec 10, 2023
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
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.

Loading