Skip to content

Commit e599084

Browse files
authored
Add logging for when Vizier registers (#1464)
Summary: We were recommended to add logging for when a Vizier registers. This is useful for auditing, so users can track when/who/how Viziers were registered to an org. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Unit tests Signed-off-by: Michelle Nguyen <michellenguyen@pixielabs.ai>
1 parent 8f3c268 commit e599084

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/cloud/vzmgr/deployment/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ go_library(
2727
"//src/cloud/vzmgr/vzmgrpb:service_pl_go_proto",
2828
"//src/utils",
2929
"@com_github_gofrs_uuid//:uuid",
30+
"@com_github_sirupsen_logrus//:logrus",
3031
"@org_golang_google_grpc//codes",
3132
"@org_golang_google_grpc//status",
3233
],

src/cloud/vzmgr/deployment/deployment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323

2424
"github.com/gofrs/uuid"
25+
log "github.com/sirupsen/logrus"
2526
"google.golang.org/grpc/codes"
2627
"google.golang.org/grpc/status"
2728

@@ -32,7 +33,7 @@ import (
3233

3334
// InfoFetcher fetches information about deployments using the key.
3435
type InfoFetcher interface {
35-
FetchOrgUserIDUsingDeploymentKey(context.Context, string) (uuid.UUID, uuid.UUID, error)
36+
FetchOrgUserIDUsingDeploymentKey(context.Context, string) (uuid.UUID, uuid.UUID, uuid.UUID, error)
3637
}
3738

3839
// VizierProvisioner provisions a new Vizier.
@@ -60,7 +61,7 @@ func (s *Service) RegisterVizierDeployment(ctx context.Context, req *vzmgrpb.Reg
6061
return nil, status.Error(codes.InvalidArgument, "empty cluster UID is not allowed")
6162
}
6263
// Fetch the orgID and userID based on the deployment key.
63-
orgID, userID, err := s.deploymentInfoFetcher.FetchOrgUserIDUsingDeploymentKey(ctx, req.DeploymentKey)
64+
orgID, userID, keyID, err := s.deploymentInfoFetcher.FetchOrgUserIDUsingDeploymentKey(ctx, req.DeploymentKey)
6465
if err != nil {
6566
return nil, status.Error(codes.Unauthenticated, "invalid/unknown deployment key")
6667
}
@@ -73,6 +74,9 @@ func (s *Service) RegisterVizierDeployment(ctx context.Context, req *vzmgrpb.Reg
7374
if err != nil {
7475
return nil, vzerrors.ToGRPCError(err)
7576
}
77+
78+
log.WithField("orgID", orgID).WithField("keyID", keyID).WithField("clusterID", clusterID).WithField("clusterName", clusterName).Info("Successfully registered Vizier deployment")
79+
7680
return &vzmgrpb.RegisterVizierDeploymentResponse{
7781
VizierID: utils.ProtoFromUUID(clusterID),
7882
VizierName: clusterName,

src/cloud/vzmgr/deployment/deployment_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
var (
3939
testOrgID = uuid.FromStringOrNil("223e4567-e89b-12d3-a456-426655440000")
4040
testUserID = uuid.FromStringOrNil("423e4567-e89b-12d3-a456-426655440000")
41+
testKeyID = uuid.FromStringOrNil("323e4567-e89b-12d3-a456-426655440000")
4142

4243
testValidClusterID = uuid.FromStringOrNil("553e4567-e89b-12d3-a456-426655440000")
4344

@@ -46,11 +47,11 @@ var (
4647

4748
type fakeDF struct{}
4849

49-
func (f *fakeDF) FetchOrgUserIDUsingDeploymentKey(ctx context.Context, key string) (uuid.UUID, uuid.UUID, error) {
50+
func (f *fakeDF) FetchOrgUserIDUsingDeploymentKey(ctx context.Context, key string) (uuid.UUID, uuid.UUID, uuid.UUID, error) {
5051
if key == testValidDeploymentKey {
51-
return testOrgID, testUserID, nil
52+
return testOrgID, testUserID, testKeyID, nil
5253
}
53-
return uuid.Nil, uuid.Nil, vzerrors.ErrDeploymentKeyNotFound
54+
return uuid.Nil, uuid.Nil, uuid.Nil, vzerrors.ErrDeploymentKeyNotFound
5455
}
5556

5657
type fakeProvisioner struct {

src/cloud/vzmgr/deploymentkey/deployment_keys.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,24 @@ func (s *Service) Delete(ctx context.Context, req *vzmgrpb.DeleteDeploymentKeyRe
209209
}
210210

211211
// FetchOrgUserIDUsingDeploymentKey gets the org and user ID based on the deployment key.
212-
func (s *Service) FetchOrgUserIDUsingDeploymentKey(ctx context.Context, key string) (uuid.UUID, uuid.UUID, error) {
212+
func (s *Service) FetchOrgUserIDUsingDeploymentKey(ctx context.Context, key string) (uuid.UUID, uuid.UUID, uuid.UUID, error) {
213213
resp, err := s.fetchDeploymentKeyUsingKeyFromDB(ctx, key)
214214
if err != nil {
215-
return uuid.Nil, uuid.Nil, err
215+
return uuid.Nil, uuid.Nil, uuid.Nil, err
216216
}
217217
oid, err := utils.UUIDFromProto(resp.OrgID)
218218
if err != nil {
219-
return uuid.Nil, uuid.Nil, err
219+
return uuid.Nil, uuid.Nil, uuid.Nil, err
220220
}
221221
uid, err := utils.UUIDFromProto(resp.UserID)
222222
if err != nil {
223-
return uuid.Nil, uuid.Nil, err
223+
return uuid.Nil, uuid.Nil, uuid.Nil, err
224224
}
225-
return oid, uid, nil
225+
keyID, err := utils.UUIDFromProto(resp.ID)
226+
if err != nil {
227+
return uuid.Nil, uuid.Nil, uuid.Nil, err
228+
}
229+
return oid, uid, keyID, nil
226230
}
227231

228232
// LookupDeploymentKey gets the complete Deployment key information using just the Key.

src/cloud/vzmgr/deploymentkey/deployment_keys_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,11 @@ func TestService_FetchOrgUserIDUsingDeploymentKey(t *testing.T) {
454454
ctx := test.ctx
455455
svc := New(db, testDBKey)
456456

457-
orgID, userID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "px-dep-key1")
457+
orgID, userID, keyID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "px-dep-key1")
458458
require.NoError(t, err)
459459
assert.Equal(t, testAuthOrgID, orgID)
460460
assert.Equal(t, testAuthUserID, userID)
461+
assert.Equal(t, testKey1ID, keyID)
461462
})
462463
}
463464
}
@@ -484,10 +485,11 @@ func TestService_FetchOrgUserIDUsingDeploymentKey_OldKeys(t *testing.T) {
484485
ctx := test.ctx
485486
svc := New(db, testDBKey)
486487

487-
orgID, userID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "key1")
488+
orgID, userID, keyID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "key1")
488489
require.NoError(t, err)
489490
assert.Equal(t, testAuthOrgID, orgID)
490491
assert.Equal(t, testAuthUserID, userID)
492+
assert.Equal(t, testKey1ID, keyID)
491493
})
492494
}
493495
}
@@ -513,11 +515,12 @@ func TestService_FetchOrgUserIDUsingDeploymentKey_BadKey(t *testing.T) {
513515
ctx := test.ctx
514516
svc := New(db, testDBKey)
515517

516-
orgID, userID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "some rando key that does not exist")
518+
orgID, userID, keyID, err := svc.FetchOrgUserIDUsingDeploymentKey(ctx, "some rando key that does not exist")
517519
assert.NotNil(t, err)
518520
assert.Equal(t, vzerrors.ErrDeploymentKeyNotFound, err)
519521
assert.Equal(t, uuid.Nil, orgID)
520522
assert.Equal(t, uuid.Nil, userID)
523+
assert.Equal(t, uuid.Nil, keyID)
521524
})
522525
}
523526
}

0 commit comments

Comments
 (0)