Skip to content

Commit 9d51f79

Browse files
tiwatsukaYaSuenag
authored andcommitted
1 parent 734605d commit 9d51f79

File tree

72 files changed

+968
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+968
-167
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:6.0
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0
22

33
RUN apt-get update
44

.github/workflows/1-pr.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
# web app
99
DOCKERFILE_PATH: "CarbonAware.WebApi/src/Dockerfile"
1010
HEALTH_ENDPOINT: "0.0.0.0:8080/health"
11-
DLL_FILE_PATH: "./bin/Release/net6.0/CarbonAware.WebApi.dll"
11+
DLL_FILE_PATH: "./bin/Release/net8.0/CarbonAware.WebApi.dll"
1212
DOTNET_SRC_DIR: "./src"
1313
# console app packages
1414
DOTNET_SOLUTION: "src/GSF.CarbonAware/src/GSF.CarbonAware.csproj"
@@ -40,9 +40,9 @@ jobs:
4040

4141
- uses: actions/checkout@v2
4242
- name: Setup .NET
43-
uses: actions/setup-dotnet@v1
43+
uses: actions/setup-dotnet@v3
4444
with:
45-
dotnet-version: 6.0.x
45+
dotnet-version: 8.0.x
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
@@ -86,14 +86,14 @@ jobs:
8686
needs: sln-build-and-test
8787
runs-on: ubuntu-latest
8888
container:
89-
image: mcr.microsoft.com/dotnet/sdk:6.0
89+
image: mcr.microsoft.com/dotnet/sdk:8.0
9090
steps:
9191
- uses: actions/checkout@v3
9292

93-
- name: Setup .NET Core SDK 6
94-
uses: actions/setup-dotnet@v2
93+
- name: Setup .NET Core SDK 8
94+
uses: actions/setup-dotnet@v3
9595
with:
96-
dotnet-version: '6.0.x'
96+
dotnet-version: '8.0.x'
9797
include-prerelease: false
9898

9999
- name: Install dependencies
@@ -123,6 +123,8 @@ jobs:
123123

124124
- name: Generate Open API
125125
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
126+
env:
127+
DOTNET_ROLL_FORWARD: LatestMajor
126128
working-directory: ./src/CarbonAware.WebApi/src
127129

128130
- name: Upload swagger artifact
@@ -144,7 +146,7 @@ jobs:
144146

145147
- name: Docker Run Container
146148
run: |
147-
docker run -d --name runnable-container -p 8080:80 ca-api
149+
docker run -d --name runnable-container -p 8080:8080 ca-api
148150
docker container ls
149151
150152
- name: Docker WGET Health Endpoint
@@ -164,10 +166,10 @@ jobs:
164166
uses: actions/checkout@v3
165167
with:
166168
ref: dev
167-
- name: Setup .NET Core SDK 6
168-
uses: actions/setup-dotnet@v2
169+
- name: Setup .NET Core SDK 8
170+
uses: actions/setup-dotnet@v3
169171
with:
170-
dotnet-version: '6.0.x'
172+
dotnet-version: '8.0.x'
171173
include-prerelease: false
172174
- name: Install dependencies
173175
run: dotnet restore
@@ -179,6 +181,8 @@ jobs:
179181
working-directory: ${{ env.DOTNET_SRC_DIR }}
180182
- name: Generate Open API
181183
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
184+
env:
185+
DOTNET_ROLL_FORWARD: LatestMajor
182186
- name: Upload dev artifact
183187
uses: actions/upload-artifact@v1
184188
with:
@@ -199,10 +203,10 @@ jobs:
199203
- name: Checkout
200204
uses: actions/checkout@v3
201205

202-
- name: Setup .NET Core SDK 6
203-
uses: actions/setup-dotnet@v2
206+
- name: Setup .NET Core SDK 8
207+
uses: actions/setup-dotnet@v3
204208
with:
205-
dotnet-version: '6.0.x'
209+
dotnet-version: '8.0.x'
206210
include-prerelease: false
207211

208212
- name: Create packages
@@ -244,4 +248,4 @@ jobs:
244248
command: config
245249
globs: |
246250
./custom.markdownlint.jsonc
247-
{"*[^.github]/**,*"}.md
251+
{"*[^.github]/**,*"}.md

.github/workflows/dev_carbon-aware-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up .NET Core
2121
uses: actions/setup-dotnet@v1
2222
with:
23-
dotnet-version: '6.0.x'
23+
dotnet-version: '8.0.x'
2424
include-prerelease: true
2525

2626
- name: Build with dotnet

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "coreclr",
1111
"request": "launch",
1212
"preLaunchTask": "buildCLI",
13-
"program": "${workspaceFolder}/src/CarbonAware.CLI/src/bin/Debug/net6.0/caw.dll",
13+
"program": "${workspaceFolder}/src/CarbonAware.CLI/src/bin/Debug/net8.0/caw.dll",
1414
"args": [
1515
"emissions",
1616
"--location", "${input:caw_location}"
@@ -27,7 +27,7 @@
2727
"type": "coreclr",
2828
"request": "launch",
2929
"preLaunchTask": "buildWebApi",
30-
"program": "${workspaceFolder}/src/CarbonAware.WebApi/src/bin/Debug/net6.0/CarbonAware.WebApi.dll",
30+
"program": "${workspaceFolder}/src/CarbonAware.WebApi/src/bin/Debug/net8.0/CarbonAware.WebApi.dll",
3131
"args": [],
3232
"cwd": "${workspaceFolder}/src/CarbonAware.WebApi/src/",
3333
"stopAtEntry": false,

casdk-docs/docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ generated libraries for your language of choice!
1818

1919
Prerequisites:
2020

21-
- .NET Core 6.0
21+
- .NET Core 8.0
2222
- Alternatively:
2323
- Docker
2424
- VSCode (it is recommended to work in a Dev Container)

casdk-docs/docs/tutorial-basics/carbon-aware-webapi.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ CarbonAware.LocationSources.LocationSource: Warning: New key swedencentral_1 gen
456456
## Error Handling
457457

458458
The WebAPI leveraged the
459-
[.Net controller filter pipeline](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-6.0)
459+
[.Net controller filter pipeline](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-8.0)
460460
to ensure that all requests respond with a consistent JSON schema.
461461

462-
![.Net controller filter pipeline image](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters/_static/filter-pipeline-2.png?view=aspnetcore-6.0)
462+
![.Net controller filter pipeline image](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters/_static/filter-pipeline-2.png?view=aspnetcore-8.0)
463463

464464
Controllers are responsible for managing the "Success" responses. If an error
465465
occurs in the WebAPI code and an unhandled exception is thrown, the
@@ -470,7 +470,7 @@ caught and handled by the WebAPI code, the controller will continue to manage
470470
the response.
471471

472472
The .Net framework will automatically respond to validation errors with a
473-
[ValidationProblemDetails](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.validationproblemdetails?view=aspnetcore-6.0)
473+
[ValidationProblemDetails](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.validationproblemdetails?view=aspnetcore-8.0)
474474
object. Using the Exception Filter class enables the WebAPI to consistently
475475
respond with the `ValidationProblemDetails` error schema in all error cases and
476476
take advantage of error handling automatically provided by the framework.
@@ -489,7 +489,7 @@ specification
489489
cd CarbonAware.WebApi/src
490490
dotnet tool restore
491491
dotnet build --configuration Release --no-restore
492-
dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml bin/Release/net6.0/CarbonAware.WebApi.dll v1
492+
dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml bin/Release/net8.0/CarbonAware.WebApi.dll v1
493493
```
494494
1. The `CarbonAware.WebApi/src/wwwroot/api/v1/swagger.yaml` file contains the supported
495495
OpenApi specification.

casdk-docs/docs/tutorial-basics/containerization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ carbon_aware v1 6293e2528bf2 About an hour ago 230MB
2525
## Run WebApi Image
2626

2727
1. Run the image using `docker run` with host port 8000 mapped to the WebApi
28-
port 80 and configure environment variable settings for
28+
port 8080 and configure environment variable settings for
2929
[WattTime](https://www.watttime.org) provider.
3030

3131
```sh
32-
docker run --rm -p 8000:80 \
32+
docker run --rm -p 8000:8080 \
3333
> -e DataSources__EmissionsDataSource="WattTime" \
3434
> -e DataSources__ForecastDataSource="WattTime" \
3535
> -e DataSources__Configurations__WattTime__Type="WattTime" \
@@ -40,7 +40,7 @@ carbon_aware v1 6293e2528bf2 About an hour ago 230MB
4040
or the [ElectricityMaps](https://www.electricitymaps.com) provider
4141

4242
```sh
43-
docker run --rm -p 8000:80 \
43+
docker run --rm -p 8000:8080 \
4444
> -e DataSources__EmissionsDataSource="ElectricityMaps" \
4545
> -e DataSources__ForecastDataSource="ElectricityMaps" \
4646
> -e DataSources__Configurations__ElectricityMaps__Type="ElectricityMaps" \
@@ -52,7 +52,7 @@ carbon_aware v1 6293e2528bf2 About an hour ago 230MB
5252
or the [ElectricityMapsFree](https://www.co2signal.com/) provider
5353

5454
```sh
55-
docker run --rm -p 8000:80 \
55+
docker run --rm -p 8000:8080 \
5656
> -e DataSources__EmissionsDataSource="ElectricityMapsFree" \
5757
> -e DataSources__Configurations__ElectricityMapsFree__Type="ElectricityMapsFree" \
5858
> -e DataSources__Configurations__ElectricityMapsFree__token="<YOUR_CO2SIGNAL_TOKEN>" \

casdk-docs/docs/tutorial-extras/configuration.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
- [ElectricityMapsFree Configuration](#electricitymapsfree-configuration)
2020
- [API Token](#api-token)
2121
- [BaseUrl](#baseurl)
22+
- [Cache](#cache)
2223
- [CarbonAwareVars](#carbonawarevars)
2324
- [Tracing and Monitoring Configuration](#tracing-and-monitoring-configuration)
2425
- [Verbosity](#verbosity)
26+
- [Prometheus exporter](#prometheus-exporter-for-emissions-data)
2527
- [Web API Prefix](#web-api-prefix)
2628
- [LocationDataSourcesConfiguration](#locationdatasourcesconfiguration)
2729
- [Sample Configurations](#sample-configurations)
@@ -194,7 +196,7 @@ custom `EmissionsData` sets. The file should be located under the
194196
`<user's repo>/src/data/data-sources/` directory that is part of the repository.
195197
At build time, all the JSON files under `<user's repo>/src/data/data-sources/`
196198
are copied over the destination directory
197-
`<user's repo>/src/CarbonAware.WebApi/src/bin/[Debug|Publish]/net6.0/data-sources/json`
199+
`<user's repo>/src/CarbonAware.WebApi/src/bin/[Debug|Publish]/net8.0/data-sources/json`
198200
that is part of the `CarbonAware.WebApi` assembly. Also the file can be placed
199201
where the assembly `CarbonAware.WebApi.dll` is located under `data-sources/json`
200202
directory. For instance, if the application is installed under `/app`, copy the
@@ -327,6 +329,29 @@ The url to use when connecting to ElectricityMapsFree. Defaults to
327329
"https://api.co2signal.com/v1/" but can be overridden in the config if needed
328330
(such as to enable integration testing scenarios).
329331

332+
## Cache
333+
334+
Frequent access to data sources could cause problems such as performance trouble
335+
or exceed rate limit. To avoid them, you can configure data cache like this:
336+
337+
```json
338+
{
339+
"EmissionsDataCache": {
340+
"Enabled": true,
341+
"ExpirationMin": 30
342+
}
343+
}
344+
```
345+
346+
The behavior of current cache implementation:
347+
* Only emissions data are cached
348+
* Forecast data are not stored
349+
* The result of the latest query to data sources is cached
350+
* Use cache rather than data sources if even one datum in cache match with the query
351+
* Even though more data in data sources would be matched, they are not retrieved
352+
* Cached data are stored in memory
353+
* They are cleard when the process of the SDK is down
354+
330355
## CarbonAwareVars
331356

332357
This section contains the global settings for the SDK. The configuration looks
@@ -379,6 +404,32 @@ InstrumentationKey. For more details, please refer to
379404
AppInsights_InstrumentationKey="AppInsightsInstrumentationKey"
380405
```
381406

407+
### Prometheus exporter for emissions data
408+
409+
> DISCLAIMER: The `/metrics` Prometheus exporter is currently unsupported, and is used for internal GSF needs, and may change in the future. It will retrieve _all_ emissions data and create heavy load on your data API's. It is turned off by default.
410+
411+
In the WebApi project, this application can exporse latest carbon emissions data as a prometheus exporter.
412+
413+
```bash
414+
CarbonAwareVars__EnableCarbonExporter="true"
415+
```
416+
The scraping endpoint is `<ROOT_PATH>/metrics` like this:
417+
418+
```bash
419+
http://localhost/metrics
420+
```
421+
422+
By default, the exposed data are latest ones within last 24 hours. If you would like to change the period
423+
in some reasones, you can configure the value like this:
424+
425+
```json
426+
{
427+
"CarbonExporter": {
428+
"PeriodInHours": 48
429+
}
430+
}
431+
```
432+
382433
### Verbosity
383434

384435
You can configure the verbosity of the application error messages by setting the
@@ -427,7 +478,7 @@ By setting `LocationDataSourcesConfiguration` property with one or more location
427478
data sources, it is possible to load different `Location` data sets in order to
428479
have more than one location. For instance by setting two location regions, the
429480
property would be set as follow using
430-
[environment](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0#naming-of-environment-variables)
481+
[environment](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0#naming-of-environment-variables)
431482
variables:
432483

433484
```sh
@@ -458,7 +509,7 @@ curl "http://${IP_HOST}:${PORT}/emissions/bylocations/best?location=${REGION}&ti
458509
At build time, all the JSON files under
459510
`<user's repo>/src/data/location-sources` are copied over the destination
460511
directory
461-
`<user's repo>/src/CarbonAware.WebApi/src/bin/[Debug|Publish]/net6.0/location-sources/json`
512+
`<user's repo>/src/CarbonAware.WebApi/src/bin/[Debug|Publish]/net8.0/location-sources/json`
462513
that is part of the `CarbonAware.WebApi` assembly. Also the file can be placed
463514
where the assembly `CarbonAware.WebApi.dll` is located under
464515
`location-sources/json` directory. For instance, if the application is installed

casdk-docs/docs/tutorial-extras/packaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ project. When running in the dev container you will need:
6363
- [Remote Containers extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
6464

6565
Alternatively you can run in your local environment using the
66-
[.NET Core 6.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0).
66+
[.NET Core 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0).
6767

6868
## SDK Configuration
6969

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.418",
3+
"version": "8.0.201",
44
"rollForward": "latestFeature"
55
}
66
}

helm-chart/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
{{- end }}
4040
ports:
4141
- name: http
42-
containerPort: 80
42+
containerPort: 8080
4343
protocol: TCP
4444
volumeMounts:
4545
- name: appsettings

helm-chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ securityContext: {}
3737

3838
service:
3939
type: ClusterIP
40-
port: 80
40+
port: 8080
4141

4242
ingress:
4343
enabled: false

samples/azure/azure-function/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Find the Dockerfile at this URL
22
# https://github.com/Azure/azure-functions-docker/blob/dev/host/4/bullseye/amd64/dotnet/dotnet-inproc/dotnet.Dockerfile
33

4-
FROM mcr.microsoft.com/azure-functions/dotnet:4.0 AS base
4+
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
55
WORKDIR /home/site/wwwroot
66

7-
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
88
COPY ["src/", "data/src/"]
99
COPY ["scripts/", "data/scripts/"]
1010
COPY ["samples/", "data/samples/"]
@@ -21,3 +21,4 @@ RUN dotnet publish "samples/azure/azure-function/function.csproj" -c Release -o
2121
FROM base AS final
2222
WORKDIR /home/site/wwwroot
2323
COPY --from=publish /app/publish .
24+
ENV ASPNETCORE_CONTENTROOT=/home/site/wwwroot

0 commit comments

Comments
 (0)