-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
24 changes: 24 additions & 0 deletions
24
components/public-api-server/pkg/proxy/prometheusmetrics.go
This file contains 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,24 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package proxy | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"time" | ||
) | ||
|
||
func reportConnectionDuration(d time.Duration) { | ||
proxyConnectionCreateDurationSeconds.Observe(d.Seconds()) | ||
} | ||
|
||
var proxyConnectionCreateDurationSeconds = prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: "gitpod", | ||
Name: "public_api_proxy_connection_create_duration_seconds", | ||
Help: "Histogram of connection time in seconds", | ||
}) | ||
|
||
func RegisterMetrics(registry *prometheus.Registry) { | ||
registry.MustRegister(proxyConnectionCreateDurationSeconds) | ||
} |
38 changes: 38 additions & 0 deletions
38
components/public-api-server/pkg/proxy/prometheusmetrics_test.go
This file contains 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,38 @@ | ||
package proxy | ||
|
||
import ( | ||
"context" | ||
"github.com/gitpod-io/gitpod/common-go/baseserver" | ||
v1 "github.com/gitpod-io/gitpod/public-api/v1" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/metadata" | ||
"testing" | ||
) | ||
|
||
func TestConnectionCreationWasTracked(t *testing.T) { | ||
// Set up server | ||
srv := baseserver.NewForTests(t) | ||
baseserver.StartServerForTests(t, srv) | ||
|
||
// Set up Prometheus registry | ||
registry := prometheus.NewRegistry() | ||
registry.MustRegister(proxyConnectionCreateDurationSeconds) | ||
|
||
// Set up Workspace client | ||
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", "some-token") | ||
conn, err := grpc.Dial(srv.GRPCAddress(), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
client := v1.NewWorkspacesServiceClient(conn) | ||
|
||
// Call GetWorkspace | ||
client.GetWorkspace(ctx, &v1.GetWorkspaceRequest{ | ||
WorkspaceId: "some-ID", | ||
}) | ||
|
||
count, err := testutil.GatherAndCount(registry) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, count) | ||
} |
This file contains 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
This file contains 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