Skip to content

Commit ef78d66

Browse files
authored
Add Since/Until for endpoint stats to libs (#927)
## Motivation We added this feature to our API a while ago (see [here](https://api.svix.com/docs#tag/Endpoint/operation/v1.endpoint.get-stats)), but never updated the libs. This PR corrects that. ## Solution Update the libs.
2 parents e733fbc + c23fb3b commit ef78d66

File tree

12 files changed

+183
-27
lines changed

12 files changed

+183
-27
lines changed

csharp/Svix/Endpoint.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ public EndpointStats GetStats(string appId, string endpointId, string idempotenc
531531
{
532532
var lStats = _endpointApi.V1EndpointGetStats(
533533
appId,
534-
endpointId);
534+
endpointId,
535+
null,
536+
null);
535537

536538
return lStats;
537539
}
@@ -546,6 +548,29 @@ public EndpointStats GetStats(string appId, string endpointId, string idempotenc
546548
}
547549
}
548550

551+
public EndpointStats GetStatsWithOptions(string appId, string endpointId, EndpointStatsOptions options = null, string idempotencyKey = default)
552+
{
553+
try
554+
{
555+
var lStats = _endpointApi.V1EndpointGetStats(
556+
appId,
557+
endpointId,
558+
options?.Since,
559+
options?.Until);
560+
561+
return lStats;
562+
}
563+
catch (ApiException e)
564+
{
565+
Logger?.LogError(e, $"{nameof(GetStatsWithOptions)} failed");
566+
567+
if (Throw)
568+
throw;
569+
570+
return null;
571+
}
572+
}
573+
549574
public async Task<EndpointStats> GetStatsAsync(string appId, string endpointId, string idempotencyKey = default,
550575
CancellationToken cancellationToken = default)
551576
{
@@ -571,6 +596,31 @@ public async Task<EndpointStats> GetStatsAsync(string appId, string endpointId,
571596
}
572597
}
573598

599+
public async Task<EndpointStats> GetStatsWithOptionsAsync(string appId, string endpointId, EndpointStatsOptions options = null, string idempotencyKey = default,
600+
CancellationToken cancellationToken = default)
601+
{
602+
try
603+
{
604+
var lStats = await _endpointApi.V1EndpointGetStatsAsync(
605+
appId,
606+
endpointId,
607+
options?.Since,
608+
options?.Until,
609+
cancellationToken);
610+
611+
return lStats;
612+
}
613+
catch (ApiException e)
614+
{
615+
Logger?.LogError(e, $"{nameof(GetStatsWithOptionsAsync)} failed");
616+
617+
if (Throw)
618+
throw;
619+
620+
return null;
621+
}
622+
}
623+
574624
public bool ReplayMissing(string appId, string endpointId, ReplayIn replayIn,
575625
string idempotencyKey = default)
576626
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Svix.Models
5+
{
6+
public sealed class EndpointStatsOptions
7+
{
8+
public DateTime? Since { get; set; }
9+
10+
public DateTime? Until { get; set; }
11+
}
12+
}

go/endpoint.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package svix
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/svix/svix-webhooks/go/internal/openapi"
78
)
@@ -35,6 +36,11 @@ type EndpointListOptions struct {
3536
Order *Ordering
3637
}
3738

39+
type EndpointStatsOptions struct {
40+
Since *time.Time
41+
Until *time.Time
42+
}
43+
3844
func (e *Endpoint) List(ctx context.Context, appId string, options *EndpointListOptions) (*ListResponseEndpointOut, error) {
3945
req := e.api.EndpointApi.V1EndpointList(ctx, appId)
4046
if options != nil {
@@ -182,7 +188,11 @@ func (e *Endpoint) PatchHeaders(ctx context.Context, appId string, endpointId st
182188
}
183189

184190
func (e *Endpoint) GetStats(ctx context.Context, appId string, endpointId string) (*EndpointStats, error) {
185-
req := e.api.EndpointApi.V1EndpointGetStats(ctx, appId, endpointId)
191+
return e.GetStatsWithOptions(ctx, appId, endpointId, EndpointStatsOptions{})
192+
}
193+
194+
func (e *Endpoint) GetStatsWithOptions(ctx context.Context, appId string, endpointId string, options EndpointStatsOptions) (*EndpointStats, error) {
195+
req := e.api.EndpointApi.V1EndpointGetStats(ctx, appId, endpointId, options.Since, options.Until)
186196
out, res, err := req.Execute()
187197
if err != nil {
188198
return nil, wrapError(err, res)

go/internal/openapi/api_endpoint.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/lib/src/main/java/com/svix/Endpoint.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public EndpointOut create(final String appId, final EndpointIn endpointIn) throw
3838
return this.create(appId, endpointIn, new PostOptions());
3939
}
4040

41-
public EndpointOut create(final String appId, final EndpointIn endpointIn, final PostOptions options) throws ApiException {
41+
public EndpointOut create(final String appId, final EndpointIn endpointIn, final PostOptions options)
42+
throws ApiException {
4243
try {
4344
return api.v1EndpointCreate(appId, endpointIn, options.getIdempotencyKey());
4445
} catch (com.svix.internal.ApiException e) {
@@ -54,7 +55,8 @@ public EndpointOut get(final String appId, final String endpointId) throws ApiEx
5455
}
5556
}
5657

57-
public EndpointOut update(final String appId, final String endpointId, final EndpointUpdate endpointUpdate) throws ApiException {
58+
public EndpointOut update(final String appId, final String endpointId, final EndpointUpdate endpointUpdate)
59+
throws ApiException {
5860
try {
5961
return api.v1EndpointUpdate(appId, endpointId, endpointUpdate);
6062
} catch (com.svix.internal.ApiException e) {
@@ -78,11 +80,13 @@ public EndpointSecretOut getSecret(final String appId, final String endpointId)
7880
}
7981
}
8082

81-
public void rotateSecret(final String appId, final String endpointId, final EndpointSecretRotateIn endpointSecretRotateIn) throws ApiException {
83+
public void rotateSecret(final String appId, final String endpointId,
84+
final EndpointSecretRotateIn endpointSecretRotateIn) throws ApiException {
8285
this.rotateSecret(appId, endpointId, endpointSecretRotateIn, new PostOptions());
8386
}
8487

85-
public void rotateSecret(final String appId, final String endpointId, final EndpointSecretRotateIn endpointSecretRotateIn, final PostOptions options) throws ApiException {
88+
public void rotateSecret(final String appId, final String endpointId,
89+
final EndpointSecretRotateIn endpointSecretRotateIn, final PostOptions options) throws ApiException {
8690
try {
8791
api.v1EndpointRotateSecret(appId, endpointId, endpointSecretRotateIn, options.getIdempotencyKey());
8892
} catch (com.svix.internal.ApiException e) {
@@ -94,7 +98,8 @@ public void recover(final String appId, final String endpointId, final RecoverIn
9498
this.recover(appId, endpointId, recoverIn, new PostOptions());
9599
}
96100

97-
public void recover(final String appId, final String endpointId, final RecoverIn recoverIn, final PostOptions options) throws ApiException {
101+
public void recover(final String appId, final String endpointId, final RecoverIn recoverIn,
102+
final PostOptions options) throws ApiException {
98103
try {
99104
api.v1EndpointRecover(appId, endpointId, recoverIn, options.getIdempotencyKey());
100105
} catch (com.svix.internal.ApiException e) {
@@ -110,15 +115,17 @@ public EndpointHeadersOut getHeaders(final String appId, final String endpointId
110115
}
111116
}
112117

113-
public void updateHeaders(final String appId, final String endpointId, final EndpointHeadersIn endpointHeadersIn) throws ApiException {
118+
public void updateHeaders(final String appId, final String endpointId, final EndpointHeadersIn endpointHeadersIn)
119+
throws ApiException {
114120
try {
115121
api.v1EndpointUpdateHeaders(appId, endpointId, endpointHeadersIn);
116122
} catch (com.svix.internal.ApiException e) {
117123
throw Utils.wrapInternalApiException(e);
118124
}
119125
}
120126

121-
public void patchHeaders(final String appId, final String endpointId, final EndpointHeadersPatchIn endpointHeadersIn) throws ApiException {
127+
public void patchHeaders(final String appId, final String endpointId,
128+
final EndpointHeadersPatchIn endpointHeadersIn) throws ApiException {
122129
try {
123130
api.v1EndpointPatchHeaders(appId, endpointId, endpointHeadersIn);
124131
} catch (com.svix.internal.ApiException e) {
@@ -127,46 +134,57 @@ public void patchHeaders(final String appId, final String endpointId, final Endp
127134
}
128135

129136
public EndpointStats getStats(final String appId, final String endpointId) throws ApiException {
137+
return getStats(appId, endpointId, new EndpointStatsOptions());
138+
}
139+
140+
public EndpointStats getStats(final String appId, final String endpointId, final EndpointStatsOptions options)
141+
throws ApiException {
130142
try {
131-
return api.v1EndpointGetStats(appId, endpointId, null, null);
143+
return api.v1EndpointGetStats(appId, endpointId, options.getSince(), options.getUntil());
132144
} catch (com.svix.internal.ApiException e) {
133145
throw Utils.wrapInternalApiException(e);
134146
}
135147
}
136148

137-
public void replayMissing(final String appId, final String endpointId, final ReplayIn replayIn) throws ApiException {
149+
public void replayMissing(final String appId, final String endpointId, final ReplayIn replayIn)
150+
throws ApiException {
138151
this.replayMissing(appId, endpointId, replayIn, new PostOptions());
139152
}
140153

141-
public void replayMissing(final String appId, final String endpointId, final ReplayIn replayIn, final PostOptions options) throws ApiException {
154+
public void replayMissing(final String appId, final String endpointId, final ReplayIn replayIn,
155+
final PostOptions options) throws ApiException {
142156
try {
143157
api.v1EndpointReplay(appId, endpointId, replayIn, options.getIdempotencyKey());
144158
} catch (com.svix.internal.ApiException e) {
145159
throw Utils.wrapInternalApiException(e);
146160
}
147161
}
148162

149-
public EndpointTransformationOut transformationGet(final String appId, final String endpointId) throws ApiException {
163+
public EndpointTransformationOut transformationGet(final String appId, final String endpointId)
164+
throws ApiException {
150165
try {
151166
return api.v1EndpointTransformationGet(appId, endpointId);
152167
} catch (com.svix.internal.ApiException e) {
153168
throw Utils.wrapInternalApiException(e);
154169
}
155170
}
156171

157-
public void transformationPartialUpdate(final String appId, final String endpointId, final EndpointTransformationIn transformationIn) throws ApiException {
172+
public void transformationPartialUpdate(final String appId, final String endpointId,
173+
final EndpointTransformationIn transformationIn) throws ApiException {
158174
try {
159175
api.v1EndpointTransformationPartialUpdate(appId, endpointId, transformationIn);
160176
} catch (com.svix.internal.ApiException e) {
161177
throw Utils.wrapInternalApiException(e);
162178
}
163179
}
164180

165-
public MessageOut sendExample(final String appId, final String endpointId, final EventExampleIn eventExampleIn) throws ApiException {
181+
public MessageOut sendExample(final String appId, final String endpointId, final EventExampleIn eventExampleIn)
182+
throws ApiException {
166183
return this.sendExample(appId, endpointId, eventExampleIn, new PostOptions());
167184
}
168185

169-
public MessageOut sendExample(final String appId, final String endpointId, final EventExampleIn eventExampleIn, final PostOptions options) throws ApiException {
186+
public MessageOut sendExample(final String appId, final String endpointId, final EventExampleIn eventExampleIn,
187+
final PostOptions options) throws ApiException {
170188
try {
171189
return api.v1EndpointSendExample(appId, endpointId, eventExampleIn, options.getIdempotencyKey());
172190
} catch (com.svix.internal.ApiException e) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.svix;
2+
3+
import org.threeten.bp.OffsetDateTime;
4+
5+
public class EndpointStatsOptions {
6+
private OffsetDateTime since;
7+
private OffsetDateTime until;
8+
9+
public void setSince(final OffsetDateTime since) {
10+
this.since = since;
11+
}
12+
13+
public OffsetDateTime getSince() {
14+
return since;
15+
}
16+
17+
public void setUntil(final OffsetDateTime until) {
18+
this.until = until;
19+
}
20+
21+
public OffsetDateTime getUntil() {
22+
return until;
23+
}
24+
}

javascript/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ export interface EndpointListOptions extends ListOptions {
182182
order?: Ordering;
183183
}
184184

185+
export interface EndpointStatsOptions {
186+
since?: Date;
187+
until?: Date;
188+
}
189+
185190
export type IntegrationListOptions = ListOptions;
186191

187192
export interface EventTypeListOptions extends ListOptions {
@@ -385,10 +390,11 @@ class Endpoint {
385390
});
386391
}
387392

388-
public getStats(appId: string, endpointId: string): Promise<EndpointStats> {
393+
public getStats(appId: string, endpointId: string, options?: EndpointStatsOptions): Promise<EndpointStats> {
389394
return this.api.v1EndpointGetStats({
390395
appId,
391396
endpointId,
397+
...options
392398
});
393399
}
394400

kotlin/lib/src/main/kotlin/Endpoint.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ class Endpoint internal constructor(token: String, options: SvixOptions) {
182182
}
183183
}
184184

185-
suspend fun getStats(appId: String, endpointId: String): EndpointStats {
185+
suspend fun getStats(
186+
appId: String,
187+
endpointId: String,
188+
options: EndpointStatsOptions = EndpointStatsOptions()
189+
): EndpointStats {
186190
try {
187191
return api.v1EndpointGetStats(
188192
appId,
189193
endpointId,
190-
null,
191-
null
194+
options.since,
195+
options.until
192196
)
193197
} catch (e: Exception) {
194198
throw ApiException.wrap(e)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.svix.kotlin
2+
3+
import java.time.OffsetDateTime
4+
5+
class EndpointStatsOptions {
6+
var since: OffsetDateTime? = null
7+
var until: OffsetDateTime? = null
8+
}

python/svix/api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ class EndpointListOptions(ListOptions):
171171
order: t.Optional[Ordering] = None
172172

173173

174+
@dataclass
175+
class EndpointStatsOptions:
176+
since: t.Optional[datetime] = None
177+
until: t.Optional[datetime] = None
178+
179+
174180
@dataclass
175181
class IntegrationListOptions(ListOptions):
176182
pass
@@ -486,11 +492,15 @@ def patch_headers(self, app_id: str, endpoint_id: str, endpoint_headers_in: Endp
486492
json_body=endpoint_headers_in,
487493
)
488494

489-
def get_stats(self, app_id: str, endpoint_id: str) -> EndpointStats:
495+
def get_stats(
496+
self, app_id: str, endpoint_id: str, options: EndpointStatsOptions = EndpointStatsOptions()
497+
) -> EndpointStats:
490498
return v1_endpoint_get_stats.sync(
491499
client=self._client,
492500
app_id=app_id,
493501
endpoint_id=endpoint_id,
502+
since=options.since,
503+
until=options.until,
494504
)
495505

496506
def replay_missing(

0 commit comments

Comments
 (0)