Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api-server/pkg/proxy/prometheusmetrics_test.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package proxy
6
7
import (
8
"context"
9
"testing"
10
11
"github.com/gitpod-io/gitpod/common-go/baseserver"
12
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
13
"github.com/prometheus/client_golang/prometheus"
14
"github.com/prometheus/client_golang/prometheus/testutil"
15
"github.com/stretchr/testify/assert"
16
"google.golang.org/grpc"
17
"google.golang.org/grpc/credentials/insecure"
18
"google.golang.org/grpc/metadata"
19
)
20
21
func TestConnectionCreationWasTracked(t *testing.T) {
22
// Set up server
23
srv := baseserver.NewForTests(t,
24
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
25
)
26
baseserver.StartServerForTests(t, srv)
27
28
// Set up Prometheus registry
29
registry := prometheus.NewRegistry()
30
registry.MustRegister(proxyConnectionCreateDurationSeconds)
31
32
// Set up Workspace client
33
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", "some-token")
34
conn, _ := grpc.Dial(srv.GRPCAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
35
client := v1.NewWorkspacesServiceClient(conn)
36
37
// Call GetWorkspace
38
client.GetWorkspace(ctx, &v1.GetWorkspaceRequest{
39
WorkspaceId: "some-ID",
40
})
41
42
count, err := testutil.GatherAndCount(registry)
43
assert.NoError(t, err)
44
assert.Equal(t, 1, count)
45
}
46
47