Skip to content

Commit 8394632

Browse files
author
MUzairS15
committed
fix init and close of logs stream
Signed-off-by: MUzairS15 <[email protected]>
1 parent a8e2fb7 commit 8394632

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/layer5io/meshery-operator v0.7.0
1616
github.com/layer5io/meshkit v0.7.9
1717
github.com/myntra/pipeline v0.0.0-20180618182531-2babf4864ce8
18+
github.com/sirupsen/logrus v1.9.3
1819
github.com/spf13/viper v1.18.2
1920
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
2021
golang.org/x/net v0.19.0
@@ -134,7 +135,6 @@ require (
134135
github.com/sagikazarmark/locafero v0.4.0 // indirect
135136
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
136137
github.com/shopspring/decimal v1.3.1 // indirect
137-
github.com/sirupsen/logrus v1.9.3 // indirect
138138
github.com/sourcegraph/conc v0.3.0 // indirect
139139
github.com/spf13/afero v1.11.0 // indirect
140140
github.com/spf13/cast v1.6.0 // indirect

internal/config/crd_config.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"errors"
6+
"fmt"
67

78
"github.com/layer5io/meshery-operator/pkg/client"
89
"github.com/layer5io/meshkit/utils"
@@ -168,7 +169,7 @@ func PopulateConfigs(configMap corev1.ConfigMap) (*MeshsyncConfig, error) {
168169
func PatchCRVersion(config *rest.Config) error {
169170
meshsyncClient, err := client.New(config)
170171
if err != nil {
171-
return err
172+
return ErrInitConfig(fmt.Errorf("unable to update MeshSync configuration"))
172173
}
173174

174175
patchedResource := map[string]interface{}{
@@ -178,11 +179,11 @@ func PatchCRVersion(config *rest.Config) error {
178179
}
179180
byt, err := utils.Marshal(patchedResource)
180181
if err != nil {
181-
return err
182+
return ErrInitConfig(fmt.Errorf("unable to update MeshSync configuration"))
182183
}
183184
_, err = meshsyncClient.CoreV1Alpha1().MeshSyncs("meshery").Patch(context.TODO(), crName, types.MergePatchType, []byte(byt), metav1.PatchOptions{})
184185
if err != nil {
185-
return err
186+
return ErrInitConfig(fmt.Errorf("unable to update MeshSync configuration"))
186187
}
187188
return nil
188189
}

main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/layer5io/meshsync/internal/channels"
1717
"github.com/layer5io/meshsync/internal/config"
1818
"github.com/layer5io/meshsync/meshsync"
19+
"github.com/sirupsen/logrus"
1920
"github.com/spf13/viper"
2021
)
2122

@@ -33,7 +34,8 @@ func main() {
3334

3435
// Initialize Logger instance
3536
log, err := logger.New(serviceName, logger.Options{
36-
Format: logger.SyslogLogFormat,
37+
Format: logger.SyslogLogFormat,
38+
LogLevel: int(logrus.InfoLevel),
3739
})
3840
if err != nil {
3941
fmt.Println(err)

meshsync/logstream.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ func (h *Handler) streamLogs(id string, req model.LogRequest, cfg config.Listene
6262
return
6363
}
6464

65-
defer resp.Close()
65+
go func() {
66+
<-h.channelPool[id].(channels.StructChannel)
67+
h.Log.Info("Closing", id)
68+
delete(h.channelPool, id)
69+
resp.Close()
70+
}()
6671

6772
for {
6873
buf := make([]byte, 2000)
6974
numBytes, err := resp.Read(buf)
70-
if numBytes == 0 {
71-
continue
72-
}
7375
if err == io.EOF {
7476
break
7577
}
78+
if numBytes == 0 {
79+
continue
80+
}
7681
if err != nil {
7782
h.Log.Error(ErrCopyBuffer(err))
7883
delete(h.channelPool, id)
@@ -94,7 +99,4 @@ func (h *Handler) streamLogs(id string, req model.LogRequest, cfg config.Listene
9499
}
95100
}
96101

97-
<-h.channelPool[id].(channels.StructChannel)
98-
h.Log.Info("Closing", id)
99-
delete(h.channelPool, id)
100102
}

0 commit comments

Comments
 (0)