Skip to content

Commit f9212a3

Browse files
Merge pull request #353 from gofr-dev/development
Release v1.0.2
2 parents 59228aa + f908e7a commit f9212a3

File tree

25 files changed

+623
-122
lines changed

25 files changed

+623
-122
lines changed

.github/workflows/go.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ on:
1616

1717
jobs:
1818
MIGRATION-Unit-Testing:
19-
name: Migration Unit Testing🛠
19+
name: Migration Unit Testing (v${{ matrix.go-version }})🛠
2020
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
go-version: ['1.21', '1.20']
2124

2225
steps:
2326
- name: Checkout code into go module directory
2427
uses: actions/checkout@v4
2528
with:
2629
fetch-depth: 0
2730

28-
- name: Set up Go 1.21
31+
- name: Set up Go ${{ matrix.go-version }}
2932
uses: actions/setup-go@v4
3033
with:
31-
go-version: 1.21
34+
go-version: ${{ matrix.go-version }}
3235
id: Go
3336

3437
- name: Get dependencies
@@ -43,14 +46,19 @@ jobs:
4346
go tool cover -func profile.cov
4447
4548
- name: Upload Test Coverage
49+
if: ${{ matrix.go-version == '1.21'}}
4650
uses: actions/upload-artifact@v3
4751
with:
4852
name: MIGRATION-Coverage-Report
4953
path: profile.cov
5054

5155
Example-Unit-Testing:
52-
name: Example Unit Testing🛠
56+
name: Example Unit Testing (v${{ matrix.go-version }})🛠
5357
runs-on: ubuntu-latest
58+
strategy:
59+
matrix:
60+
go-version: ['1.21', '1.20']
61+
5462
services:
5563
zookeeper:
5664
image: wurstmeister/zookeeper
@@ -90,10 +98,10 @@ jobs:
9098
with:
9199
fetch-depth: 0
92100

93-
- name: Set up Go 1.21
101+
- name: Set up Go ${{ matrix.go-version }}
94102
uses: actions/setup-go@v4
95103
with:
96-
go-version: 1.21
104+
go-version: ${{ matrix.go-version }}
97105
id: Go
98106

99107
- name: Get dependencies
@@ -116,25 +124,29 @@ jobs:
116124
go tool cover -func profile.cov
117125
118126
- name: Upload Test Coverage
127+
if: ${{ matrix.go-version == '1.21'}}
119128
uses: actions/upload-artifact@v3
120129
with:
121130
name: Example-Test-Report
122131
path: profile.cov
123132

124133
PKG-Unit-Testing:
125-
name: PKG Unit Testing🛠
134+
name: PKG Unit Testing (v${{ matrix.go-version }})🛠
126135
runs-on: ubuntu-latest
136+
strategy:
137+
matrix:
138+
go-version: ['1.21', '1.20']
127139

128140
steps:
129141
- name: Checkout code into go module directory
130142
uses: actions/checkout@v4
131143
with:
132144
fetch-depth: 0
133145

134-
- name: Set up Go 1.21
146+
- name: Set up Go ${{ matrix.go-version }}
135147
uses: actions/setup-go@v4
136148
with:
137-
go-version: 1.21
149+
go-version: ${{ matrix.go-version }}
138150
id: Go
139151

140152
- name: Get dependencies
@@ -149,6 +161,7 @@ jobs:
149161
go tool cover -func profile.cov
150162
151163
- name: Upload Test Coverage
164+
if: ${{ matrix.go-version == '1.21'}}
152165
uses: actions/upload-artifact@v3
153166
with:
154167
name: PKG-Coverage-Report
@@ -157,7 +170,7 @@ jobs:
157170
parse_coverage:
158171
name: Code Coverage
159172
runs-on: ubuntu-latest
160-
needs: [Example-Unit-Testing,PKG-Unit-Testing,MIGRATION-Unit-Testing]
173+
needs: [ Example-Unit-Testing,PKG-Unit-Testing,MIGRATION-Unit-Testing ]
161174
steps:
162175
- name: Check out code into the Go module directory
163176
uses: actions/checkout@v4
@@ -167,6 +180,7 @@ jobs:
167180
with:
168181
path: artifacts
169182

183+
170184
- name: Merge Coverage Files
171185
working-directory: artifacts
172186
run: |
@@ -191,7 +205,7 @@ jobs:
191205
name: Upload Coverage📊
192206
runs-on: ubuntu-latest
193207
needs: [Example-Unit-Testing,PKG-Unit-Testing,MIGRATION-Unit-Testing]
194-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
208+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development'}}
195209
steps:
196210
- name: Check out code into the Go module directory
197211
uses: actions/checkout@v4

docs/quick-start/introduction/page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prerequisite
22

3-
- Go 1.19 or above.
3+
- Go 1.20 or above.
44
To check the version use the following command `go version`.
55

66
- Prior familiarity with Golang syntax is essential. [Golang Tour](https://tour.golang.org/) is highly recommended as it has an excellent guided tour.

docs/quick-start/observability/page.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,27 @@ GoFr by default publishes metrics automatically to port: _2121_ on _/metrics_ en
7373
---
7474
* app_sql_stats
7575
* histogram
76-
* Observes the response time for SQL queries
76+
* Response time of SQL queries in microseconds
7777
---
7878
* app_redis_stats
7979
* histogram
80-
* Observes the response time for Redis commands
80+
* Response time of Redis commands in microseconds
81+
---
82+
* app_pubsub_publish_total_count
83+
* counter
84+
* Number of total publish operations
85+
---
86+
* app_pubsub_publish_success_count
87+
* counter
88+
* Number of successful publish operations
89+
---
90+
* app_pubsub_subscribe_total_count
91+
* counter
92+
* Number of total subscribe operations
93+
---
94+
* app_pubsub_subscribe_success_count
95+
* counter
96+
* Number of successful subscribe operations
8197

8298
{% /table %}
8399

pkg/gofr/container/container.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Container struct {
3030

3131
Services map[string]service.HTTP
3232
metricsManager metrics.Manager
33-
pubsub pubsub.Client
33+
PubSub pubsub.Client
3434

3535
Redis *redis.Redis
3636
SQL *sql.DB
@@ -82,18 +82,18 @@ func (c *Container) Create(conf config.Config) {
8282
partition, _ := strconv.Atoi(conf.GetOrDefault("PARTITION_SIZE", "0"))
8383
offSet, _ := strconv.Atoi(conf.GetOrDefault("PUBSUB_OFFSET", "-1"))
8484

85-
c.pubsub = kafka.New(kafka.Config{
85+
c.PubSub = kafka.New(kafka.Config{
8686
Broker: conf.Get("PUBSUB_BROKER"),
8787
Partition: partition,
8888
ConsumerGroupID: conf.Get("CONSUMER_ID"),
8989
OffSet: offSet,
90-
}, c.Logger)
90+
}, c.Logger, c.metricsManager)
9191
}
9292
case "GOOGLE":
93-
c.pubsub = google.New(google.Config{
93+
c.PubSub = google.New(google.Config{
9494
ProjectID: conf.Get("GOOGLE_PROJECT_ID"),
9595
SubscriptionName: conf.Get("GOOGLE_SUBSCRIPTION_NAME"),
96-
}, c.Logger)
96+
}, c.Logger, c.metricsManager)
9797
}
9898
}
9999

@@ -115,19 +115,26 @@ func (c *Container) registerFrameworkMetrics() {
115115
c.Metrics().NewGauge("app_go_numGC", "Number of completed Garbage Collector cycles.")
116116
c.Metrics().NewGauge("app_go_sys", "Number of total bytes of memory.")
117117

118-
histogramBuckets := []float64{.001, .003, .005, .01, .02, .03, .05, .1, .2, .3, .5, .75, 1, 2, 3, 5, 10, 30}
119-
120118
// http metrics
121-
c.Metrics().NewHistogram("app_http_response", "Response time of http requests in seconds.", histogramBuckets...)
122-
c.Metrics().NewHistogram("app_http_service_response", "Response time of http service requests in seconds.", histogramBuckets...)
119+
httpBuckets := []float64{.001, .003, .005, .01, .02, .03, .05, .1, .2, .3, .5, .75, 1, 2, 3, 5, 10, 30}
120+
c.Metrics().NewHistogram("app_http_response", "Response time of http requests in seconds.", httpBuckets...)
121+
c.Metrics().NewHistogram("app_http_service_response", "Response time of http service requests in seconds.", httpBuckets...)
123122

124123
// redis metrics
125-
c.Metrics().NewHistogram("app_redis_stats", "Observes the response time for Redis commands.", histogramBuckets...)
124+
redisBuckets := []float64{50, 75, 100, 125, 150, 200, 300, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000}
125+
c.Metrics().NewHistogram("app_redis_stats", "Response time of Redis commands in microseconds.", redisBuckets...)
126126

127127
// sql metrics
128-
c.Metrics().NewHistogram("app_sql_stats", "Observes the response time for SQL queries.", histogramBuckets...)
128+
sqlBuckets := []float64{50, 75, 100, 125, 150, 200, 300, 500, 750, 1000, 2000, 3000, 4000, 5000, 7500, 10000}
129+
c.Metrics().NewHistogram("app_sql_stats", "Response time of SQL queries in microseconds.", sqlBuckets...)
129130
c.Metrics().NewGauge("app_sql_open_connections", "Number of open SQL connections.")
130131
c.Metrics().NewGauge("app_sql_inUse_connections", "Number of inUse SQL connections.")
132+
133+
// pubsub metrics
134+
c.Metrics().NewCounter("app_pubsub_publish_total_count", "Number of total publish operations.")
135+
c.Metrics().NewCounter("app_pubsub_publish_success_count", "Number of successful publish operations.")
136+
c.Metrics().NewCounter("app_pubsub_subscribe_total_count", "Number of total subscribe operations.")
137+
c.Metrics().NewCounter("app_pubsub_subscribe_success_count", "Number of successful subscribe operations.")
131138
}
132139

133140
func (c *Container) GetAppName() string {
@@ -139,9 +146,9 @@ func (c *Container) GetAppVersion() string {
139146
}
140147

141148
func (c *Container) GetPublisher() pubsub.Publisher {
142-
return c.pubsub
149+
return c.PubSub
143150
}
144151

145152
func (c *Container) GetSubscriber() pubsub.Subscriber {
146-
return c.pubsub
153+
return c.PubSub
147154
}

pkg/gofr/container/container_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Test_newContainerPubSubIntializationFail(t *testing.T) {
5858
for _, tc := range testCases {
5959
c := NewContainer(testutil.NewMockConfig(tc.configs))
6060

61-
assert.Nil(t, c.pubsub)
61+
assert.Nil(t, c.PubSub)
6262
}
6363
}
6464

@@ -112,7 +112,7 @@ func TestContainer_GetAppVersion(t *testing.T) {
112112
func TestContainer_GetPublisher(t *testing.T) {
113113
publisher := &mockPubSub{}
114114

115-
c := &Container{pubsub: publisher}
115+
c := &Container{PubSub: publisher}
116116

117117
out := c.GetPublisher()
118118

@@ -122,7 +122,7 @@ func TestContainer_GetPublisher(t *testing.T) {
122122
func TestContainer_GetSubscriber(t *testing.T) {
123123
subscriber := &mockPubSub{}
124124

125-
c := &Container{pubsub: subscriber}
125+
c := &Container{PubSub: subscriber}
126126

127127
out := c.GetSubscriber()
128128

pkg/gofr/datasource/pubsub/google/google.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ type Config struct {
2323
type googleClient struct {
2424
Config
2525

26-
client *gcPubSub.Client
27-
logger pubsub.Logger
26+
client *gcPubSub.Client
27+
logger pubsub.Logger
28+
metrics Metrics
2829
}
2930

3031
//nolint:revive // We do not want anyone using the client without initialization steps.
31-
func New(conf Config, logger pubsub.Logger) *googleClient {
32+
func New(conf Config, logger pubsub.Logger, metrics Metrics) *googleClient {
3233
err := validateConfigs(&conf)
3334
if err != nil {
3435
logger.Errorf("google pubsub could not be configured, err : %v", err)
@@ -44,9 +45,10 @@ func New(conf Config, logger pubsub.Logger) *googleClient {
4445
}
4546

4647
return &googleClient{
47-
Config: conf,
48-
client: client,
49-
logger: logger,
48+
Config: conf,
49+
client: client,
50+
logger: logger,
51+
metrics: metrics,
5052
}
5153
}
5254

@@ -63,6 +65,8 @@ func validateConfigs(conf *Config) error {
6365
}
6466

6567
func (g *googleClient) Publish(ctx context.Context, topic string, message []byte) error {
68+
g.metrics.IncrementCounter(ctx, "app_pubsub_publish_total_count", "topic", topic)
69+
6670
t, err := g.getTopic(ctx, topic)
6771
if err != nil {
6872
return err
@@ -80,10 +84,14 @@ func (g *googleClient) Publish(ctx context.Context, topic string, message []byte
8084

8185
g.logger.Debugf("published google message %v on topic %v", string(message), topic)
8286

87+
g.metrics.IncrementCounter(ctx, "app_pubsub_publish_success_count", "topic", topic)
88+
8389
return nil
8490
}
8591

8692
func (g *googleClient) Subscribe(ctx context.Context, topic string) (*pubsub.Message, error) {
93+
g.metrics.IncrementCounter(ctx, "app_pubsub_subscribe_total_count", "topic", topic)
94+
8795
var m = pubsub.NewMessage(ctx)
8896

8997
t, err := g.getTopic(ctx, topic)
@@ -118,6 +126,8 @@ func (g *googleClient) Subscribe(ctx context.Context, topic string) (*pubsub.Mes
118126

119127
g.logger.Debugf("received google message %v on topic %v", string(m.Value), m.Topic)
120128

129+
g.metrics.IncrementCounter(ctx, "app_pubsub_subscribe_success_count", "topic", topic)
130+
121131
return m, nil
122132
}
123133

0 commit comments

Comments
 (0)