refactor state to recorder, finish implementing

This commit is contained in:
2025-03-21 09:22:32 -04:00
parent a5948cf334
commit 42eea2346b
7 changed files with 89 additions and 56 deletions

20
main.go
View File

@@ -9,19 +9,16 @@ import (
grpcopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
"golang.org/x/sys/unix"
"k8s.io/utils/ptr"
weatherpb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/ambienthttp"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
weathergrpc "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/grpc"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/state"
)
const (
defaultMetricPrefix = "weather"
defaultUpdatesToKeep = 120
defaultMetricPrefix = "weather"
)
func main() {
@@ -48,11 +45,6 @@ func main() {
}
func prepareApp(ctx context.Context, aw *ambient.AmbientWeather) *app.App {
// Config updates / defaults
if aw.Config.UpdatesToKeep == nil || *aw.Config.UpdatesToKeep < 1 {
aw.Config.UpdatesToKeep = ptr.To(defaultUpdatesToKeep)
}
// Load ambient routes into app
awApp := &app.App{
AppContext: ctx,
@@ -88,13 +80,9 @@ func prepareApp(ctx context.Context, aw *ambient.AmbientWeather) *app.App {
GRPC: &grpcopts.AppGRPC{
Services: []*grpcopts.GRPCService{
{
Name: "Weather Service",
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
Service: weathergrpc.NewGRPCWeather(ctx, state.NewWeatherState(
&state.Opts{
Ctx: ctx,
KeepLast: *aw.Config.UpdatesToKeep,
})),
Name: "Weather Service",
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
Service: weathergrpc.NewGRPCWeather(ctx, aw.GetState()),
},
},
},