Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
feat(metrics): add errCode metrics to MeshConfig
Browse files Browse the repository at this point in the history
Adds error code metrics for MeshConfig

Signed-off-by: Shalier Xia <[email protected]>
Signed-off-by: jaellio <[email protected]>
  • Loading branch information
shalier authored and jaellio committed Aug 10, 2021
1 parent 025002e commit 1379930
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/configurator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func (c *Client) run(stop <-chan struct{}) {
log.Debug().Msgf("Started OSM MeshConfig informer")
log.Debug().Msg("[MeshConfig Client] Waiting for MeshConfig informer's cache to sync")
if !cache.WaitForCacheSync(stop, c.informer.HasSynced) {
log.Error().Str(errcode.Kind, errcode.ErrMeshConfigInformerInitCache.String()).Msg("Failed initial cache sync for MeshConfig informer")
// TODO: Need to push metric
log.Error().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigInformerInitCache)).Msg("Failed initial cache sync for MeshConfig informer")
return
}

Expand Down Expand Up @@ -133,7 +134,7 @@ func meshConfigUpdatedMessageHandler(psubMsg *events.PubSubMessage) {
prevMeshConfig, okPrevCast := psubMsg.OldObj.(*v1alpha1.MeshConfig)
newMeshConfig, okNewCast := psubMsg.NewObj.(*v1alpha1.MeshConfig)
if !okPrevCast || !okNewCast {
log.Error().Str(errcode.Kind, errcode.ErrMeshConfigStructCasting.String()).Msgf("[%s] Error casting old/new MeshConfigs objects (%v %v)",
log.Error().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigStructCasting)).Msgf("[%s] Error casting old/new MeshConfigs objects (%v %v)",
psubMsg.AnnouncementType, okPrevCast, okNewCast)
return
}
Expand Down Expand Up @@ -191,7 +192,7 @@ func (c *Client) getMeshConfig() *v1alpha1.MeshConfig {
meshConfigCacheKey := c.getMeshConfigCacheKey()
item, exists, err := c.cache.GetByKey(meshConfigCacheKey)
if err != nil {
log.Error().Err(err).Str(errcode.Kind, errcode.ErrMeshConfigFetchFromCache.String()).Msgf("Error getting MeshConfig from cache with key %s", meshConfigCacheKey)
log.Error().Err(err).Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigFetchFromCache)).Msgf("Error getting MeshConfig from cache with key %s", meshConfigCacheKey)
return &v1alpha1.MeshConfig{}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/configurator/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func marshalConfigToJSON(config *configv1alpha1.MeshConfigSpec) (string, error)
func (c *Client) GetMeshConfigJSON() (string, error) {
cm, err := marshalConfigToJSON(&c.getMeshConfig().Spec)
if err != nil {
log.Error().Err(err).Str(errcode.Kind, errcode.ErrMeshConfigMarshaling.String()).Msgf("Error marshaling MeshConfig %s: %+v", c.getMeshConfigCacheKey(), c.getMeshConfig())
log.Error().Err(err).Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigMarshaling)).Msgf("Error marshaling MeshConfig %s: %+v", c.getMeshConfigCacheKey(), c.getMeshConfig())
return "", err
}
return cm, nil
Expand Down

0 comments on commit 1379930

Please sign in to comment.