From d2303cc46b396c048d571490a8be5f103ca7efab Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Wed, 5 Aug 2026 18:31:44 +0800 Subject: [PATCH] Go: align with EE (#17882) Signed-off-by: Jin Hai --- internal/common/error_code.go | 1 + internal/service/admin_client.go | 50 ++++++++++++++++++++--------- internal/service/admin_client_ee.go | 20 ++++++++++++ internal/utility/fingerprint_ee.go | 20 ++++++++++++ 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 internal/service/admin_client_ee.go create mode 100644 internal/utility/fingerprint_ee.go diff --git a/internal/common/error_code.go b/internal/common/error_code.go index e3bd460755..9c7a8d60cf 100644 --- a/internal/common/error_code.go +++ b/internal/common/error_code.go @@ -43,6 +43,7 @@ const ( CodeLicenseTimeRollback ErrorCode = 324 CodeLicenseNotFound ErrorCode = 325 CodeLicenseUnexpectedError ErrorCode = 326 + CodeLicenseNotValidYet ErrorCode = 327 CodeBadRequest ErrorCode = 400 CodeUnauthorized ErrorCode = 401 CodeForbidden ErrorCode = 403 diff --git a/internal/service/admin_client.go b/internal/service/admin_client.go index c13208f403..149048dbb0 100644 --- a/internal/service/admin_client.go +++ b/internal/service/admin_client.go @@ -20,6 +20,7 @@ import ( "encoding/json" "errors" "fmt" + "net/http" "ragflow/internal/common" "ragflow/internal/server" "ragflow/internal/utility" @@ -28,6 +29,7 @@ import ( "go.uber.org/zap" ) +var licenseStatusCode common.ErrorCode var AdminServiceClient *AdminClient // AdminClient is responsible for sending heartbeat reports to the admin server @@ -41,10 +43,12 @@ type AdminClient struct { version string lastSuccess bool attemptCount int + clusterInfo *utility.ClusterInfo } // NewAdminClient creates a new heartbeat service instance func NewAdminClient(logger *zap.Logger, serverType common.ServerType, serverName, host string, port int) *AdminClient { + licenseStatusCode = common.CodeSuccess return &AdminClient{ logger: logger, serverType: serverType, @@ -76,6 +80,11 @@ func (h *AdminClient) InitHTTPClient() error { zap.Int("admin_port", adminConfig.HTTPPort), ) + err := h.InitHTTPClientEE() + if err != nil { + h.logger.Fatal(fmt.Sprintf("Fail to init enterprise service: %v", err)) + } + return nil } @@ -110,6 +119,8 @@ func (h *AdminClient) SendHeartbeat() error { Ext: nil, } + message.Ext = h.clusterInfo + jsonData, err := json.Marshal(message) if err != nil { h.logger.Error("Failed to marshal heartbeat message", zap.Error(err)) @@ -122,22 +133,31 @@ func (h *AdminClient) SendHeartbeat() error { } defer resp.Body.Close() - if resp.StatusCode != 200 { - // extract the Code and Message field of the response - var responseBody map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&responseBody) - if err != nil { - return err - } - code, ok := responseBody["code"].(float64) - if !ok { - return fmt.Errorf("unexpected heartbeat response (status %d): missing or non-numeric \"code\" field", resp.StatusCode) - } - responseCode := common.ErrorCode(code) - if responseCode != common.CodeLicenseValid { - return errors.New(responseCode.Message()) - } + // extract the Code and Message field of the response + var responseBody map[string]interface{} + err = json.NewDecoder(resp.Body).Decode(&responseBody) + if err != nil { + return err } + code, ok := responseBody["code"].(float64) + if !ok { + return fmt.Errorf("unexpected heartbeat response (status %d): missing or non-numeric \"code\" field", resp.StatusCode) + } + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("error HTTP status code: %d", resp.StatusCode) + } + + responseCode := common.ErrorCode(code) + if responseCode != common.CodeLicenseValid { + if responseCode != licenseStatusCode { + licenseStatusCode = responseCode + h.logger.Warn(fmt.Sprintf("Heartbeat response error: %s, code: %d", responseCode.Message(), responseCode)) + } + + return errors.New(responseCode.Message()) + } + licenseStatusCode = responseCode h.logger.Debug("Heartbeat sent successfully", zap.String("server_id", h.serverName), diff --git a/internal/service/admin_client_ee.go b/internal/service/admin_client_ee.go new file mode 100644 index 0000000000..d2683d9bd8 --- /dev/null +++ b/internal/service/admin_client_ee.go @@ -0,0 +1,20 @@ +// Copyright 2026 The InfiniFlow Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package service + +func (h *AdminClient) InitHTTPClientEE() error { + return nil +} diff --git a/internal/utility/fingerprint_ee.go b/internal/utility/fingerprint_ee.go new file mode 100644 index 0000000000..5c41b3124c --- /dev/null +++ b/internal/utility/fingerprint_ee.go @@ -0,0 +1,20 @@ +// +// Copyright 2026 The InfiniFlow Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package utility + +type ClusterInfo struct { +}