-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BRIDGE-122): Observability support; type definitions, helper met…
…hods in fake server
- Loading branch information
1 parent
dd607af
commit ca6bb64
Showing
7 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,13 @@ | ||
package proton | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
func (c *Client) SendObservabilityBatch(ctx context.Context, req ObservabilityBatch) error { | ||
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { | ||
return r.SetHeader("Priority", "u=6").SetBody(req).Post("/data/v1/metrics") | ||
}) | ||
} |
This file contains 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,12 @@ | ||
package proton | ||
|
||
type ObservabilityBatch struct { | ||
Metrics []ObservabilityMetric `json:"Metrics"` | ||
} | ||
|
||
type ObservabilityMetric struct { | ||
Name string `json:"Name"` | ||
Version int `json:"Version"` | ||
Timestamp int64 `json:"Timestamp"` // Unix timestamp | ||
Data interface{} `json:"Data"` | ||
} |
This file contains 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 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,32 @@ | ||
package backend | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ProtonMail/go-proton-api" | ||
) | ||
|
||
type ObservabilityStatistics struct { | ||
Metrics []proton.ObservabilityMetric | ||
RequestTime []time.Time | ||
} | ||
|
||
func NewObservabilityStatistics() ObservabilityStatistics { | ||
return ObservabilityStatistics{ | ||
Metrics: make([]proton.ObservabilityMetric, 0), | ||
RequestTime: make([]time.Time, 0), | ||
} | ||
} | ||
|
||
func (b *Backend) PushObservabilityMetrics(metrics []proton.ObservabilityMetric) { | ||
writeBackend(b, func(b *unsafeBackend) { | ||
b.observabilityStatistics.Metrics = append(b.observabilityStatistics.Metrics, metrics...) | ||
b.observabilityStatistics.RequestTime = append(b.observabilityStatistics.RequestTime, time.Now()) | ||
}) | ||
} | ||
|
||
func (b *Backend) GetObservabilityStatistics() ObservabilityStatistics { | ||
return readBackendRet(b, func(b *unsafeBackend) ObservabilityStatistics { | ||
return b.observabilityStatistics | ||
}) | ||
} |
This file contains 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 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 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