Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
EFGS: Metrics
Browse files Browse the repository at this point in the history
Preparing total/yesterday's amount of uploaded, downloaded keys and
publisher for download from metrics API.
  • Loading branch information
Matěj Jehlička authored and dizider committed Mar 30, 2021
1 parent f821179 commit de98c2a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
22 changes: 14 additions & 8 deletions internal/firebase/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ type StringValue struct {

//MetricsData Data of metrics.
type MetricsData struct {
Modified int64 `json:"modified"`
Date string `json:"date"`
ActivationsYesterday int32 `json:"activations_yesterday"`
ActivationsTotal int32 `json:"activations_total"`
KeyPublishersYesterday int32 `json:"key_publishers_yesterday"`
KeyPublishersTotal int32 `json:"key_publishers_total"`
NotificationsYesterday int32 `json:"notifications_yesterday"`
NotificationsTotal int32 `json:"notifications_total"`
Modified int64 `json:"modified"`
Date string `json:"date"`
ActivationsYesterday int32 `json:"activations_yesterday"`
ActivationsTotal int32 `json:"activations_total"`
KeyPublishersYesterday int32 `json:"key_publishers_yesterday"`
KeyPublishersTotal int32 `json:"key_publishers_total"`
NotificationsYesterday int32 `json:"notifications_yesterday"`
NotificationsTotal int32 `json:"notifications_total"`
EfgsKeysUploadedTotal int32 `json:"efgs_keys_uploaded_total"`
EfgsKeysUploadedYesterday int32 `json:"efgs_keys_uploaded_yesterday"`
EfgsKeysDownloadedTotal int32 `json:"efgs_keys_downloaded_total"`
EfgsKeysDownloadedYesterday int32 `json:"efgs_keys_downloaded_yesterday"`
EfgsPublishersTotal int32 `json:"efgs_publishers_total"`
EfgsPublishersYesterday int32 `json:"efgs_publishers_yesterday"`
}
45 changes: 37 additions & 8 deletions internal/functions/metricsapi/prepare-new-version.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,28 @@ func prepareNewVersion(ctx context.Context, config *config) error {
return fmt.Errorf("Error while fetching data: %v", err)
}

yestEfgs, err := getEfgsCounter(ctx, config, yesterday.Format("20060102"))
if err != nil {
return fmt.Errorf("Error while fetching data: %v", err)
}

var today = config.now.Format("20060102")

data := structs.MetricsData{
Modified: config.now.Unix(),
Date: today,
ActivationsYesterday: yestActivations,
ActivationsTotal: yestData.ActivationsTotal + yestActivations,
KeyPublishersYesterday: yestPublishers,
KeyPublishersTotal: yestData.KeyPublishersTotal + yestPublishers,
NotificationsYesterday: yestNotifications,
NotificationsTotal: yestData.NotificationsTotal + yestNotifications,
Modified: config.now.Unix(),
Date: today,
ActivationsYesterday: yestActivations,
ActivationsTotal: yestData.ActivationsTotal + yestActivations,
KeyPublishersYesterday: yestPublishers,
KeyPublishersTotal: yestData.KeyPublishersTotal + yestPublishers,
NotificationsYesterday: yestNotifications,
NotificationsTotal: yestData.NotificationsTotal + yestNotifications,
EfgsKeysDownloadedYesterday: int32(yestEfgs.KeysDownloaded),
EfgsKeysDownloadedTotal: yestData.EfgsKeysDownloadedTotal + int32(yestEfgs.KeysDownloaded),
EfgsKeysUploadedYesterday: int32(yestEfgs.KeysUploaded),
EfgsKeysUploadedTotal: yestData.EfgsKeysUploadedTotal + int32(yestEfgs.KeysUploaded),
EfgsPublishersYesterday: int32(yestEfgs.Publishers),
EfgsPublishersTotal: yestData.EfgsPublishersTotal + int32(yestEfgs.Publishers),
}

logger.Debugf("Collected data: %+v", data)
Expand Down Expand Up @@ -169,3 +180,21 @@ func getPublishersCount(ctx context.Context, config *config, key string) (int32,

return int32(data.PublishersCount), nil
}

func getEfgsCounter(ctx context.Context, config *config, key string) (*structs.EfgsCounter, error) {
logger := logging.FromContext(ctx)

logger.Debugf("Getting EFGS publishers with key %v", key)

var data structs.EfgsCounter

if err := config.realtimedbClient.NewRef(constants.DbEfgsCountersPrefix+key).Get(ctx, &data); err != nil {
if status.Code(err) != codes.NotFound {
return nil, fmt.Errorf("Error while querying Firestore: %v", err)
}

logger.Debug("EFGS counter for '%v' was not found, using default value", key)
}

return &data, nil
}

0 comments on commit de98c2a

Please sign in to comment.