-
Notifications
You must be signed in to change notification settings - Fork 17
feat(metrics): add metrics collection mechanism #1071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
d2771f8
feat(metrics): add metrics collection mechanism
leo-marble a948c87
refactor(task_queue): integrate global queue configuration
leo-marble 66f5c83
refactor(metrics): rename NewCollectorV1 to NewCollectorsV1 and clean…
leo-marble cbe80a8
feat(metrics): enhance metrics collection with frequency support
leo-marble 8ba5830
refactor(metrics): rename MetricsPayload to MetricsCollection and enh…
leo-marble ebec6b2
fix(time_ranges): Edge case on monthly frequency when last day of 31 …
leo-marble ee95279
fix(metrics_collection): use UTC when using time.Date
leo-marble af150ea
fix(metrics_collection): use UTC when using time.Date
leo-marble b4b73f9
feat(metrics_collection): add api version and license collector
leo-marble 45258cd
refactor(metrics_collection): replace slices.ContainsFunc with assert…
leo-marble 497dcdf
feat(task_queue): implement queue whitelist for non-org metrics and u…
leo-marble 74fa39d
fix(time_ranges_test): Expect an error in case from > to
leo-marble 9c4f7b5
refactor(watermark): rename OffloadingWatermark to Watermark and upda…
leo-marble 69a4af0
feat(metrics_collection): add watermark to fetch data from watermark …
leo-marble 9880327
refacto(watermark): delete offloading watermark and change *json.RawM…
leo-marble 806262c
feat(metrics_collection): add configuration for metrics collection
leo-marble a6e59f0
feat(metrics_collection): implement metrics ingestion API and update …
leo-marble 266f61e
fix(metrics_ingestion): defer after sending metrics
leo-marble e675f15
fix(metrics_ingestion): handle body parsing error
leo-marble f33b4d5
refacto(worker): use for range map instead of slice
leo-marble 42c83de
refacto(metrics_collection_job): use NewEncoder instead of jsonMarsha…
leo-marble 7de85d4
refacto(metrics_ingestion): remove ingection checking, let storage to…
leo-marble af2cfae
refacto(metrics): refactor MetricData structure to use separate Numer…
leo-marble 3eac549
feat(metrics_collection): enhance metrics ingestion with deployment I…
leo-marble 70e526e
refacto(watermark_repository): simplify SaveWatermark logic by using …
leo-marble 26e9e9c
feat(bigquery): integrate BigQuery client for metrics ingestion and h…
leo-marble 9a45a96
feat(metrics_ingestion): implement SendMetrics function to send metri…
leo-marble 55bb29b
refactor(metrics_collection): simplify NullString and NullFloat64 han…
leo-marble 70e9c3d
fix(metrics_collection): update Collect method to include time range …
leo-marble bc53b9f
feat(metrics_collection): add DecisionCollector to count decisions pe…
leo-marble 4cfd7d0
feat(metrics_ingestion): add license validation if license key is giv…
leo-marble c773278
fix(metrics_ingestion): Do not retry if the request send 401 error
leo-marble a78267e
fix(metrics_collection): update getFromTime to collect metrics from t…
leo-marble 4945c82
feat(metrics_collection): add CaseCollector to count cases per organi…
leo-marble 85f2938
refactor(metrics_collection): remove MetricCollectionFrequency from M…
leo-marble e3a8377
chore(routes): reorder validate-license route for improved clarity
leo-marble 7e30563
refactor(metrics_ingestion): simplify success response by removing JS…
leo-marble 607e048
feat(gcp): add GCP project ID retrieval and integrate with metrics co…
leo-marble 1ed3639
refactor(repositories): streamline case and decision counting logic t…
leo-marble 8e4d1ef
refactor(metrics_collection): update utility functions for BigQuery c…
leo-marble 1ee2922
feat(bigquery): enhance BigQuery configuration with metrics dataset a…
leo-marble 317be38
rename(migration): Change the migration name to change the migration …
leo-marble b809a04
refactor(metrics_collection): from and to date are mandatory and stor…
leo-marble e2692e4
Update usecases/metrics_ingestion.go
leo-marble 5184729
refacto(metrics): metrics URL configuration
leo-marble 212fff5
fix(server): update BigQuery ProjectID retrieval to use GCP configura…
leo-marble d254812
refactor(metrics): remove BigQuery references and simplify app versio…
leo-marble d360e15
refactor(metrics): improve license validation handling and update HTT…
leo-marble 7a461f8
refactor(metrics_collection): centralize metric names
leo-marble 0a2afdb
refactor(bigquery): replace BigQueryClient with BigQueryInfra for imp…
leo-marble 67352d8
refactor(worker): streamline global queue management by introducing e…
leo-marble 177ad09
refactor(metrics_collection): rename NewCollectorsTestV1 to NewCollec…
leo-marble 128a6c2
feat(metrics_collection): add fallback duration configuration for met…
leo-marble b0bfd33
feat(metadata): introduce metadata management with database integrati…
leo-marble 708bb06
refactor(metrics): rename OrganizationID to OrgID in MetricDataDto an…
leo-marble dac1ebb
refactor(metrics): update error handling in metrics ingestion and str…
leo-marble db3a193
feat(metrics_collection): add Timeout method to MetricCollectionWorke…
leo-marble b8af99f
refactor(metrics): update telemetry configuration to use DISABLED_TEL…
leo-marble 9658147
refactor(bigquery): update MetricsDataset constant to use 'marble_met…
leo-marble f245195
refactor(license): simplify license verification logic by removing un…
leo-marble File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/checkmarble/marble-backend/dto" | ||
"github.com/checkmarble/marble-backend/usecases" | ||
"github.com/checkmarble/marble-backend/utils" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Handle metrics ingestion from the metrics collection worker. | ||
func handleMetricsIngestion(uc usecases.Usecases) func(c *gin.Context) { | ||
return func(c *gin.Context) { | ||
logger := utils.LoggerFromContext(c.Request.Context()) | ||
var metricsCollectionDto dto.MetricsCollectionDto | ||
if err := c.ShouldBindJSON(&metricsCollectionDto); err != nil { | ||
c.Status(http.StatusBadRequest) | ||
logger.WarnContext(c.Request.Context(), "Failed to bind metrics collection", "error", err.Error()) | ||
return | ||
} | ||
|
||
metricsCollection := dto.AdaptMetricsCollection(metricsCollectionDto) | ||
|
||
usecase := uc.NewMetricsIngestionUsecase() | ||
err := usecase.IngestMetrics(c.Request.Context(), metricsCollection) | ||
if presentError(c.Request.Context(), c, err) { | ||
return | ||
} | ||
|
||
// Success response | ||
c.Status(http.StatusOK) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package dto | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/checkmarble/marble-backend/models" | ||
"github.com/checkmarble/marble-backend/pure_utils" | ||
"github.com/google/uuid" | ||
) | ||
|
||
// Be careful when changing this struct, it is used as input and output in the API. | ||
type MetricDataDto struct { | ||
Name string `json:"name" binding:"required"` | ||
Numeric *float64 `json:"numeric,omitempty"` | ||
Text *string `json:"text,omitempty"` | ||
Timestamp time.Time `json:"timestamp" binding:"required"` | ||
OrgID *string `json:"org_id,omitempty"` | ||
From time.Time `json:"from" binding:"required"` | ||
To time.Time `json:"to" binding:"required"` | ||
} | ||
|
||
// Be careful when changing this struct, it is used as input and output in the API. | ||
type MetricsCollectionDto struct { | ||
leo-marble marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CollectionID uuid.UUID `json:"collection_id" binding:"required"` | ||
Timestamp time.Time `json:"timestamp" binding:"required"` | ||
Metrics []MetricDataDto `json:"metrics" binding:"required"` | ||
Version string `json:"version" binding:"required"` | ||
DeploymentID uuid.UUID `json:"deployment_id" binding:"required"` | ||
LicenseKey *string `json:"license_key,omitempty"` | ||
} | ||
|
||
func AdaptMetricDataDto(metricData models.MetricData) MetricDataDto { | ||
return MetricDataDto{ | ||
Name: metricData.Name, | ||
Numeric: metricData.Numeric, | ||
Text: metricData.Text, | ||
Timestamp: metricData.Timestamp, | ||
OrgID: metricData.OrgID, | ||
From: metricData.From, | ||
To: metricData.To, | ||
} | ||
} | ||
|
||
func AdaptMetricsCollectionDto(metricsCollection models.MetricsCollection) MetricsCollectionDto { | ||
return MetricsCollectionDto{ | ||
CollectionID: metricsCollection.CollectionID, | ||
Timestamp: metricsCollection.Timestamp, | ||
Metrics: pure_utils.Map(metricsCollection.Metrics, AdaptMetricDataDto), | ||
Version: metricsCollection.Version, | ||
DeploymentID: metricsCollection.DeploymentID, | ||
LicenseKey: metricsCollection.LicenseKey, | ||
} | ||
} | ||
|
||
func AdaptMetricData(metricDataDto MetricDataDto) models.MetricData { | ||
return models.MetricData{ | ||
Name: metricDataDto.Name, | ||
Numeric: metricDataDto.Numeric, | ||
Text: metricDataDto.Text, | ||
Timestamp: metricDataDto.Timestamp, | ||
OrgID: metricDataDto.OrgID, | ||
From: metricDataDto.From, | ||
To: metricDataDto.To, | ||
} | ||
} | ||
|
||
func AdaptMetricsCollection(metricsCollectionDto MetricsCollectionDto) models.MetricsCollection { | ||
return models.MetricsCollection{ | ||
CollectionID: metricsCollectionDto.CollectionID, | ||
Timestamp: metricsCollectionDto.Timestamp, | ||
Metrics: pure_utils.Map(metricsCollectionDto.Metrics, AdaptMetricData), | ||
Version: metricsCollectionDto.Version, | ||
DeploymentID: metricsCollectionDto.DeploymentID, | ||
LicenseKey: metricsCollectionDto.LicenseKey, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.