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 invalid UTF-8 data. #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions echoprometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"sort"
"strconv"
"strings"
"time"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/expfmt"
"io"
"net/http"
"sort"
"strconv"
"time"
)

const (
Expand Down Expand Up @@ -273,10 +275,17 @@ func (conf MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
values[2] = c.Request().Host
values[3] = url
for _, cv := range customValuers {
values[cv.index] = cv.valueFunc(c, err)
values[cv.index] = strings.ToValidUTF8(cv.valueFunc(c, err), "�")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is necessary. It should be up to valueFunc creator to handle this.

}

requestDuration.WithLabelValues(values...).Observe(elapsed)
// The first metric set is done this way to ensure
// that the values all contain valid UTF8. If not, it
// returns, if they are then .WithLabelValues is fine.
if obs, tmpErr := requestDuration.GetMetricWithLabelValues(values...); tmpErr == nil {
obs.Observe(elapsed)
} else {
return fmt.Errorf("requestDuration observation failed, err: %w", tmpErr)
}
requestCount.WithLabelValues(values...).Inc()
requestSize.WithLabelValues(values...).Observe(float64(reqSz))
responseSize.WithLabelValues(values...).Observe(float64(c.Response().Size))
Expand Down