Skip to content

Commit

Permalink
added support for filtering out unwanted URL parameters for metrics l…
Browse files Browse the repository at this point in the history
…ogging (#348)
  • Loading branch information
edisonguo authored Oct 3, 2019
1 parent f7acc3a commit bbf01a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type MetricsCollector struct {
logger Logger
}

var reservedQueryParams = map[string]bool{"bbox": true, "coverage": true, "crs": true, "dptol": true, "height": true, "identifier": true, "identitytol": true, "layer": true, "layers": true, "limit": true, "namespace": true, "nseg": true, "request": true, "service": true, "srs": true, "styles": true, "time": true, "until": true, "version": true, "width": true, "wkt": true}

func NewMetricsCollector(logger Logger) *MetricsCollector {
return &MetricsCollector{
Info: &MetricsInfo{
Expand Down Expand Up @@ -136,6 +138,9 @@ func (i *MetricsInfo) normaliseURL(u *URLInfo) error {
u.Query = make(map[string]string)
}
for k, v := range query {
if _, found := reservedQueryParams[k]; !found {
continue
}
if len(v) == 1 {
u.Query[k] = v[0]
} else if len(v) > 1 {
Expand Down
12 changes: 12 additions & 0 deletions ows.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,18 @@ func generalHandler(conf *utils.Config, w http.ResponseWriter, r *http.Request)
serveWCS(ctx, params, conf, r.URL.String(), w, query, metricsCollector)
case "WPS":
params, err := utils.WPSParamsChecker(query, reWPSMap)
if _, hasId := query["identifier"]; hasId && r.Method == "POST" {
if params.Identifier != nil {
url := metricsCollector.Info.URL.RawURL
var sep string
if len(query) > 0 {
sep = "&"
} else {
sep = "?"
}
metricsCollector.Info.URL.RawURL = fmt.Sprintf("%s%sidentifier=%s", url, sep, *params.Identifier)
}
}
if err != nil {
metricsCollector.Info.HTTPStatus = 400
http.Error(w, fmt.Sprintf("Wrong WPS parameters on URL: %s", err), 400)
Expand Down

0 comments on commit bbf01a4

Please sign in to comment.