From c7f00e011f78f63ee67258a4c45358fe6dbbe571 Mon Sep 17 00:00:00 2001 From: Heba Elayoty Date: Mon, 27 Mar 2023 14:48:14 -0700 Subject: [PATCH 1/2] Add license and format files Signed-off-by: Heba Elayoty --- .gitignore | 2 + cmd/exporter/app/config/config.go | 4 + cmd/exporter/app/options/options.go | 4 + pkg/sdk/client/README.md | 20 ++--- pkg/sdk/client/api_carbon_aware.go | 31 ++++--- pkg/sdk/client/api_locations.go | 5 +- pkg/sdk/client/client.go | 4 +- pkg/sdk/client/configuration.go | 4 +- pkg/sdk/client/docs/CarbonAwareApi.md | 86 +++++++++---------- .../docs/CarbonIntensityBatchParametersDto.md | 10 +-- pkg/sdk/client/docs/CarbonIntensityDto.md | 12 +-- pkg/sdk/client/docs/EmissionsData.md | 12 +-- pkg/sdk/client/docs/EmissionsDataDto.md | 12 +-- .../EmissionsForecastBatchParametersDto.md | 14 +-- pkg/sdk/client/docs/EmissionsForecastDto.md | 20 ++--- pkg/sdk/client/docs/Location.md | 10 +-- pkg/sdk/client/docs/LocationsApi.md | 6 +- ...l_carbon_intensity_batch_parameters_dto.go | 4 +- pkg/sdk/client/model_carbon_intensity_dto.go | 4 +- pkg/sdk/client/model_emissions_data.go | 4 +- pkg/sdk/client/model_emissions_data_dto.go | 4 +- ...emissions_forecast_batch_parameters_dto.go | 4 +- .../client/model_emissions_forecast_dto.go | 4 +- pkg/sdk/client/model_location.go | 4 +- pkg/sdk/client/response.go | 4 +- 25 files changed, 137 insertions(+), 151 deletions(-) diff --git a/.gitignore b/.gitignore index 5326ed9..5c3d031 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ _testmain.go *.travis.yml *git_push.sh _output + +.idea diff --git a/cmd/exporter/app/config/config.go b/cmd/exporter/app/config/config.go index e08bb60..6bccef7 100644 --- a/cmd/exporter/app/config/config.go +++ b/cmd/exporter/app/config/config.go @@ -1,3 +1,7 @@ +/* +MIT License +Copyright (c) Microsoft Corporation. +*/ package config import ( diff --git a/cmd/exporter/app/options/options.go b/cmd/exporter/app/options/options.go index e2a5065..27920a3 100644 --- a/cmd/exporter/app/options/options.go +++ b/cmd/exporter/app/options/options.go @@ -1,3 +1,7 @@ +/* +MIT License +Copyright (c) Microsoft Corporation. +*/ package options import ( diff --git a/pkg/sdk/client/README.md b/pkg/sdk/client/README.md index 141fc1b..01afaf2 100644 --- a/pkg/sdk/client/README.md +++ b/pkg/sdk/client/README.md @@ -19,16 +19,16 @@ import "./client" All URIs are relative to *https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0* -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -*CarbonAwareApi* | [**BatchForecastDataAsync**](docs/CarbonAwareApi.md#batchforecastdataasync) | **Post** /emissions/forecasts/batch | Given an array of historical forecasts, retrieves the data that contains forecasts metadata, the optimal forecast and a range of forecasts filtered by the attributes [start...end] if provided. -*CarbonAwareApi* | [**GetAverageCarbonIntensity**](docs/CarbonAwareApi.md#getaveragecarbonintensity) | **Get** /emissions/average-carbon-intensity | Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period. -*CarbonAwareApi* | [**GetAverageCarbonIntensityBatch**](docs/CarbonAwareApi.md#getaveragecarbonintensitybatch) | **Post** /emissions/average-carbon-intensity/batch | Given an array of request objects, each with their own location and time boundaries, calculate the average carbon intensity for that location and time period and return an array of carbon intensity objects. -*CarbonAwareApi* | [**GetBestEmissionsDataForLocationsByTime**](docs/CarbonAwareApi.md#getbestemissionsdataforlocationsbytime) | **Get** /emissions/bylocations/best | Calculate the best emission data by list of locations for a specified time period. -*CarbonAwareApi* | [**GetCurrentForecastData**](docs/CarbonAwareApi.md#getcurrentforecastdata) | **Get** /emissions/forecasts/current | Retrieves the most recent forecasted data and calculates the optimal marginal carbon intensity window. -*CarbonAwareApi* | [**GetEmissionsDataForLocationByTime**](docs/CarbonAwareApi.md#getemissionsdataforlocationbytime) | **Get** /emissions/bylocation | Calculate the best emission data by location for a specified time period. -*CarbonAwareApi* | [**GetEmissionsDataForLocationsByTime**](docs/CarbonAwareApi.md#getemissionsdataforlocationsbytime) | **Get** /emissions/bylocations | Calculate the observed emission data by list of locations for a specified time period. -*LocationsApi* | [**GetAllLocations**](docs/LocationsApi.md#getalllocations) | **Get** /locations | Get all locations instances +| Class | Method | HTTP request | Description | +|------------------|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| *CarbonAwareApi* | [**BatchForecastDataAsync**](/pkg/sdk/client/docs/CarbonAwareApi.md#batchforecastdataasync) | **Post** /emissions/forecasts/batch | Given an array of historical forecasts, retrieves the data that contains forecasts metadata, the optimal forecast and a range of forecasts filtered by the attributes [start...end] if provided. | +| *CarbonAwareApi* | [**GetAverageCarbonIntensity**](/pkg/sdk/client/docs/CarbonAwareApi.md#getaveragecarbonintensity) | **Get** /emissions/average-carbon-intensity | Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period. | +| *CarbonAwareApi* | [**GetAverageCarbonIntensityBatch**](/pkg/sdk/client/docs/CarbonAwareApi.md#getaveragecarbonintensitybatch) | **Post** /emissions/average-carbon-intensity/batch | Given an array of request objects, each with their own location and time boundaries, calculate the average carbon intensity for that location and time period and return an array of carbon intensity objects. | +| *CarbonAwareApi* | [**GetBestEmissionsDataForLocationsByTime**](/pkg/sdk/client/docs/CarbonAwareApi.md#getbestemissionsdataforlocationsbytime) | **Get** /emissions/bylocations/best | Calculate the best emission data by list of locations for a specified time period. | +| *CarbonAwareApi* | [**GetCurrentForecastData**](/pkg/sdk/client/docs/CarbonAwareApi.md#getcurrentforecastdata) | **Get** /emissions/forecasts/current | Retrieves the most recent forecasted data and calculates the optimal marginal carbon intensity window. | +| *CarbonAwareApi* | [**GetEmissionsDataForLocationByTime**](/pkg/sdk/client/docs/CarbonAwareApi.md#getemissionsdataforlocationbytime) | **Get** /emissions/bylocation | Calculate the best emission data by location for a specified time period. | +| *CarbonAwareApi* | [**GetEmissionsDataForLocationsByTime**](/pkg/sdk/client/docs/CarbonAwareApi.md#getemissionsdataforlocationsbytime) | **Get** /emissions/bylocations | Calculate the observed emission data by list of locations for a specified time period. | +| *LocationsApi* | [**GetAllLocations**](docs/LocationsApi.md#getalllocations) | **Get** /locations | Get all locations instances | ## Documentation For Models diff --git a/pkg/sdk/client/api_carbon_aware.go b/pkg/sdk/client/api_carbon_aware.go index 0ec87a5..3a99074 100644 --- a/pkg/sdk/client/api_carbon_aware.go +++ b/pkg/sdk/client/api_carbon_aware.go @@ -1,21 +1,20 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( "context" - "github.com/antihax/optional" "io/ioutil" "net/http" "net/url" "strings" "time" + + "github.com/antihax/optional" ) // Linger please @@ -117,7 +116,7 @@ func (a *CarbonAwareApiService) BatchForecastDataAsync(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -127,7 +126,7 @@ func (a *CarbonAwareApiService) BatchForecastDataAsync(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 500 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -228,7 +227,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, l return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -238,7 +237,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, l return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 500 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -345,7 +344,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensityBatch(ctx context.Conte return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -355,7 +354,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensityBatch(ctx context.Conte return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 500 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -465,7 +464,7 @@ func (a *CarbonAwareApiService) GetBestEmissionsDataForLocationsByTime(ctx conte return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -581,7 +580,7 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -591,7 +590,7 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 500 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -601,7 +600,7 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 501 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -711,7 +710,7 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationByTime(ctx context.Co return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() @@ -821,7 +820,7 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationsByTime(ctx context.C return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 400 { - var v map[string]Object + var v map[string]interface{} err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) if err != nil { newErr.error = err.Error() diff --git a/pkg/sdk/client/api_locations.go b/pkg/sdk/client/api_locations.go index 17bff54..cfa54a1 100644 --- a/pkg/sdk/client/api_locations.go +++ b/pkg/sdk/client/api_locations.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( @@ -26,7 +24,6 @@ type LocationsApiService service /* LocationsApiService Get all locations instances - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return map[string]Location */ func (a *LocationsApiService) GetAllLocations(ctx context.Context) (map[string]Location, *http.Response, error) { diff --git a/pkg/sdk/client/client.go b/pkg/sdk/client/client.go index e8fbba8..1c22122 100644 --- a/pkg/sdk/client/client.go +++ b/pkg/sdk/client/client.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/configuration.go b/pkg/sdk/client/configuration.go index b0e7390..8bf6af0 100644 --- a/pkg/sdk/client/configuration.go +++ b/pkg/sdk/client/configuration.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/docs/CarbonAwareApi.md b/pkg/sdk/client/docs/CarbonAwareApi.md index 3c47416..52d68cc 100644 --- a/pkg/sdk/client/docs/CarbonAwareApi.md +++ b/pkg/sdk/client/docs/CarbonAwareApi.md @@ -2,15 +2,15 @@ All URIs are relative to *https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0* -Method | HTTP request | Description -------------- | ------------- | ------------- -[**BatchForecastDataAsync**](CarbonAwareApi.md#BatchForecastDataAsync) | **Post** /emissions/forecasts/batch | Given an array of historical forecasts, retrieves the data that contains forecasts metadata, the optimal forecast and a range of forecasts filtered by the attributes [start...end] if provided. -[**GetAverageCarbonIntensity**](CarbonAwareApi.md#GetAverageCarbonIntensity) | **Get** /emissions/average-carbon-intensity | Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period. -[**GetAverageCarbonIntensityBatch**](CarbonAwareApi.md#GetAverageCarbonIntensityBatch) | **Post** /emissions/average-carbon-intensity/batch | Given an array of request objects, each with their own location and time boundaries, calculate the average carbon intensity for that location and time period and return an array of carbon intensity objects. -[**GetBestEmissionsDataForLocationsByTime**](CarbonAwareApi.md#GetBestEmissionsDataForLocationsByTime) | **Get** /emissions/bylocations/best | Calculate the best emission data by list of locations for a specified time period. -[**GetCurrentForecastData**](CarbonAwareApi.md#GetCurrentForecastData) | **Get** /emissions/forecasts/current | Retrieves the most recent forecasted data and calculates the optimal marginal carbon intensity window. -[**GetEmissionsDataForLocationByTime**](CarbonAwareApi.md#GetEmissionsDataForLocationByTime) | **Get** /emissions/bylocation | Calculate the best emission data by location for a specified time period. -[**GetEmissionsDataForLocationsByTime**](CarbonAwareApi.md#GetEmissionsDataForLocationsByTime) | **Get** /emissions/bylocations | Calculate the observed emission data by list of locations for a specified time period. +| Method | HTTP request | Description | +|--------------------------------------------------------------------------------------------------------|----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [**BatchForecastDataAsync**](CarbonAwareApi.md#BatchForecastDataAsync) | **Post** /emissions/forecasts/batch | Given an array of historical forecasts, retrieves the data that contains forecasts metadata, the optimal forecast and a range of forecasts filtered by the attributes [start...end] if provided. | +| [**GetAverageCarbonIntensity**](CarbonAwareApi.md#GetAverageCarbonIntensity) | **Get** /emissions/average-carbon-intensity | Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period. | +| [**GetAverageCarbonIntensityBatch**](CarbonAwareApi.md#GetAverageCarbonIntensityBatch) | **Post** /emissions/average-carbon-intensity/batch | Given an array of request objects, each with their own location and time boundaries, calculate the average carbon intensity for that location and time period and return an array of carbon intensity objects. | +| [**GetBestEmissionsDataForLocationsByTime**](CarbonAwareApi.md#GetBestEmissionsDataForLocationsByTime) | **Get** /emissions/bylocations/best | Calculate the best emission data by list of locations for a specified time period. | +| [**GetCurrentForecastData**](CarbonAwareApi.md#GetCurrentForecastData) | **Get** /emissions/forecasts/current | Retrieves the most recent forecasted data and calculates the optimal marginal carbon intensity window. | +| [**GetEmissionsDataForLocationByTime**](CarbonAwareApi.md#GetEmissionsDataForLocationByTime) | **Get** /emissions/bylocation | Calculate the best emission data by location for a specified time period. | +| [**GetEmissionsDataForLocationsByTime**](CarbonAwareApi.md#GetEmissionsDataForLocationsByTime) | **Get** /emissions/bylocations | Calculate the observed emission data by list of locations for a specified time period. | # **BatchForecastDataAsync** > []EmissionsForecastDto BatchForecastDataAsync(ctx, optional) @@ -20,10 +20,10 @@ This endpoint takes a batch of requests for historical forecast data, fetches th ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **optional** | ***CarbonAwareApiBatchForecastDataAsyncOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|-----------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **optional** | ***CarbonAwareApiBatchForecastDataAsyncOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiBatchForecastDataAsyncOpts struct @@ -54,12 +54,12 @@ This endpoint is useful for reporting the measured carbon intensity for a specif ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **location** | **string**| The location name where workflow is run | - **startTime** | **time.Time**| The time at which the workflow we are measuring carbon intensity for started | - **endTime** | **time.Time**| The time at which the workflow we are measuring carbon intensity for ended | +| Name | Type | Description | Notes | +|---------------|---------------------|------------------------------------------------------------------------------|-------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **location** | **string** | The location name where workflow is run | | +| **startTime** | **time.Time** | The time at which the workflow we are measuring carbon intensity for started | | +| **endTime** | **time.Time** | The time at which the workflow we are measuring carbon intensity for ended | | ### Return type @@ -84,10 +84,10 @@ The application only supports batching across a single location with different t ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **optional** | ***CarbonAwareApiGetAverageCarbonIntensityBatchOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|-------------------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **optional** | ***CarbonAwareApiGetAverageCarbonIntensityBatchOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiGetAverageCarbonIntensityBatchOpts struct @@ -116,11 +116,11 @@ Calculate the best emission data by list of locations for a specified time perio ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **location** | [**[]string**](string.md)| String array of named locations | - **optional** | ***CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|---------------------------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **location** | [**[]string**](string.md) | String array of named locations | | +| **optional** | ***CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts struct @@ -153,11 +153,11 @@ This endpoint fetches only the most recently generated forecast for all provided ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **location** | [**[]string**](string.md)| String array of named locations | - **optional** | ***CarbonAwareApiGetCurrentForecastDataOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|-----------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **location** | [**[]string**](string.md) | String array of named locations | | +| **optional** | ***CarbonAwareApiGetCurrentForecastDataOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiGetCurrentForecastDataOpts struct @@ -189,11 +189,11 @@ Calculate the best emission data by location for a specified time period. ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **location** | **string**| String named location. | - **optional** | ***CarbonAwareApiGetEmissionsDataForLocationByTimeOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|----------------------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **location** | **string** | String named location. | | +| **optional** | ***CarbonAwareApiGetEmissionsDataForLocationByTimeOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiGetEmissionsDataForLocationByTimeOpts struct @@ -224,11 +224,11 @@ Calculate the observed emission data by list of locations for a specified time p ### Required Parameters -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **location** | [**[]string**](string.md)| String array of named locations | - **optional** | ***CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts** | optional parameters | nil if no parameters +| Name | Type | Description | Notes | +|--------------|-----------------------------------------------------------|-----------------------------------------------------------------------------|----------------------| +| **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. | | +| **location** | [**[]string**](string.md) | String array of named locations | | +| **optional** | ***CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts** | optional parameters | nil if no parameters | ### Optional Parameters Optional parameters are passed through a pointer to a CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts struct diff --git a/pkg/sdk/client/docs/CarbonIntensityBatchParametersDto.md b/pkg/sdk/client/docs/CarbonIntensityBatchParametersDto.md index bcdc890..b70b620 100644 --- a/pkg/sdk/client/docs/CarbonIntensityBatchParametersDto.md +++ b/pkg/sdk/client/docs/CarbonIntensityBatchParametersDto.md @@ -1,11 +1,11 @@ # CarbonIntensityBatchParametersDto ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Location** | **string** | The location name where workflow is run | [optional] [default to null] -**StartTime** | [**time.Time**](time.Time.md) | The time at which the workflow we are measuring carbon intensity for started | [optional] [default to null] -**EndTime** | [**time.Time**](time.Time.md) | The time at which the workflow we are measuring carbon intensity for ended | [optional] [default to null] +| Name | Type | Description | Notes | +|---------------|-------------------------------|------------------------------------------------------------------------------|------------------------------| +| **Location** | **string** | The location name where workflow is run | [optional] [default to null] | +| **StartTime** | [**time.Time**](time.Time.md) | The time at which the workflow we are measuring carbon intensity for started | [optional] [default to null] | +| **EndTime** | [**time.Time**](time.Time.md) | The time at which the workflow we are measuring carbon intensity for ended | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/CarbonIntensityDto.md b/pkg/sdk/client/docs/CarbonIntensityDto.md index ddd7035..a263ea0 100644 --- a/pkg/sdk/client/docs/CarbonIntensityDto.md +++ b/pkg/sdk/client/docs/CarbonIntensityDto.md @@ -1,12 +1,12 @@ # CarbonIntensityDto ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Location** | **string** | the location name where workflow is run | [optional] [default to null] -**StartTime** | [**time.Time**](time.Time.md) | the time at which the workflow we are measuring carbon intensity for started | [optional] [default to null] -**EndTime** | [**time.Time**](time.Time.md) | the time at which the workflow we are measuring carbon intensity for ended | [optional] [default to null] -**CarbonIntensity** | **float64** | Value of the marginal carbon intensity in grams per kilowatt-hour. | [optional] [default to null] +| Name | Type | Description | Notes | +|---------------------|-------------------------------|------------------------------------------------------------------------------|------------------------------| +| **Location** | **string** | the location name where workflow is run | [optional] [default to null] | +| **StartTime** | [**time.Time**](time.Time.md) | the time at which the workflow we are measuring carbon intensity for started | [optional] [default to null] | +| **EndTime** | [**time.Time**](time.Time.md) | the time at which the workflow we are measuring carbon intensity for ended | [optional] [default to null] | +| **CarbonIntensity** | **float64** | Value of the marginal carbon intensity in grams per kilowatt-hour. | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/EmissionsData.md b/pkg/sdk/client/docs/EmissionsData.md index d26e814..e9479c6 100644 --- a/pkg/sdk/client/docs/EmissionsData.md +++ b/pkg/sdk/client/docs/EmissionsData.md @@ -1,12 +1,12 @@ # EmissionsData ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Location** | **string** | | [optional] [default to null] -**Time** | [**time.Time**](time.Time.md) | | [optional] [default to null] -**Rating** | **float64** | | [optional] [default to null] -**Duration** | **string** | | [optional] [default to null] +| Name | Type | Description | Notes | +|--------------|-------------------------------|-------------|------------------------------| +| **Location** | **string** | | [optional] [default to null] | +| **Time** | [**time.Time**](time.Time.md) | | [optional] [default to null] | +| **Rating** | **float64** | | [optional] [default to null] | +| **Duration** | **string** | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/EmissionsDataDto.md b/pkg/sdk/client/docs/EmissionsDataDto.md index 6856674..3e1a132 100644 --- a/pkg/sdk/client/docs/EmissionsDataDto.md +++ b/pkg/sdk/client/docs/EmissionsDataDto.md @@ -1,12 +1,12 @@ # EmissionsDataDto ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Location** | **string** | | [optional] [default to null] -**Timestamp** | [**time.Time**](time.Time.md) | | [optional] [default to null] -**Duration** | **int32** | | [optional] [default to null] -**Value** | **float64** | | [optional] [default to null] +| Name | Type | Description | Notes | +|---------------|-------------------------------|-------------|------------------------------| +| **Location** | **string** | | [optional] [default to null] | +| **Timestamp** | [**time.Time**](time.Time.md) | | [optional] [default to null] | +| **Duration** | **int32** | | [optional] [default to null] | +| **Value** | **float64** | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/EmissionsForecastBatchParametersDto.md b/pkg/sdk/client/docs/EmissionsForecastBatchParametersDto.md index 27310f6..4b074f3 100644 --- a/pkg/sdk/client/docs/EmissionsForecastBatchParametersDto.md +++ b/pkg/sdk/client/docs/EmissionsForecastBatchParametersDto.md @@ -1,13 +1,13 @@ # EmissionsForecastBatchParametersDto ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**RequestedAt** | [**time.Time**](time.Time.md) | For historical forecast requests, this value is the timestamp used to access the most recently generated forecast as of that time. | [optional] [default to null] -**Location** | **string** | The location of the forecast | [optional] [default to null] -**DataStartAt** | [**time.Time**](time.Time.md) | Start time boundary of forecasted data points.Ignores current forecast data points before this time. Defaults to the earliest time in the forecast data. | [optional] [default to null] -**DataEndAt** | [**time.Time**](time.Time.md) | End time boundary of forecasted data points. Ignores current forecast data points after this time. Defaults to the latest time in the forecast data. | [optional] [default to null] -**WindowSize** | **int32** | The estimated duration (in minutes) of the workload. Defaults to the duration of a single forecast data point. | [optional] [default to null] +| Name | Type | Description | Notes | +|-----------------|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------| +| **RequestedAt** | [**time.Time**](time.Time.md) | For historical forecast requests, this value is the timestamp used to access the most recently generated forecast as of that time. | [optional] [default to null] | +| **Location** | **string** | The location of the forecast | [optional] [default to null] | +| **DataStartAt** | [**time.Time**](time.Time.md) | Start time boundary of forecasted data points.Ignores current forecast data points before this time. Defaults to the earliest time in the forecast data. | [optional] [default to null] | +| **DataEndAt** | [**time.Time**](time.Time.md) | End time boundary of forecasted data points. Ignores current forecast data points after this time. Defaults to the latest time in the forecast data. | [optional] [default to null] | +| **WindowSize** | **int32** | The estimated duration (in minutes) of the workload. Defaults to the duration of a single forecast data point. | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/EmissionsForecastDto.md b/pkg/sdk/client/docs/EmissionsForecastDto.md index 810a005..d8713f7 100644 --- a/pkg/sdk/client/docs/EmissionsForecastDto.md +++ b/pkg/sdk/client/docs/EmissionsForecastDto.md @@ -1,16 +1,16 @@ # EmissionsForecastDto ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**GeneratedAt** | [**time.Time**](time.Time.md) | Timestamp when the forecast was generated. | [optional] [default to null] -**RequestedAt** | [**time.Time**](time.Time.md) | For current requests, this value is the timestamp the request for forecast data was made. For historical forecast requests, this value is the timestamp used to access the most recently generated forecast as of that time. | [optional] [default to null] -**Location** | **string** | The location of the forecast | [optional] [default to null] -**DataStartAt** | [**time.Time**](time.Time.md) | Start time boundary of forecasted data points. Ignores forecast data points before this time. Defaults to the earliest time in the forecast data. | [optional] [default to null] -**DataEndAt** | [**time.Time**](time.Time.md) | End time boundary of forecasted data points. Ignores forecast data points after this time. Defaults to the latest time in the forecast data. | [optional] [default to null] -**WindowSize** | **int32** | The estimated duration (in minutes) of the workload. Defaults to the duration of a single forecast data point. | [optional] [default to null] -**OptimalDataPoints** | [**[]EmissionsDataDto**](EmissionsDataDTO.md) | The optimal forecasted data point within the 'forecastData' array. Null if 'forecastData' array is empty. | [optional] [default to null] -**ForecastData** | [**[]EmissionsDataDto**](EmissionsDataDTO.md) | The forecasted data points transformed and filtered to reflect the specified time and window parameters. Points are ordered chronologically; Empty array if all data points were filtered out. E.G. dataStartAt and dataEndAt times outside the forecast period; windowSize greater than total duration of forecast data; | [optional] [default to null] +| Name | Type | Description | Notes | +|-----------------------|-----------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------| +| **GeneratedAt** | [**time.Time**](time.Time.md) | Timestamp when the forecast was generated. | [optional] [default to null] | +| **RequestedAt** | [**time.Time**](time.Time.md) | For current requests, this value is the timestamp the request for forecast data was made. For historical forecast requests, this value is the timestamp used to access the most recently generated forecast as of that time. | [optional] [default to null] | +| **Location** | **string** | The location of the forecast | [optional] [default to null] | +| **DataStartAt** | [**time.Time**](time.Time.md) | Start time boundary of forecasted data points. Ignores forecast data points before this time. Defaults to the earliest time in the forecast data. | [optional] [default to null] | +| **DataEndAt** | [**time.Time**](time.Time.md) | End time boundary of forecasted data points. Ignores forecast data points after this time. Defaults to the latest time in the forecast data. | [optional] [default to null] | +| **WindowSize** | **int32** | The estimated duration (in minutes) of the workload. Defaults to the duration of a single forecast data point. | [optional] [default to null] | +| **OptimalDataPoints** | [**[]EmissionsDataDto**](EmissionsDataDTO.md) | The optimal forecasted data point within the 'forecastData' array. Null if 'forecastData' array is empty. | [optional] [default to null] | +| **ForecastData** | [**[]EmissionsDataDto**](EmissionsDataDTO.md) | The forecasted data points transformed and filtered to reflect the specified time and window parameters. Points are ordered chronologically; Empty array if all data points were filtered out. E.G. dataStartAt and dataEndAt times outside the forecast period; windowSize greater than total duration of forecast data; | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/Location.md b/pkg/sdk/client/docs/Location.md index 6df026f..c7d3f8b 100644 --- a/pkg/sdk/client/docs/Location.md +++ b/pkg/sdk/client/docs/Location.md @@ -1,11 +1,11 @@ # Location ## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Latitude** | **float64** | | [optional] [default to null] -**Longitude** | **float64** | | [optional] [default to null] -**Name** | **string** | | [optional] [default to null] +| Name | Type | Description | Notes | +|---------------|-------------|-------------|------------------------------| +| **Latitude** | **float64** | | [optional] [default to null] | +| **Longitude** | **float64** | | [optional] [default to null] | +| **Name** | **string** | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/pkg/sdk/client/docs/LocationsApi.md b/pkg/sdk/client/docs/LocationsApi.md index b2be8c1..23ce86a 100644 --- a/pkg/sdk/client/docs/LocationsApi.md +++ b/pkg/sdk/client/docs/LocationsApi.md @@ -2,9 +2,9 @@ All URIs are relative to *https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0* -Method | HTTP request | Description -------------- | ------------- | ------------- -[**GetAllLocations**](LocationsApi.md#GetAllLocations) | **Get** /locations | Get all locations instances +| Method | HTTP request | Description | +|--------------------------------------------------------|--------------------|-----------------------------| +| [**GetAllLocations**](LocationsApi.md#GetAllLocations) | **Get** /locations | Get all locations instances | # **GetAllLocations** > map[string]Location GetAllLocations(ctx, ) diff --git a/pkg/sdk/client/model_carbon_intensity_batch_parameters_dto.go b/pkg/sdk/client/model_carbon_intensity_batch_parameters_dto.go index bdcdebd..e98f416 100644 --- a/pkg/sdk/client/model_carbon_intensity_batch_parameters_dto.go +++ b/pkg/sdk/client/model_carbon_intensity_batch_parameters_dto.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_carbon_intensity_dto.go b/pkg/sdk/client/model_carbon_intensity_dto.go index a86eb19..4ab01d6 100644 --- a/pkg/sdk/client/model_carbon_intensity_dto.go +++ b/pkg/sdk/client/model_carbon_intensity_dto.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_emissions_data.go b/pkg/sdk/client/model_emissions_data.go index 4b5f581..5e10bad 100644 --- a/pkg/sdk/client/model_emissions_data.go +++ b/pkg/sdk/client/model_emissions_data.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_emissions_data_dto.go b/pkg/sdk/client/model_emissions_data_dto.go index 92e3f2e..5f4416b 100644 --- a/pkg/sdk/client/model_emissions_data_dto.go +++ b/pkg/sdk/client/model_emissions_data_dto.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_emissions_forecast_batch_parameters_dto.go b/pkg/sdk/client/model_emissions_forecast_batch_parameters_dto.go index 6ec23fa..7644464 100644 --- a/pkg/sdk/client/model_emissions_forecast_batch_parameters_dto.go +++ b/pkg/sdk/client/model_emissions_forecast_batch_parameters_dto.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_emissions_forecast_dto.go b/pkg/sdk/client/model_emissions_forecast_dto.go index 292f464..bc6818e 100644 --- a/pkg/sdk/client/model_emissions_forecast_dto.go +++ b/pkg/sdk/client/model_emissions_forecast_dto.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( diff --git a/pkg/sdk/client/model_location.go b/pkg/sdk/client/model_location.go index f7d5ee5..e901ff0 100644 --- a/pkg/sdk/client/model_location.go +++ b/pkg/sdk/client/model_location.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client type Location struct { diff --git a/pkg/sdk/client/response.go b/pkg/sdk/client/response.go index d76e7a6..35a83fd 100644 --- a/pkg/sdk/client/response.go +++ b/pkg/sdk/client/response.go @@ -1,11 +1,9 @@ /* * CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - * * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - * * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ + */ package client import ( From fad5d81b92679333c839a778d4a704253702c721 Mon Sep 17 00:00:00 2001 From: Heba Elayoty Date: Mon, 27 Mar 2023 17:01:35 -0700 Subject: [PATCH 2/2] Implement get EmissionsData Signed-off-by: Heba Elayoty --- .github/workflows/create-images.yml | 3 - .github/workflows/e2e-test.yml | 64 +++++++++++++++++++++ cmd/exporter/app/server.go | 9 ++- cmd/exporter/main.go | 6 ++ deploy/carbon-aware.yaml | 62 ++++++++++++++++++++ deploy/exporter.yaml | 11 ---- deploy/server.yaml | 16 ------ docker/server/Dockerfile | 7 ++- pkg/exporter/exporter.go | 89 ++++++++++++++++++++++++----- pkg/sdk/api/swagger.yaml | 5 +- pkg/sdk/client/README.md | 2 +- pkg/sdk/client/api_carbon_aware.go | 58 ++++++++----------- pkg/sdk/client/api_locations.go | 4 +- pkg/sdk/client/client.go | 5 +- pkg/sdk/client/configuration.go | 4 +- 15 files changed, 257 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/e2e-test.yml create mode 100644 deploy/carbon-aware.yaml delete mode 100644 deploy/exporter.yaml delete mode 100644 deploy/server.yaml diff --git a/.github/workflows/create-images.yml b/.github/workflows/create-images.yml index 3be72bf..27ffd9c 100644 --- a/.github/workflows/create-images.yml +++ b/.github/workflows/create-images.yml @@ -3,9 +3,6 @@ on: push: branches: - main - pull_request: - branches: - - main permissions: contents: write packages: write diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml new file mode 100644 index 0000000..c3e1800 --- /dev/null +++ b/.github/workflows/e2e-test.yml @@ -0,0 +1,64 @@ +name: Run e2e test +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + REGISTRY: ghcr.io + # Common versions + GO_VERSION: '1.19' + + SERVER_IMG_TAG : '0.1.0' + EXPORTER_IMG_TAG: '0.1.0' + +jobs: + export-registry: + runs-on: ubuntu-20.04 + outputs: + registry: ${{ steps.export.outputs.registry }} + steps: + - id: export + run: | + # registry must be in lowercase + echo "registry=$(echo "${{ env.REGISTRY }}/${{ github.repository }}" | tr [:upper:] [:lower:])" >> $GITHUB_OUTPUT + + e2e-test: + runs-on: ubuntu-20.04 + needs: + - export-registry + env: + REGISTRY: ${{ needs.export-registry.outputs.registry }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 0 + - name: Login to ${{ env.REGISTRY }} + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: install kubectl + uses: azure/setup-kubectl@v3 + - name: Create k8s Kind Cluster + uses: helm/kind-action@v1.4.0 + with: + cluster_name: "carbon" + - name: Run e2e test + run: | + make docker-build-server-image docker-build-exporter-image + kind load docker-image -n carbon ${{ env.REGISTRY }}/server:${{ env.SERVER_IMG_TAG }} + kind load docker-image -n carbon ${{ env.REGISTRY }}/exporter:${{ env.EXPORTER_IMG_TAG }} + kubectl apply -f deploy/carbon-aware.yaml + sleep 20 + kubectl wait --for=condition=available deploy carbon-aware --timeout=300s + sleep 20 + kubectl logs $(echo $(kubectl get pods --output=jsonpath={.items..metadata.name})) -c carbon-data-exporter + env: + SERVER_IMG_TAG: ${{ env.SERVER_IMG_TAG }} + EXPORTER_IMG_TAG: ${{ env.EXPORTER_IMG_TAG }} diff --git a/cmd/exporter/app/server.go b/cmd/exporter/app/server.go index 28d47ed..97d4cdf 100644 --- a/cmd/exporter/app/server.go +++ b/cmd/exporter/app/server.go @@ -1,3 +1,7 @@ +/* +MIT License +Copyright (c) Microsoft Corporation. +*/ package app import ( @@ -7,6 +11,7 @@ import ( _ "net/http/pprof" // enable pprof in the server "os" + "github.com/Azure/kubernetes-carbon-intensity-exporter/pkg/sdk/client" "github.com/spf13/cobra" "k8s.io/apiserver/pkg/server/healthz" v1core "k8s.io/client-go/kubernetes/typed/core/v1" @@ -72,7 +77,9 @@ func NewExporterCommand(stopChan <-chan struct{}) *cobra.Command { } func Run(cc *exporterconfig.CompletedConfig, stopCh <-chan struct{}) error { - p, err := exporter.New(cc.ClusterClient, cc.Recorder) + + apiClient := client.NewAPIClient(client.NewConfiguration()) + p, err := exporter.New(cc.ClusterClient, apiClient, cc.Recorder) if err != nil { return fmt.Errorf("new syncer: %v", err) diff --git a/cmd/exporter/main.go b/cmd/exporter/main.go index 3ffe9e5..6f4a851 100644 --- a/cmd/exporter/main.go +++ b/cmd/exporter/main.go @@ -1,3 +1,7 @@ +/* +MIT License +Copyright (c) Microsoft Corporation. +*/ package main import ( @@ -23,6 +27,8 @@ func mainMethod() error { } func main() { + + time.Sleep(10 * time.Second) if mainMethod() != nil { os.Exit(1) } diff --git a/deploy/carbon-aware.yaml b/deploy/carbon-aware.yaml new file mode 100644 index 0000000..f92e436 --- /dev/null +++ b/deploy/carbon-aware.yaml @@ -0,0 +1,62 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: carbon-aware-sa +--- +apiVersion: "rbac.authorization.k8s.io/v1" +kind: ClusterRoleBinding +metadata: + name: carbon-aware-binding +subjects: + - kind: ServiceAccount + name: carbon-aware-sa + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: carbon-aware + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: carbon-aware + template: + metadata: + labels: + app: carbon-aware + spec: + serviceAccountName: carbon-aware-sa + containers: + - name: api-server + image: ghcr.io/azure/kubernetes-carbon-intensity-exporter/server:0.1.0 + imagePullPolicy: IfNotPresent + command: + - sh + - -c + - cd /app && sed "s/username/wibuchan/" -i appsettings.json && sed "s/password/greenAI/" -i appsettings.json && dotnet CarbonAware.WebApi.dll + ports: + - name: api-server-port + containerPort: 7031 + - name: carbon-data-exporter + image: ghcr.io/azure/kubernetes-carbon-intensity-exporter/exporter:0.1.0 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9090 +--- +apiVersion: v1 +kind: Service +metadata: + name: api-server-svc +spec: + selector: + app: carbon-aware + ports: + - protocol: TCP + port: 80 + targetPort: api-server-port diff --git a/deploy/exporter.yaml b/deploy/exporter.yaml deleted file mode 100644 index 067222e..0000000 --- a/deploy/exporter.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: keda-carbon-exporter -spec: - containers: - - name: exporter - image: ghcr.io/azure/kubernetes-carbon-intensity-exporter/exporter:0.1.0 - imagePullPolicy: Always - ports: - - containerPort: 7031 diff --git a/deploy/server.yaml b/deploy/server.yaml deleted file mode 100644 index f989521..0000000 --- a/deploy/server.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: server -spec: - containers: - - name: server - image: ghcr.io/azure/kubernetes-carbon-intensity-exporter/server:0.1.0 - imagePullPolicy: Always - command: [ - "sh", - "-c", - "cd /app && sed \"s/username/wibuchan/g\" -i appsettings.json && sed \"s/password/greenAI/g\" -i appsettings.json && dotnet CarbonAware.WebApi.dll", - ] - ports: - - containerPort: 7031 diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index a28eeae..a493660 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -2,9 +2,14 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env WORKDIR /app # Copy everything from source -RUN git clone https://github.com/helayoty/carbon-aware-sdk.git && cd carbon-aware-sdk && git checkout 159f99c +RUN git clone https://github.com/helayoty/carbon-aware-sdk.git && cd carbon-aware-sdk && git checkout 70568de # Use implicit restore to build and publish RUN dotnet publish carbon-aware-sdk/src/CarbonAware.WebApi/src/CarbonAware.WebApi.csproj -c Release -o publish +# Generate OpenAPI spec +WORKDIR carbon-aware-sdk/src/CarbonAware.WebApi/src +RUN dotnet tool restore && \ + mkdir -p /app/publish/wwwroot/api/v1 && \ + dotnet tool run swagger tofile --output /app/publish/wwwroot/api/v1/swagger.yaml --yaml /app/publish/CarbonAware.WebApi.dll v1 # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:6.0 diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 8a57993..8e349eb 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -1,12 +1,20 @@ +/* +MIT License +Copyright (c) Microsoft Corporation. +*/ package exporter import ( "time" + "github.com/Azure/kubernetes-carbon-intensity-exporter/pkg/sdk/client" + "github.com/antihax/optional" + "golang.org/x/net/context" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/record" + "k8s.io/klog/v2" ) const ( @@ -16,32 +24,87 @@ const ( type Exporter struct { clusterClient clientset.Interface - - recorder record.EventRecorder + apiClient *client.APIClient + recorder record.EventRecorder } -func New(clusterClient clientset.Interface, recorder record.EventRecorder) (*Exporter, error) { +func New(clusterClient clientset.Interface, apiClient *client.APIClient, recorder record.EventRecorder) (*Exporter, error) { b := &Exporter{ clusterClient: clusterClient, + apiClient: apiClient, recorder: recorder, } return b, nil } -func (b *Exporter) Run(stopChan <-chan struct{}) { - go wait.Until(b.Patrol, patrolInterval, stopChan) +func (e *Exporter) Run(stopChan <-chan struct{}) { + go wait.Until(e.Patrol, patrolInterval, stopChan) } -func (b *Exporter) Patrol() { - - /* - Calling SDK to get 24 hours foreceast data, - */ - - b.recorder.Eventf(&corev1.ObjectReference{ +func (e *Exporter) Patrol() { + ctx := context.Background() + //e.getEmissionData(ctx, "eastus") + e.getCarbonIntensity(ctx, "eastus") + e.getCurrentForecastData(ctx, []string{"eastus"}) + e.recorder.Eventf(&corev1.ObjectReference{ Kind: "Pod", - Namespace: "kube-system", + Namespace: "", Name: "carbon-data-exporter", // TODO: replace this with the actual Pod name, passed through the downward API. }, corev1.EventTypeNormal, "Exporter results", "Done retrieve data") } + +func (e *Exporter) getEmissionData(ctx context.Context, region string) { + opt := &client.CarbonAwareApiGetEmissionsDataForLocationByTimeOpts{ + StartTime: optional.NewTime(time.Now().AddDate(0, 0, -1)), + EndTime: optional.NewTime(time.Now()), + } + emissionsData, _, err := e.apiClient.CarbonAwareApi.GetEmissionsDataForLocationByTime(ctx, + region, opt) + if err != nil { + klog.ErrorS(err, "error while getting emissions data") + return + } + + klog.Infof("emissionsData for %s region is: \n", region) + for i := range emissionsData { + index := i + index++ + klog.Infof("%d. Location: %s {Time: %s, Duration: %s, Rating: %f}\n", + index, emissionsData[i].Location, emissionsData[i].Time.String(), emissionsData[i].Duration, emissionsData[i].Rating) + } +} + +func (e *Exporter) getCarbonIntensity(ctx context.Context, region string) { + intensity, _, err := e.apiClient.CarbonAwareApi.GetAverageCarbonIntensity(ctx, + region, + time.Now().AddDate(0, 0, -1), + time.Now()) + if err != nil { + klog.ErrorS(err, "error while getting carbon intensity") + return + } + + klog.Infof("carbon intensity for %s region is %f", region, intensity.CarbonIntensity) +} + +func (e *Exporter) getCurrentForecastData(ctx context.Context, region []string) { + opt := &client.CarbonAwareApiGetCurrentForecastDataOpts{ + DataStartAt: optional.EmptyTime(), + DataEndAt: optional.EmptyTime(), + } + forecast, _, err := e.apiClient.CarbonAwareApi.GetCurrentForecastData(ctx, + region, opt) + if err != nil { + klog.ErrorS(err, "error while getting current forecast data") + return + } + + klog.Infof("current forecast data for %s region is: \n", region) + for i := range forecast { + index := i + index++ + klog.Infof("%d. Location: %s {DataStartAt: %s, DataEndAt: %s, ForecastData: %v, OptimalDataPoints: %v}\n", + index, forecast[i].Location, forecast[i].DataStartAt.String(), forecast[i].DataEndAt.String(), forecast[i].ForecastData, forecast[i].OptimalDataPoints) + } +} diff --git a/pkg/sdk/api/swagger.yaml b/pkg/sdk/api/swagger.yaml index 62aa102..9318a12 100644 --- a/pkg/sdk/api/swagger.yaml +++ b/pkg/sdk/api/swagger.yaml @@ -3,9 +3,8 @@ info: title: "CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" version: "1.0" servers: -- url: https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0 - description: SwaggerHub API Auto Mocking -- url: https://carbonaware.swagger.io/v2 +- url: http://api-server-svc.default.svc.cluster.local + description: API Server URL paths: /emissions/bylocations/best: get: diff --git a/pkg/sdk/client/README.md b/pkg/sdk/client/README.md index 01afaf2..c59a8d7 100644 --- a/pkg/sdk/client/README.md +++ b/pkg/sdk/client/README.md @@ -12,7 +12,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge ## Installation Put the package under your project folder and add the following in import: ```golang -import "./client" +import "github.com/Azure/kubernetes-carbon-intensity-exporter/pkg/sdk/client" ``` ## Documentation for API Endpoints diff --git a/pkg/sdk/client/api_carbon_aware.go b/pkg/sdk/client/api_carbon_aware.go index 3a99074..bc617cc 100644 --- a/pkg/sdk/client/api_carbon_aware.go +++ b/pkg/sdk/client/api_carbon_aware.go @@ -8,7 +8,7 @@ package client import ( "context" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -20,6 +20,8 @@ import ( // Linger please var ( _ context.Context + // to determine the Accept header + localVarHttpHeaderAccepts = []string{"application/json", "application/json; charset=utf-8", "application/problem+json; charset=utf-8"} ) type CarbonAwareApiService service @@ -62,9 +64,6 @@ func (a *CarbonAwareApiService) BatchForecastDataAsync(ctx context.Context, loca localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -86,7 +85,7 @@ func (a *CarbonAwareApiService) BatchForecastDataAsync(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -168,8 +167,12 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, l localVarFormParams := url.Values{} localVarQueryParams.Add("location", parameterToString(location, "")) - localVarQueryParams.Add("startTime", parameterToString(startTime, "")) - localVarQueryParams.Add("endTime", parameterToString(endTime, "")) + + cutStartDate, _, _ := strings.Cut(parameterToString(startTime, ""), " ") + localVarQueryParams.Add("startTime", cutStartDate) + + cutEndDate, _, _ := strings.Cut(parameterToString(endTime, ""), " ") + localVarQueryParams.Add("endTime", cutEndDate) // to determine the Content-Type header localVarHttpContentTypes := []string{} @@ -179,9 +182,6 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, l localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -197,7 +197,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, l return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -290,9 +290,6 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensityBatch(ctx context.Conte localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -314,7 +311,7 @@ func (a *CarbonAwareApiService) GetAverageCarbonIntensityBatch(ctx context.Conte return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -416,9 +413,6 @@ func (a *CarbonAwareApiService) GetBestEmissionsDataForLocationsByTime(ctx conte localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -434,7 +428,7 @@ func (a *CarbonAwareApiService) GetBestEmissionsDataForLocationsByTime(ctx conte return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -513,12 +507,14 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca localVarQueryParams := url.Values{} localVarFormParams := url.Values{} - localVarQueryParams.Add("location", parameterToString(location, "multi")) + localVarQueryParams.Add("location", parameterToString(location, "")) if localVarOptionals != nil && localVarOptionals.DataStartAt.IsSet() { - localVarQueryParams.Add("dataStartAt", parameterToString(localVarOptionals.DataStartAt.Value(), "")) + cutDate, _, _ := strings.Cut(parameterToString(localVarOptionals.DataStartAt.Value(), ""), "UTC") + localVarQueryParams.Add("dataStartAt", cutDate) } if localVarOptionals != nil && localVarOptionals.DataEndAt.IsSet() { - localVarQueryParams.Add("dataEndAt", parameterToString(localVarOptionals.DataEndAt.Value(), "")) + cutDate, _, _ := strings.Cut(parameterToString(localVarOptionals.DataEndAt.Value(), ""), "UTC") + localVarQueryParams.Add("dataEndAt", cutDate) } if localVarOptionals != nil && localVarOptionals.WindowSize.IsSet() { localVarQueryParams.Add("windowSize", parameterToString(localVarOptionals.WindowSize.Value(), "")) @@ -532,9 +528,6 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -550,7 +543,7 @@ func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -648,10 +641,12 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationByTime(ctx context.Co localVarQueryParams.Add("location", parameterToString(location, "")) if localVarOptionals != nil && localVarOptionals.StartTime.IsSet() { - localVarQueryParams.Add("startTime", parameterToString(localVarOptionals.StartTime.Value(), "")) + cutDate, _, _ := strings.Cut(parameterToString(localVarOptionals.StartTime.Value(), ""), "UTC") + localVarQueryParams.Add("startTime", cutDate) } if localVarOptionals != nil && localVarOptionals.EndTime.IsSet() { - localVarQueryParams.Add("endTime", parameterToString(localVarOptionals.EndTime.Value(), "")) + cutDate, _, _ := strings.Cut(parameterToString(localVarOptionals.EndTime.Value(), ""), "UTC") + localVarQueryParams.Add("endTime", cutDate) } // to determine the Content-Type header localVarHttpContentTypes := []string{} @@ -662,9 +657,6 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationByTime(ctx context.Co localVarHeaderParams["Content-Type"] = localVarHttpContentType } - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "application/json; charset=utf-8"} - // set Accept header localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) if localVarHttpHeaderAccept != "" { @@ -680,7 +672,7 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationByTime(ctx context.Co return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err @@ -790,7 +782,7 @@ func (a *CarbonAwareApiService) GetEmissionsDataForLocationsByTime(ctx context.C return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err diff --git a/pkg/sdk/client/api_locations.go b/pkg/sdk/client/api_locations.go index cfa54a1..d2fa1ac 100644 --- a/pkg/sdk/client/api_locations.go +++ b/pkg/sdk/client/api_locations.go @@ -8,7 +8,7 @@ package client import ( "context" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -69,7 +69,7 @@ func (a *LocationsApiService) GetAllLocations(ctx context.Context) (map[string]L return localVarReturnValue, localVarHttpResponse, err } - localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarBody, err := io.ReadAll(localVarHttpResponse.Body) localVarHttpResponse.Body.Close() if err != nil { return localVarReturnValue, localVarHttpResponse, err diff --git a/pkg/sdk/client/client.go b/pkg/sdk/client/client.go index 1c22122..90d0f26 100644 --- a/pkg/sdk/client/client.go +++ b/pkg/sdk/client/client.go @@ -137,7 +137,8 @@ func parameterToString(obj interface{}, collectionFormat string) string { } if reflect.TypeOf(obj).Kind() == reflect.Slice { - return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + replacedStr := strings.Replace(fmt.Sprint(obj), " ", delimiter, -1) + return strings.Replace(strings.Trim(replacedStr, "[]"), " ", delimiter, -1) } return fmt.Sprintf("%v", obj) @@ -315,7 +316,7 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err return err } return nil - } else if strings.Contains(contentType, "application/json") { + } else if strings.Contains(contentType, "application/json") || strings.Contains(contentType, "application/problem+json") { if err = json.Unmarshal(b, v); err != nil { return err } diff --git a/pkg/sdk/client/configuration.go b/pkg/sdk/client/configuration.go index 8bf6af0..2333d1a 100644 --- a/pkg/sdk/client/configuration.go +++ b/pkg/sdk/client/configuration.go @@ -57,9 +57,9 @@ type Configuration struct { func NewConfiguration() *Configuration { cfg := &Configuration{ - BasePath: "https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0", + BasePath: "http://api-server-svc.default.svc.cluster.local", DefaultHeader: make(map[string]string), - UserAgent: "Swagger-Codegen/1.0.0/go", + UserAgent: "KEDA/carbon-exporter", } return cfg }