Skip to content

Commit cd1bd55

Browse files
authored
fix(usage): add missing error filtering for users/admin (#1119)
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 b51c8f4 commit cd1bd55

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pkg/usage/usage.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strings"
78
"time"
89

10+
"github.com/gofrs/uuid"
911
"github.com/redis/go-redis/v9"
1012
"google.golang.org/protobuf/types/known/timestamppb"
1113

@@ -41,10 +43,15 @@ func NewUsage(ctx context.Context, r repository.Repository, m mgmtpb.MgmtPrivate
4143
logger, _ := logx.GetZapLogger(ctx)
4244

4345
var defaultOwnerUID string
44-
if resp, err := m.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
45-
defaultOwnerUID = resp.GetUser().GetUid()
46+
if user, err := m.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
47+
defaultOwnerUID = user.GetUser().GetUid()
48+
} else if strings.Contains(err.Error(), "users/admin") {
49+
// Only Instill Core CE has the default user "admin"
50+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
51+
defaultOwnerUID = uuid.Nil.String()
4652
} else {
4753
logger.Error(err.Error())
54+
return nil
4855
}
4956

5057
reporter, err := usageclient.InitReporter(ctx, usc, usagepb.Session_SERVICE_PIPELINE, config.Config.Server.Edition, serviceVersion, defaultOwnerUID)
@@ -219,6 +226,10 @@ func (u *usage) StartReporter(ctx context.Context) {
219226
var defaultOwnerUID string
220227
if resp, err := u.mgmtPrivateServiceClient.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
221228
defaultOwnerUID = resp.GetUser().GetUid()
229+
} else if strings.Contains(err.Error(), "users/admin") {
230+
// Only Instill Core CE has the default user "admin"
231+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
232+
defaultOwnerUID = uuid.Nil.String()
222233
} else {
223234
logger.Error(err.Error())
224235
return
@@ -243,6 +254,10 @@ func (u *usage) TriggerSingleReporter(ctx context.Context) {
243254
var defaultOwnerUID string
244255
if resp, err := u.mgmtPrivateServiceClient.GetUserAdmin(ctx, &mgmtpb.GetUserAdminRequest{UserId: constant.DefaultUserID}); err == nil {
245256
defaultOwnerUID = resp.GetUser().GetUid()
257+
} else if strings.Contains(err.Error(), "users/admin") {
258+
// Only Instill Core CE has the default user "admin"
259+
logger.Debug(fmt.Sprintf("error getting default user: %v, use a zero uuid as default owner uid", err))
260+
defaultOwnerUID = uuid.Nil.String()
246261
} else {
247262
logger.Error(err.Error())
248263
return

0 commit comments

Comments
 (0)