Skip to content

Commit

Permalink
Merge branch 'master' into 475-use-k8s-job-instead-of-pod-for-blob-ca…
Browse files Browse the repository at this point in the history
…che-transfer
  • Loading branch information
munishchouhan committed Jul 3, 2024
2 parents 17d8f46 + 32f7dd1 commit 322ab8b
Show file tree
Hide file tree
Showing 35 changed files with 469 additions and 172 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/typespec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Typespec_Validation

on:
push:
branches:
- '**'
paths :
- 'typespec/**'
pull_request:
types: [opened, reopened, synchronize]
paths:
- 'typespec/**'

permissions:
contents: read

jobs:
typespec_validation:
name: validate typespec files
runs-on: ubuntu-latest

steps:
- name : Checkout
uses : actions/checkout@v4

- name : Setup Node.js environment
uses : actions/setup-node@v4
with :
node-version : '20.9.0'

- name : Install tsp
run : npm install -g @typespec/compiler

- name : Validate tsp files
run : |
cd typespec
tsp install
tsp compile .
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ scan-workspace/
.cache
site/
deployment-url.txt

#typespec
tsp-output/
node_modules/
package-lock.json
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ container registry where the image is stored, while the instrumented layers are
'-Djdk.httpclient.HttpClient.log=requests,headers'
```

## TypeSpec API Specifications

- You can find the API specifications using (typespec)[https://github.com/microsoft/typespec] in typespec directory. Use following command to generate the API specifications.

```bash
'cd typespec'
'tsp install'
'tsp compile .'
```

- Check `typespec/tsp-output` directory for the generated API specifications.

## Related links
* [Wave command line tool](https://github.com/seqeralabs/wave-cli)
Expand Down
30 changes: 20 additions & 10 deletions docs/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ Provides status of build against buildId passed as path variable

```json
{
serviceInfo: {
id: string,
status: string,
startTime: string,
duration: string,
succeeded: boolean
}
id: string,
status: string,
startTime: string,
duration: string,
succeeded: boolean
}
```

Expand Down Expand Up @@ -527,7 +525,7 @@ This endpoint is used to retrieve the builds performed by Wave.

```json
{
metric: "builds|pulls|fusion",
metric: "builds",
count: integer,
orgs: {
String: integer,
Expand Down Expand Up @@ -590,7 +588,13 @@ This endpoint is used to get the pulls performed through Wave.

```json
{
count: integer
metric: "pulls",
count: integer,
orgs: {
String: integer,
String: integer,
...
}
}
```

Expand Down Expand Up @@ -648,7 +652,13 @@ This endpoint is used to get the pulls of Fusion-based containers performed thro

```json
{
count: integer
metric: "fusion",
count: integer,
orgs: {
String: integer,
String: integer,
...
}
}
```

Expand Down
18 changes: 8 additions & 10 deletions src/main/groovy/io/seqera/wave/controller/MetricsController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ import io.micronaut.security.annotation.Secured
import io.micronaut.security.authentication.AuthorizationException
import io.micronaut.security.rules.SecurityRule
import io.seqera.wave.exception.BadRequestException
import io.seqera.wave.service.metric.MetricConstants
import io.seqera.wave.service.metric.MetricsConstants
import io.seqera.wave.service.metric.MetricsService
import io.seqera.wave.service.metric.model.GetBuildsCountResponse
import io.seqera.wave.service.metric.model.GetFusionPullsCountResponse
import io.seqera.wave.service.metric.model.GetPullsCountResponse

import jakarta.inject.Inject

import static io.micronaut.http.HttpHeaders.WWW_AUTHENTICATE
Expand All @@ -65,25 +63,25 @@ class MetricsController {
@Get(uri = "/v1alpha2/metrics/builds", produces = MediaType.APPLICATION_JSON)
HttpResponse<?> getBuildsMetrics(@Nullable @QueryValue String date, @Nullable @QueryValue String org) {
if(!date && !org)
return HttpResponse.ok(metricsService.getAllOrgCount(MetricConstants.PREFIX_BUILDS))
return HttpResponse.ok(metricsService.getAllOrgCount(MetricsConstants.PREFIX_BUILDS))
validateQueryParams(date)
return HttpResponse.ok(metricsService.getOrgCount(MetricConstants.PREFIX_BUILDS, date, org))
return HttpResponse.ok(metricsService.getOrgCount(MetricsConstants.PREFIX_BUILDS, date, org))
}

@Get(uri = "/v1alpha2/metrics/pulls", produces = MediaType.APPLICATION_JSON)
HttpResponse<?> getPullsMetrics(@Nullable @QueryValue String date, @Nullable @QueryValue String org) {
if(!date && !org)
return HttpResponse.ok(metricsService.getAllOrgCount(MetricConstants.PREFIX_PULLS))
return HttpResponse.ok(metricsService.getAllOrgCount(MetricsConstants.PREFIX_PULLS))
validateQueryParams(date)
return HttpResponse.ok(metricsService.getOrgCount(MetricConstants.PREFIX_PULLS, date, org))
return HttpResponse.ok(metricsService.getOrgCount(MetricsConstants.PREFIX_PULLS, date, org))
}

@Get(uri = "/v1alpha2/metrics/fusion/pulls", produces = MediaType.APPLICATION_JSON)
HttpResponse<?> getFusionPullsMetrics(@Nullable @QueryValue String date, @Nullable @QueryValue String org) {
if(!date && !org)
return HttpResponse.ok(metricsService.getAllOrgCount(MetricConstants.PREFIX_FUSION))
return HttpResponse.ok(metricsService.getAllOrgCount(MetricsConstants.PREFIX_FUSION))
validateQueryParams(date)
return HttpResponse.ok(metricsService.getOrgCount(MetricConstants.PREFIX_FUSION, date, org))
return HttpResponse.ok(metricsService.getOrgCount(MetricsConstants.PREFIX_FUSION, date, org))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package io.seqera.wave.service.metric
*
* @author Munish Chouhan <[email protected]>
*/
interface MetricConstants {
interface MetricsConstants {

static final public String PREFIX_FUSION = 'fusion'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import java.util.regex.Pattern

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.seqera.wave.service.metric.MetricConstants
import io.seqera.wave.service.metric.MetricsCounterStore
import io.seqera.wave.service.metric.MetricsService
import io.seqera.wave.service.metric.model.GetOrgCountResponse
import io.seqera.wave.tower.PlatformId
import jakarta.inject.Inject
import jakarta.inject.Singleton

import static io.seqera.wave.service.metric.MetricsConstants.*
/**
* Implements service to store and retrieve wave metrics from the counter store
*
Expand All @@ -52,13 +53,13 @@ class MetricsServiceImpl implements MetricsService {
@Override
GetOrgCountResponse getAllOrgCount(String metric){
final response = new GetOrgCountResponse(metric, 0, [:])
final orgCounts = metricsCounterStore.getAllMatchingEntries("$metric/$MetricConstants.PREFIX_ORG/*")
final orgCounts = metricsCounterStore.getAllMatchingEntries("$metric/$PREFIX_ORG/*")
for(def entry : orgCounts) {
// orgCounts also contains the records with org and date, so here it filter out the records with date
if(!entry.key.contains("/$MetricConstants.PREFIX_DAY/")) {
if(!entry.key.contains("/$PREFIX_DAY/")) {
response.count += entry.value
//split is used to extract the org name from the key like "metrics/o/seqera.io" => seqera.io
response.orgs.put(entry.key.split("/$MetricConstants.PREFIX_ORG/").last(), entry.value)
response.orgs.put(entry.key.split("/$PREFIX_ORG/").last(), entry.value)
}
}
return response
Expand All @@ -76,7 +77,7 @@ class MetricsServiceImpl implements MetricsService {
response.orgs.put(org, response.count)
}else{
// when only date is provide, scan the store and return the count for all orgs on given date
final orgCounts = metricsCounterStore.getAllMatchingEntries("$metric/$MetricConstants.PREFIX_ORG/*/$MetricConstants.PREFIX_DAY/$date")
final orgCounts = metricsCounterStore.getAllMatchingEntries("$metric/$PREFIX_ORG/*/$PREFIX_DAY/$date")
for(def entry : orgCounts) {
response.orgs.put(extractOrgFromKey(entry.key), entry.value)
}
Expand All @@ -88,17 +89,17 @@ class MetricsServiceImpl implements MetricsService {

@Override
void incrementFusionPullsCounter(PlatformId platformId){
incrementCounter(MetricConstants.PREFIX_FUSION, platformId?.user?.email)
incrementCounter(PREFIX_FUSION, platformId?.user?.email)
}

@Override
void incrementBuildsCounter(PlatformId platformId){
incrementCounter(MetricConstants.PREFIX_BUILDS, platformId?.user?.email)
incrementCounter(PREFIX_BUILDS, platformId?.user?.email)
}

@Override
void incrementPullsCounter(PlatformId platformId) {
incrementCounter(MetricConstants.PREFIX_PULLS, platformId?.user?.email)
incrementCounter(PREFIX_PULLS, platformId?.user?.email)
}

protected void incrementCounter(String prefix, String email) {
Expand Down Expand Up @@ -127,13 +128,13 @@ class MetricsServiceImpl implements MetricsService {

protected static String getKey(String prefix, String day, String org){
if( day && org )
return "$prefix/$MetricConstants.PREFIX_ORG/$org/$MetricConstants.PREFIX_DAY/$day"
return "$prefix/$PREFIX_ORG/$org/$PREFIX_DAY/$day"

if( org )
return "$prefix/$MetricConstants.PREFIX_ORG/$org"
return "$prefix/$PREFIX_ORG/$org"

if( day )
return "$prefix/$MetricConstants.PREFIX_DAY/$day"
return "$prefix/$PREFIX_DAY/$day"

return null
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 322ab8b

Please sign in to comment.