Skip to content

Commit acf9702

Browse files
committed
feat: add metric logger
1 parent 82b629d commit acf9702

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+495
-133
lines changed

api/init.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ func initCoreComponents() error {
135135
return nil
136136
}
137137

138+
if err := llmtokenratelimit.InitMetricLogger(&llmtokenratelimit.MetricLoggerConfig{
139+
AppName: config.AppName(),
140+
LogDir: config.LogBaseDir(),
141+
MaxFileSize: config.MetricLogSingleFileMaxSize(),
142+
MaxFileAmount: config.MetricLogMaxFileAmount(),
143+
FlushInterval: config.MetricLogFlushIntervalSec(),
144+
UsePid: config.LogUsePid(),
145+
}); err != nil {
146+
return err
147+
}
148+
138149
if err := llmtokenratelimit.Init(config.LLMTokenRateLimit()); err != nil {
139150
return err
140151
}

core/llm_token_ratelimit/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"errors"

core/llm_token_ratelimit/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"testing"

core/llm_token_ratelimit/constant.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
// ================================= Config ====================================
1818
const (
@@ -89,3 +89,12 @@ const (
8989
const (
9090
TokenEncoderKeyFormat string = "{shard-%s}:token-encoder:%s:%s:%s" // hashTag, provider, model, redisRatelimitKey
9191
)
92+
93+
// ================================= MetricLogger =============================
94+
const (
95+
MetricFileNameSuffix = "llm-token-ratelimit-metrics.log"
96+
DefaultMaxFileSize = 50 * 1024 * 1024
97+
DefaultMaxFileAmount = 7
98+
DefaultBufferSize = 1000
99+
DefaultFlushInterval = 1 // second
100+
)

core/llm_token_ratelimit/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"sync"

core/llm_token_ratelimit/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"fmt"

core/llm_token_ratelimit/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
// limitations under the License.
1414

1515
// Package config provides llm token rate limit mechanism.
16-
package llmtokenratelimit
16+
package llm_token_ratelimit

core/llm_token_ratelimit/identifier_check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package llmtokenratelimit
14+
package llm_token_ratelimit
1515

1616
import (
1717
"fmt"

core/llm_token_ratelimit/identifier_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"github.com/alibaba/sentinel-golang/util"

core/llm_token_ratelimit/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package llmtokenratelimit
15+
package llm_token_ratelimit
1616

1717
import (
1818
"fmt"

0 commit comments

Comments
 (0)