- Notifications
You must be signed in to change notification settings - Fork1k
chore: add tx metrics and logs for serialization errors#15215
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
61c466a
chore: prometheus metrics to always include db transactions
Emyrk3543068
chore: add tx metrics and logs for serialization errors
Emyrk179ee27
Add test for the logs
Emyrkc7e53cd
add another metric for retries
Emyrke3f7006
add some tx labels
Emyrkd3bbe9b
spelling errors
Emyrk58288de
fixes
Emyrk3e4aa8e
fixes
Emyrk1781c7c
fix test
Emyrk3f1806c
fix sql tx references
Emyrk785fd6f
fix sql tx references
Emyrk3e41185
add tx identifiers
EmyrkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 3 additions & 1 deletioncli/server.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletioncli/testdata/coder_server_--help.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletioncli/testdata/server-config.yaml.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletioncoderd/autobuild/lifecycle_executor.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionscoderd/coderdtest/promhelp/doc.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package promhelp provides helper functions for asserting Prometheus | ||
// metric values in unit tests. | ||
package promhelp |
87 changes: 87 additions & 0 deletionscoderd/coderdtest/promhelp/metrics.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package promhelp | ||
import ( | ||
"context" | ||
"io" | ||
"maps" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
ptestutil "github.com/prometheus/client_golang/prometheus/testutil" | ||
io_prometheus_client "github.com/prometheus/client_model/go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
// RegistryDump returns the http page for a given registry's metrics. | ||
// Very useful for visual debugging. | ||
func RegistryDump(reg *prometheus.Registry) string { | ||
h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{}) | ||
rec := httptest.NewRecorder() | ||
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/", nil) | ||
h.ServeHTTP(rec, req) | ||
resp := rec.Result() | ||
data, _ := io.ReadAll(resp.Body) | ||
_ = resp.Body.Close() | ||
return string(data) | ||
} | ||
// Compare can be used to compare a registry to some prometheus formatted | ||
// text. If any values differ, an error is returned. | ||
// If metric names are passed in, only those metrics will be compared. | ||
// Usage: `Compare(reg, RegistryDump(reg))` | ||
func Compare(reg prometheus.Gatherer, compare string, metricNames ...string) error { | ||
return ptestutil.GatherAndCompare(reg, strings.NewReader(compare), metricNames...) | ||
} | ||
// HistogramValue returns the value of a histogram metric with the given name and labels. | ||
func HistogramValue(t testing.TB, reg prometheus.Gatherer, metricName string, labels prometheus.Labels) *io_prometheus_client.Histogram { | ||
t.Helper() | ||
labeled := MetricValue(t, reg, metricName, labels) | ||
require.NotNilf(t, labeled, "metric %q with labels %v not found", metricName, labels) | ||
return labeled.GetHistogram() | ||
} | ||
// GaugeValue returns the value of a gauge metric with the given name and labels. | ||
func GaugeValue(t testing.TB, reg prometheus.Gatherer, metricName string, labels prometheus.Labels) int { | ||
t.Helper() | ||
labeled := MetricValue(t, reg, metricName, labels) | ||
require.NotNilf(t, labeled, "metric %q with labels %v not found", metricName, labels) | ||
return int(labeled.GetGauge().GetValue()) | ||
} | ||
// CounterValue returns the value of a counter metric with the given name and labels. | ||
func CounterValue(t testing.TB, reg prometheus.Gatherer, metricName string, labels prometheus.Labels) int { | ||
t.Helper() | ||
labeled := MetricValue(t, reg, metricName, labels) | ||
require.NotNilf(t, labeled, "metric %q with labels %v not found", metricName, labels) | ||
return int(labeled.GetCounter().GetValue()) | ||
} | ||
func MetricValue(t testing.TB, reg prometheus.Gatherer, metricName string, labels prometheus.Labels) *io_prometheus_client.Metric { | ||
t.Helper() | ||
metrics, err := reg.Gather() | ||
require.NoError(t, err) | ||
for _, m := range metrics { | ||
if m.GetName() == metricName { | ||
for _, labeled := range m.GetMetric() { | ||
mLabels := make(prometheus.Labels) | ||
for _, v := range labeled.GetLabel() { | ||
mLabels[v.GetName()] = v.GetValue() | ||
} | ||
if maps.Equal(mLabels, labels) { | ||
return labeled | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} |
5 changes: 3 additions & 2 deletionscoderd/cryptokeys/rotate.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
69 changes: 61 additions & 8 deletionscoderd/database/db.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncoderd/database/db_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncoderd/database/dbauthz/dbauthz.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletioncoderd/database/dbmem/dbmem.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.