Skip to content

Commit c6b9f1d

Browse files
fixing resource cache key (#122)
1 parent 922fdc6 commit c6b9f1d

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.4-cap-CR-13068-fix-app-deletion
1+
2.3.4-cap-CR-12256-fix-res-cache-key

server/application/application_event_reporter.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func NewApplicationEventReporter(server *Server) *applicationEventReporter {
3434
}
3535

3636
func (s *applicationEventReporter) shouldSendResourceEvent(a *appv1.Application, rs appv1.ResourceStatus) bool {
37-
logCtx := log.WithFields(log.Fields{
37+
logCtx := logWithResourceStatus(log.WithFields(log.Fields{
3838
"app": a.Name,
3939
"gvk": fmt.Sprintf("%s/%s/%s", rs.Group, rs.Version, rs.Kind),
4040
"resource": fmt.Sprintf("%s/%s", rs.Namespace, rs.Name),
41-
})
41+
}), rs)
4242

4343
cachedRes, err := s.server.cache.GetLastResourceEvent(a, rs, getApplicationLatestRevision(a))
4444
if err != nil {
@@ -105,7 +105,7 @@ func (s *applicationEventReporter) streamApplicationEvents(
105105
ts string,
106106
) error {
107107
var (
108-
logCtx = log.WithField("application", a.Name)
108+
logCtx = log.WithField("app", a.Name)
109109
)
110110

111111
logCtx.Info("streaming application events")
@@ -225,11 +225,11 @@ func (s *applicationEventReporter) processResource(
225225
if isApp(rs) && actualState.Manifest != "" && json.Unmarshal([]byte(actualState.Manifest), &appRes) == nil {
226226
logWithAppStatus(&appRes, logCtx, ts).Info("streaming resource event")
227227
} else {
228-
logCtx.Info("streaming resource event")
228+
logWithResourceStatus(logCtx, rs).Info("streaming resource event")
229229
}
230230

231231
if err := stream.Send(ev); err != nil {
232-
logCtx.WithError(err).Error("failed to send even")
232+
logCtx.WithError(err).Error("failed to send event")
233233
return
234234
}
235235

@@ -239,7 +239,7 @@ func (s *applicationEventReporter) processResource(
239239
}
240240

241241
func (s *applicationEventReporter) shouldSendApplicationEvent(ae *appv1.ApplicationWatchEvent) bool {
242-
logCtx := log.WithField("application", ae.Application.Name)
242+
logCtx := log.WithField("app", ae.Application.Name)
243243

244244
if ae.Type == watch.Deleted {
245245
logCtx.Info("application deleted")
@@ -284,10 +284,21 @@ func isApp(rs appv1.ResourceStatus) bool {
284284

285285
func logWithAppStatus(a *appv1.Application, logCtx *log.Entry, ts string) *log.Entry {
286286
return logCtx.WithFields(log.Fields{
287-
"status": a.Status.Sync.Status,
287+
"sync": a.Status.Sync.Status,
288+
"health": a.Status.Health.Status,
288289
"resourceVersion": a.ResourceVersion,
289290
"ts": ts,
290291
})
292+
293+
}
294+
295+
func logWithResourceStatus(logCtx *log.Entry, rs appv1.ResourceStatus) *log.Entry {
296+
logCtx = logCtx.WithField("sync", rs.Status)
297+
if rs.Health != nil {
298+
logCtx = logCtx.WithField("health", rs.Health.Status)
299+
}
300+
301+
return logCtx
291302
}
292303

293304
func getLatestAppHistoryItem(a *appv1.Application) *appv1.RevisionHistory {

server/cache/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func lastApplicationEventKey(a *appv1.Application) string {
9393
}
9494

9595
func lastResourceEventKey(a *appv1.Application, rs appv1.ResourceStatus, revision string) string {
96-
return fmt.Sprintf("app|%s/%s|%s|%s|res|%s/%s/%s/%s/%s|last-sent-event",
97-
a.Namespace, a.Name, revision, a.Status.Sync.Status, rs.Group, rs.Version, rs.Kind, rs.Name, rs.Namespace)
96+
return fmt.Sprintf("app|%s/%s|%s|res|%s/%s/%s/%s/%s|last-sent-event",
97+
a.Namespace, a.Name, revision, rs.Group, rs.Version, rs.Kind, rs.Name, rs.Namespace)
9898
}
9999

100100
func repoConnectionStateKey(repo string) string {

0 commit comments

Comments
 (0)