Update agent guidelines and improve documentation structure. Refactor AGENTS.md to streamline commands and code style guidelines, enhancing clarity and usability. Update README.md with refined NATS consumer configuration details and observability metrics. Modify .gitignore to exclude dynamically generated Prometheus target files. Enhance configuration files for development and production environments, ensuring consistency and clarity in settings.

This commit is contained in:
windyboy
2025-11-19 13:07:09 +08:00
parent 06fc9cb9e0
commit c687fdcde8
39 changed files with 1112 additions and 3193 deletions
+10 -31
View File
@@ -2,10 +2,9 @@ package nats
import (
"context"
"time"
"github.com/nats-io/nats.go"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zaptest"
)
@@ -19,40 +18,20 @@ var _ = Describe("Metrics", func() {
ctx = context.Background()
c = &Consumer{
config: consumerConfig{
streamName: "TEST_STREAM",
consumerName: "test-consumer",
streamName: "TEST_STREAM",
consumerName: "test-consumer",
monitorInterval: 30 * time.Second, // Set a valid interval
},
logger: zaptest.NewLogger(GinkgoT()),
}
})
Describe("initMetrics", func() {
It("initializes metrics without error", func() {
c.initMetrics()
Expect(c.meter).NotTo(BeNil())
})
})
Describe("recordConsumerMetrics", func() {
It("handles nil ConsumerInfo gracefully", func() {
c.initMetrics()
c.recordConsumerMetrics(ctx, nil)
// Should not panic
})
It("records metrics when ConsumerInfo is provided", func() {
c.initMetrics()
info := &nats.ConsumerInfo{
Config: nats.ConsumerConfig{},
Delivered: nats.SequenceInfo{
Consumer: 50,
Stream: 100,
},
}
// Set fields directly (they are exported)
// Note: ConsumerInfo fields may not all be exported, so we test what we can
c.recordConsumerMetrics(ctx, info)
// Should not panic
Describe("emitConsumerStats", func() {
It("handles context cancellation", func() {
ctx, cancel := context.WithCancel(ctx)
cancel()
c.emitConsumerStats(ctx)
// Should return without panic
})
})
})