Skip to content

Commit c42ac14

Browse files
authored
fix(usage): add missing error filtering for users/admin (#257)
Because - The `TriggerSingleReporter` method was missing the same error filtering logic that exists in `NewUsage` and `StartReporter` methods - When `GetUserAdmin` fails with "users/admin" error, it should be treated as a debug message rather than an error since only Instill Core CE has the default "admin" user - Without this filtering, false alarm errors were being logged when the admin user doesn't exist in other Instill editions This commit - Adds the same error filtering pattern to `TriggerSingleReporter` that already exists in `NewUsage` and `StartReporter` - Changes the error handling to check if the error contains "users/admin" and treats it as a debug log instead of an error log - Ensures consistent error handling across all three methods when dealing with the default admin user lookup - Prevents false alarm error logs in Instill editions that don't have the default admin user
1 parent 302d93f commit c42ac14

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pkg/usage/usage.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package usage
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

9+
"github.com/gofrs/uuid"
810
"github.com/redis/go-redis/v9"
911
"go.uber.org/zap"
1012

@@ -40,11 +42,15 @@ func NewUsage(ctx context.Context, mu mgmtpb.MgmtPrivateServiceClient, rc *redis
4042
logger, _ := logx.GetZapLogger(ctx)
4143

4244
var defaultOwnerUID string
43-
if resp, err := mu.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
44-
defaultOwnerUID = resp.GetUser().GetUid()
45+
if user, err := mu.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
46+
defaultOwnerUID = user.GetUser().GetUid()
47+
} else if strings.Contains(err.Error(), "users/admin") {
48+
// Only Instill Core CE has the default user "admin"
49+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
50+
defaultOwnerUID = uuid.Nil.String()
4551
} else {
46-
logger.Error("Failed to get default user, usage reporter will not start", zap.Error(err))
47-
return nil // Return nil instead of continuing with empty defaultOwnerUID
52+
logger.Error(err.Error())
53+
return nil
4854
}
4955

5056
artifactReporter, err := usageclient.InitReporter(ctx, usc, usagepb.Session_SERVICE_ARTIFACT, config.Config.Server.Edition, serviceVersion, defaultOwnerUID)
@@ -144,6 +150,10 @@ func (u *usage) StartReporter(ctx context.Context) {
144150
var defaultOwnerUID string
145151
if resp, err := u.mgmtPrivateServiceClient.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
146152
defaultOwnerUID = resp.GetUser().GetUid()
153+
} else if strings.Contains(err.Error(), "users/admin") {
154+
// Only Instill Core CE has the default user "admin"
155+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
156+
defaultOwnerUID = uuid.Nil.String()
147157
} else {
148158
logger.Error(err.Error())
149159
return
@@ -169,6 +179,10 @@ func (u *usage) TriggerSingleReporter(ctx context.Context) {
169179
var defaultOwnerUID string
170180
if resp, err := u.mgmtPrivateServiceClient.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
171181
defaultOwnerUID = resp.GetUser().GetUid()
182+
} else if strings.Contains(err.Error(), "users/admin") {
183+
// Only Instill Core CE has the default user "admin"
184+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
185+
defaultOwnerUID = uuid.Nil.String()
172186
} else {
173187
logger.Error(err.Error())
174188
return

0 commit comments

Comments
 (0)