Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
f079d106a1 | |||
fc2d05e957 | |||
59f5bfbba1 | |||
0adab13221 | |||
3b0748da25 | |||
2d683e61b0 | |||
82bc3acfc3 | |||
6e1ec0b5c1 | |||
46a213f314 | |||
b483fc22a3 | |||
fb6941e6bd |
3
Makefile
3
Makefile
@ -33,6 +33,9 @@ build: test
|
|||||||
done
|
done
|
||||||
go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o bin/${CMD_NAME}
|
go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o bin/${CMD_NAME}
|
||||||
|
|
||||||
|
schema:
|
||||||
|
go run . -schema > contrib/schema.json
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
@echo "Building Docker image $(DOCKER_IMG):$(VERSION)"
|
@echo "Building Docker image $(DOCKER_IMG):$(VERSION)"
|
||||||
docker build \
|
docker build \
|
||||||
|
10
TODO.md
10
TODO.md
@ -1,10 +1,16 @@
|
|||||||
|
# Issues
|
||||||
|
- [x] Redis recorder panic
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] Finish implementing weather GRPC
|
- [ ] Add json schema to CI and README
|
||||||
- [ ] Update README
|
- [ ] Update README
|
||||||
- [ ] Add Grafana dashboard
|
- [ ] Add Grafana dashboard
|
||||||
- [ ] Add new spans
|
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
- [x] Stop Marshaling sensors / batteries with no data
|
||||||
|
- [x] Finish implementing weather GRPC
|
||||||
|
- [x] Add json schema for config
|
||||||
|
- [x] Add new spans
|
||||||
- [x] Helm Chart
|
- [x] Helm Chart
|
||||||
- [x] Add proxy to upstream support
|
- [x] Add proxy to upstream support
|
||||||
- [x] Fix wunderground 401
|
- [x] Fix wunderground 401
|
||||||
|
@ -207,6 +207,7 @@ type WeatherUpdate struct {
|
|||||||
DewPointF *float64 `protobuf:"fixed64,25,opt,name=dew_point_f,json=dewPointF,proto3,oneof" json:"dew_point_f,omitempty"`
|
DewPointF *float64 `protobuf:"fixed64,25,opt,name=dew_point_f,json=dewPointF,proto3,oneof" json:"dew_point_f,omitempty"`
|
||||||
WindChillF *float64 `protobuf:"fixed64,26,opt,name=wind_chill_f,json=windChillF,proto3,oneof" json:"wind_chill_f,omitempty"`
|
WindChillF *float64 `protobuf:"fixed64,26,opt,name=wind_chill_f,json=windChillF,proto3,oneof" json:"wind_chill_f,omitempty"`
|
||||||
TempHumiditySensors []*TempHumiditySensor `protobuf:"bytes,27,rep,name=temp_humidity_sensors,json=tempHumiditySensors,proto3" json:"temp_humidity_sensors,omitempty"`
|
TempHumiditySensors []*TempHumiditySensor `protobuf:"bytes,27,rep,name=temp_humidity_sensors,json=tempHumiditySensors,proto3" json:"temp_humidity_sensors,omitempty"`
|
||||||
|
UpdateTimestamp *timestamppb.Timestamp `protobuf:"bytes,28,opt,name=update_timestamp,json=updateTimestamp,proto3" json:"update_timestamp,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -430,6 +431,13 @@ func (x *WeatherUpdate) GetTempHumiditySensors() []*TempHumiditySensor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *WeatherUpdate) GetUpdateTimestamp() *timestamppb.Timestamp {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdateTimestamp
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Represents a temperature and humidity sensor
|
// Represents a temperature and humidity sensor
|
||||||
type TempHumiditySensor struct {
|
type TempHumiditySensor struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
@ -576,7 +584,7 @@ var file_weather_weather_proto_rawDesc = string([]byte{
|
|||||||
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0b, 0x73, 0x74, 0x61, 0x74,
|
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0b, 0x73, 0x74, 0x61, 0x74,
|
||||||
0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x73,
|
0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x73,
|
||||||
0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0f, 0x0a, 0x0d, 0x5f,
|
0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0f, 0x0a, 0x0d, 0x5f,
|
||||||
0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x22, 0xb7, 0x0c, 0x0a,
|
0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x22, 0xfe, 0x0c, 0x0a,
|
||||||
0x0d, 0x57, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x21,
|
0x0d, 0x57, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x21,
|
||||||
0x0a, 0x0c, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
|
0x0a, 0x0c, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4e, 0x61, 0x6d,
|
0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4e, 0x61, 0x6d,
|
||||||
@ -651,51 +659,56 @@ var file_weather_weather_proto_rawDesc = string([]byte{
|
|||||||
0x65, 0x6e, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x2e, 0x54, 0x65, 0x6d, 0x70,
|
0x65, 0x6e, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x2e, 0x54, 0x65, 0x6d, 0x70,
|
||||||
0x48, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x52, 0x13,
|
0x48, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x52, 0x13,
|
||||||
0x74, 0x65, 0x6d, 0x70, 0x48, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e, 0x73,
|
0x74, 0x65, 0x6d, 0x70, 0x48, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e, 0x73,
|
||||||
0x6f, 0x72, 0x73, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x6f, 0x75, 0x74,
|
0x6f, 0x72, 0x73, 0x12, 0x45, 0x0a, 0x10, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69,
|
||||||
0x64, 0x6f, 0x6f, 0x72, 0x5f, 0x66, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f,
|
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x1c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e,
|
||||||
0x69, 0x6e, 0x64, 0x6f, 0x6f, 0x72, 0x5f, 0x66, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x68, 0x75, 0x6d,
|
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
||||||
0x69, 0x64, 0x69, 0x74, 0x79, 0x5f, 0x6f, 0x75, 0x74, 0x64, 0x6f, 0x6f, 0x72, 0x42, 0x12, 0x0a,
|
0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0f, 0x75, 0x70, 0x64, 0x61, 0x74,
|
||||||
0x10, 0x5f, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x5f, 0x69, 0x6e, 0x64, 0x6f, 0x6f,
|
0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x74,
|
||||||
0x72, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x73, 0x70, 0x65, 0x65, 0x64,
|
0x65, 0x6d, 0x70, 0x5f, 0x6f, 0x75, 0x74, 0x64, 0x6f, 0x6f, 0x72, 0x5f, 0x66, 0x42, 0x10, 0x0a,
|
||||||
0x5f, 0x6d, 0x70, 0x68, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x67, 0x75,
|
0x0e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x69, 0x6e, 0x64, 0x6f, 0x6f, 0x72, 0x5f, 0x66, 0x42,
|
||||||
0x73, 0x74, 0x5f, 0x6d, 0x70, 0x68, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x64,
|
0x13, 0x0a, 0x11, 0x5f, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x5f, 0x6f, 0x75, 0x74,
|
||||||
0x61, 0x69, 0x6c, 0x79, 0x5f, 0x67, 0x75, 0x73, 0x74, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x77, 0x69,
|
0x64, 0x6f, 0x6f, 0x72, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74,
|
||||||
0x6e, 0x64, 0x5f, 0x64, 0x69, 0x72, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f,
|
0x79, 0x5f, 0x69, 0x6e, 0x64, 0x6f, 0x6f, 0x72, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x77, 0x69, 0x6e,
|
||||||
0x64, 0x69, 0x72, 0x5f, 0x61, 0x76, 0x67, 0x5f, 0x31, 0x30, 0x6d, 0x42, 0x05, 0x0a, 0x03, 0x5f,
|
0x64, 0x5f, 0x73, 0x70, 0x65, 0x65, 0x64, 0x5f, 0x6d, 0x70, 0x68, 0x42, 0x10, 0x0a, 0x0e, 0x5f,
|
||||||
0x75, 0x76, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x73, 0x6f, 0x6c, 0x61, 0x72, 0x5f, 0x72, 0x61, 0x64,
|
0x77, 0x69, 0x6e, 0x64, 0x5f, 0x67, 0x75, 0x73, 0x74, 0x5f, 0x6d, 0x70, 0x68, 0x42, 0x11, 0x0a,
|
||||||
0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x68, 0x6f, 0x75, 0x72, 0x6c,
|
0x0f, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x64, 0x61, 0x69, 0x6c, 0x79, 0x5f, 0x67, 0x75, 0x73, 0x74,
|
||||||
0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x65, 0x76,
|
0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x64, 0x69, 0x72, 0x42, 0x13, 0x0a,
|
||||||
0x65, 0x6e, 0x74, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x10, 0x0a, 0x0e, 0x5f,
|
0x11, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x64, 0x69, 0x72, 0x5f, 0x61, 0x76, 0x67, 0x5f, 0x31,
|
||||||
0x64, 0x61, 0x69, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x11, 0x0a,
|
0x30, 0x6d, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x75, 0x76, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x73, 0x6f,
|
||||||
0x0f, 0x5f, 0x77, 0x65, 0x65, 0x6b, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e,
|
0x6c, 0x61, 0x72, 0x5f, 0x72, 0x61, 0x64, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x11, 0x0a,
|
||||||
0x42, 0x12, 0x0a, 0x10, 0x5f, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69,
|
0x0f, 0x5f, 0x68, 0x6f, 0x75, 0x72, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e,
|
||||||
0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x79, 0x65, 0x61, 0x72, 0x6c, 0x79, 0x5f,
|
0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f,
|
||||||
0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x74, 0x6f, 0x74, 0x61,
|
0x69, 0x6e, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x64, 0x61, 0x69, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69,
|
||||||
0x6c, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x14, 0x0a, 0x12, 0x5f, 0x62, 0x61,
|
0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x77, 0x65, 0x65, 0x6b, 0x6c, 0x79, 0x5f,
|
||||||
0x72, 0x6f, 0x6d, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x69, 0x6e, 0x42,
|
0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x6d, 0x6f, 0x6e, 0x74,
|
||||||
0x14, 0x0a, 0x12, 0x5f, 0x62, 0x61, 0x72, 0x6f, 0x6d, 0x5f, 0x61, 0x62, 0x73, 0x6f, 0x6c, 0x75,
|
0x68, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x11, 0x0a, 0x0f, 0x5f,
|
||||||
0x74, 0x65, 0x5f, 0x69, 0x6e, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x64, 0x65, 0x77, 0x5f, 0x70, 0x6f,
|
0x79, 0x65, 0x61, 0x72, 0x6c, 0x79, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x42, 0x10,
|
||||||
0x69, 0x6e, 0x74, 0x5f, 0x66, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x63,
|
0x0a, 0x0e, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x72, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e,
|
||||||
0x68, 0x69, 0x6c, 0x6c, 0x5f, 0x66, 0x22, 0x7d, 0x0a, 0x12, 0x54, 0x65, 0x6d, 0x70, 0x48, 0x75,
|
0x42, 0x14, 0x0a, 0x12, 0x5f, 0x62, 0x61, 0x72, 0x6f, 0x6d, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74,
|
||||||
0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x12, 0x12, 0x0a, 0x04,
|
0x69, 0x76, 0x65, 0x5f, 0x69, 0x6e, 0x42, 0x14, 0x0a, 0x12, 0x5f, 0x62, 0x61, 0x72, 0x6f, 0x6d,
|
||||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
0x5f, 0x61, 0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x5f, 0x69, 0x6e, 0x42, 0x0e, 0x0a, 0x0c,
|
||||||
0x12, 0x1a, 0x0a, 0x06, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01,
|
0x5f, 0x64, 0x65, 0x77, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x66, 0x42, 0x0f, 0x0a, 0x0d,
|
||||||
0x48, 0x00, 0x52, 0x05, 0x74, 0x65, 0x6d, 0x70, 0x46, 0x88, 0x01, 0x01, 0x12, 0x1f, 0x0a, 0x08,
|
0x5f, 0x77, 0x69, 0x6e, 0x64, 0x5f, 0x63, 0x68, 0x69, 0x6c, 0x6c, 0x5f, 0x66, 0x22, 0x7d, 0x0a,
|
||||||
0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x48, 0x01,
|
0x12, 0x54, 0x65, 0x6d, 0x70, 0x48, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x53, 0x65, 0x6e,
|
||||||
0x52, 0x08, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x42, 0x09, 0x0a,
|
0x73, 0x6f, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x07, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x66, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x68, 0x75, 0x6d,
|
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x06, 0x74, 0x65, 0x6d, 0x70, 0x5f,
|
||||||
0x69, 0x64, 0x69, 0x74, 0x79, 0x22, 0x55, 0x0a, 0x0d, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79,
|
0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x48, 0x00, 0x52, 0x05, 0x74, 0x65, 0x6d, 0x70, 0x46,
|
||||||
0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e,
|
0x88, 0x01, 0x01, 0x12, 0x1f, 0x0a, 0x08, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x18,
|
||||||
0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f,
|
0x03, 0x20, 0x01, 0x28, 0x05, 0x48, 0x01, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74,
|
||||||
0x6e, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02,
|
0x79, 0x88, 0x01, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x5f, 0x66, 0x42,
|
||||||
0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x88, 0x01,
|
0x0b, 0x0a, 0x09, 0x5f, 0x68, 0x75, 0x6d, 0x69, 0x64, 0x69, 0x74, 0x79, 0x22, 0x55, 0x0a, 0x0d,
|
||||||
0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x54, 0x5a, 0x52,
|
0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1c, 0x0a,
|
||||||
0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x65, 0x74, 0x65, 0x63, 0x68, 0x63,
|
0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6d,
|
0x52, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x73,
|
||||||
0x63, 0x67, 0x75, 0x69, 0x72, 0x65, 0x2f, 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x6c,
|
0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x06, 0x73,
|
||||||
0x6f, 0x63, 0x61, 0x6c, 0x2d, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2f, 0x61, 0x70,
|
0x74, 0x61, 0x74, 0x75, 0x73, 0x88, 0x01, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x73, 0x74, 0x61,
|
||||||
0x69, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x77, 0x65, 0x61, 0x74, 0x68,
|
0x74, 0x75, 0x73, 0x42, 0x54, 0x5a, 0x52, 0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x6c, 0x69, 0x62,
|
||||||
0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x72, 0x65, 0x74, 0x65, 0x63, 0x68, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x74, 0x69, 0x6e, 0x67,
|
||||||
|
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6d, 0x63, 0x67, 0x75, 0x69, 0x72, 0x65, 0x2f, 0x61, 0x6d,
|
||||||
|
0x62, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2d, 0x65, 0x78, 0x70, 0x6f,
|
||||||
|
0x72, 0x74, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61,
|
||||||
|
0x31, 0x2f, 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x33,
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -726,11 +739,12 @@ var file_weather_weather_proto_depIdxs = []int32{
|
|||||||
3, // 2: ambient.weather.GetWeatherResponse.weather_updates:type_name -> ambient.weather.WeatherUpdate
|
3, // 2: ambient.weather.GetWeatherResponse.weather_updates:type_name -> ambient.weather.WeatherUpdate
|
||||||
5, // 3: ambient.weather.WeatherUpdate.batteries:type_name -> ambient.weather.BatteryStatus
|
5, // 3: ambient.weather.WeatherUpdate.batteries:type_name -> ambient.weather.BatteryStatus
|
||||||
4, // 4: ambient.weather.WeatherUpdate.temp_humidity_sensors:type_name -> ambient.weather.TempHumiditySensor
|
4, // 4: ambient.weather.WeatherUpdate.temp_humidity_sensors:type_name -> ambient.weather.TempHumiditySensor
|
||||||
5, // [5:5] is the sub-list for method output_type
|
6, // 5: ambient.weather.WeatherUpdate.update_timestamp:type_name -> google.protobuf.Timestamp
|
||||||
5, // [5:5] is the sub-list for method input_type
|
6, // [6:6] is the sub-list for method output_type
|
||||||
5, // [5:5] is the sub-list for extension type_name
|
6, // [6:6] is the sub-list for method input_type
|
||||||
5, // [5:5] is the sub-list for extension extendee
|
6, // [6:6] is the sub-list for extension type_name
|
||||||
0, // [0:5] is the sub-list for field type_name
|
6, // [6:6] is the sub-list for extension extendee
|
||||||
|
0, // [0:6] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_weather_weather_proto_init() }
|
func init() { file_weather_weather_proto_init() }
|
||||||
|
61
app.go
Normal file
61
app.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
||||||
|
grpcopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
||||||
|
httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||||
|
|
||||||
|
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"
|
||||||
|
weathergrpc "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func prepareApp(ctx context.Context, aw *ambient.AmbientWeather) *app.App {
|
||||||
|
// Load ambient routes into app
|
||||||
|
awApp := &app.App{
|
||||||
|
AppContext: ctx,
|
||||||
|
|
||||||
|
// HTTP Endpoints for Ambient Weather Stations
|
||||||
|
HTTP: &httpopts.AppHTTP{
|
||||||
|
Funcs: []httpopts.HTTPFunc{
|
||||||
|
{
|
||||||
|
Path: "/weatherstation/updateweatherstation.php",
|
||||||
|
HandlerFunc: aw.GetWundergroundHandlerFunc(ctx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "/data/report",
|
||||||
|
HandlerFunc: aw.GetAWNHandlerFunc(ctx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// HTTP Listener that fixes broken requests generated by
|
||||||
|
// some versions of awn firmware
|
||||||
|
CustomListener: ambienthttp.NewAWNMutatingListener(ctx,
|
||||||
|
aw.Config.HTTP.Listen), // Necessary to fix certain bad AWN firmware
|
||||||
|
|
||||||
|
// Health check funcs
|
||||||
|
HealthChecks: []httpopts.HealthCheckFunc{
|
||||||
|
// TODO: Implement
|
||||||
|
func(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// GRPC Service for retrieving weather
|
||||||
|
GRPC: &grpcopts.AppGRPC{
|
||||||
|
Services: []*grpcopts.GRPCService{
|
||||||
|
{
|
||||||
|
Name: "Weather Service",
|
||||||
|
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
|
||||||
|
Service: weathergrpc.NewGRPCWeather(ctx, aw.GetRecorder()),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return awApp
|
||||||
|
}
|
226
contrib/schema.json
Normal file
226
contrib/schema.json
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
{
|
||||||
|
"definitions": {
|
||||||
|
"ConfigGRPCConfig": {
|
||||||
|
"properties": {
|
||||||
|
"enableInstrumentation": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"enableReflection": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"enabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"listen": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logRequests": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigHTTPConfig": {
|
||||||
|
"properties": {
|
||||||
|
"enabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"idleTimeout": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"listen": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logRequests": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"readTimeout": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"writeTimeout": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigLogConfig": {
|
||||||
|
"properties": {
|
||||||
|
"enabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"format": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"level": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"output": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"timeFormat": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigOTELConfig": {
|
||||||
|
"properties": {
|
||||||
|
"enabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"metricIntervalSecs": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"prometheusEnabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"prometheusPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"stdoutEnabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigRecorderConfig": {
|
||||||
|
"properties": {
|
||||||
|
"keepLast": {
|
||||||
|
"default": 120,
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"redisConfig": {
|
||||||
|
"$ref": "#/definitions/ConfigRedisConfig"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"enum": [
|
||||||
|
"memory",
|
||||||
|
"redis",
|
||||||
|
"noop"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigRedisConfig": {
|
||||||
|
"properties": {
|
||||||
|
"redisDB": {
|
||||||
|
"default": 0,
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"redisHost": {
|
||||||
|
"default": "127.0.0.1",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"redisPassword": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"redisPort": {
|
||||||
|
"default": 6379,
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"redisTLS": {
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"redisTLSInsecure": {
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"redisUser": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"ConfigWeatherStation": {
|
||||||
|
"properties": {
|
||||||
|
"awnPassKey": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"dropMetrics": {
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"equipment": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"keepMetrics": {
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"proxyToAWN": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"proxyToWunderground": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"sensorMappings": {
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"wundergroundID": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"wundergroundPassword": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"environment": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"grpc": {
|
||||||
|
"$ref": "#/definitions/ConfigGRPCConfig"
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"$ref": "#/definitions/ConfigHTTPConfig"
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"$ref": "#/definitions/ConfigLogConfig"
|
||||||
|
},
|
||||||
|
"metricPrefix": {
|
||||||
|
"default": "weather",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"otel": {
|
||||||
|
"$ref": "#/definitions/ConfigOTELConfig"
|
||||||
|
},
|
||||||
|
"recorderConfig": {
|
||||||
|
"$ref": "#/definitions/ConfigRecorderConfig"
|
||||||
|
},
|
||||||
|
"updatesToKeep": {
|
||||||
|
"default": 1,
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"integer"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"weatherStations": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/ConfigWeatherStation"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
89
contrib/wu_sample.json
Normal file
89
contrib/wu_sample.json
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
{
|
||||||
|
"PASSKEY": [
|
||||||
|
"DE:AD:BE:EF:BE:EF"
|
||||||
|
],
|
||||||
|
"baromabsin": [
|
||||||
|
"29.025"
|
||||||
|
],
|
||||||
|
"baromrelin": [
|
||||||
|
"30.005"
|
||||||
|
],
|
||||||
|
"batt1": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"battin": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"battout": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"battrain": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"dailyrainin": [
|
||||||
|
"0.000"
|
||||||
|
],
|
||||||
|
"dateutc": [
|
||||||
|
"2025-03-23 14:07:59"
|
||||||
|
],
|
||||||
|
"eventrainin": [
|
||||||
|
"0.000"
|
||||||
|
],
|
||||||
|
"hourlyrainin": [
|
||||||
|
"0.000"
|
||||||
|
],
|
||||||
|
"humidity": [
|
||||||
|
"55"
|
||||||
|
],
|
||||||
|
"humidity1": [
|
||||||
|
"53"
|
||||||
|
],
|
||||||
|
"humidityin": [
|
||||||
|
"36"
|
||||||
|
],
|
||||||
|
"maxdailygust": [
|
||||||
|
"20.36"
|
||||||
|
],
|
||||||
|
"monthlyrainin": [
|
||||||
|
"1.969"
|
||||||
|
],
|
||||||
|
"solarradiation": [
|
||||||
|
"142.15"
|
||||||
|
],
|
||||||
|
"stationtype": [
|
||||||
|
"WeatherHub_V1.0.2"
|
||||||
|
],
|
||||||
|
"temp1f": [
|
||||||
|
"-2.74"
|
||||||
|
],
|
||||||
|
"tempf": [
|
||||||
|
"33.98"
|
||||||
|
],
|
||||||
|
"tempinf": [
|
||||||
|
"70.52"
|
||||||
|
],
|
||||||
|
"totalrainin": [
|
||||||
|
"2.421"
|
||||||
|
],
|
||||||
|
"uv": [
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"weeklyrainin": [
|
||||||
|
"0.000"
|
||||||
|
],
|
||||||
|
"winddir": [
|
||||||
|
"117"
|
||||||
|
],
|
||||||
|
"winddir_avg10m": [
|
||||||
|
"127"
|
||||||
|
],
|
||||||
|
"windgustmph": [
|
||||||
|
"17.22"
|
||||||
|
],
|
||||||
|
"windspeedmph": [
|
||||||
|
"10.29"
|
||||||
|
],
|
||||||
|
"yearlyrainin": [
|
||||||
|
"2.421"
|
||||||
|
]
|
||||||
|
}
|
9
contrib/wu_test_sample.sh
Executable file
9
contrib/wu_test_sample.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!env sh
|
||||||
|
SCRIPT_DIR=$( dirname $0 )
|
||||||
|
JSON_FILE="${SCRIPT_DIR}/wu_sample.json"
|
||||||
|
BASE_URL="http://127.0.0.1:8080/data/report"
|
||||||
|
|
||||||
|
# Convert JSON to query parameters
|
||||||
|
QUERY_STRING=$(jq -r 'to_entries | map("\(.key)=\(.value[0] | @uri)") | join("&")' "$JSON_FILE")
|
||||||
|
|
||||||
|
curl -G --data "$QUERY_STRING" "$BASE_URL"
|
18
go.mod
18
go.mod
@ -3,17 +3,18 @@ module gitea.libretechconsulting.com/rmcguire/ambient-local-exporter
|
|||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.6.3
|
gitea.libretechconsulting.com/rmcguire/go-app v0.7.0
|
||||||
github.com/go-resty/resty/v2 v2.16.5
|
github.com/go-resty/resty/v2 v2.16.5
|
||||||
github.com/gorilla/schema v1.4.1
|
github.com/gorilla/schema v1.4.1
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/redis/go-redis/v9 v9.7.3
|
||||||
|
github.com/rs/zerolog v1.34.0
|
||||||
go.opentelemetry.io/otel v1.35.0
|
go.opentelemetry.io/otel v1.35.0
|
||||||
go.opentelemetry.io/otel/metric v1.35.0
|
go.opentelemetry.io/otel/metric v1.35.0
|
||||||
go.opentelemetry.io/otel/trace v1.35.0
|
go.opentelemetry.io/otel/trace v1.35.0
|
||||||
golang.org/x/sys v0.31.0
|
golang.org/x/sys v0.31.0
|
||||||
google.golang.org/grpc v1.71.0
|
google.golang.org/grpc v1.71.0
|
||||||
google.golang.org/protobuf v1.36.5
|
google.golang.org/protobuf v1.36.5
|
||||||
k8s.io/utils v0.0.0-20241210054802-24370beab758
|
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -21,6 +22,7 @@ require (
|
|||||||
github.com/caarlos0/env/v11 v11.3.1 // indirect
|
github.com/caarlos0/env/v11 v11.3.1 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
@ -33,8 +35,10 @@ require (
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/prometheus/client_golang v1.21.1 // indirect
|
github.com/prometheus/client_golang v1.21.1 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.62.0 // indirect
|
github.com/prometheus/common v0.63.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.16.0 // indirect
|
||||||
|
github.com/swaggest/jsonschema-go v0.3.73 // indirect
|
||||||
|
github.com/swaggest/refl v1.3.1 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
|
||||||
@ -49,7 +53,7 @@ require (
|
|||||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||||
golang.org/x/net v0.37.0 // indirect
|
golang.org/x/net v0.37.0 // indirect
|
||||||
golang.org/x/text v0.23.0 // indirect
|
golang.org/x/text v0.23.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
23
go.sum
23
go.sum
@ -4,6 +4,8 @@ gitea.libretechconsulting.com/rmcguire/go-app v0.6.2 h1:vpEdZu7WI8qIil5NLf6OUF/T
|
|||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.6.2/go.mod h1:S3/vdMEiRWWIdD0Fr+tjJc627VzxNzO4Ia2HgTBXe+g=
|
gitea.libretechconsulting.com/rmcguire/go-app v0.6.2/go.mod h1:S3/vdMEiRWWIdD0Fr+tjJc627VzxNzO4Ia2HgTBXe+g=
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.6.3 h1:dXYHJxK/1vmWBj1wqbqEUncFt3O92agy9gNWoa9NpA0=
|
gitea.libretechconsulting.com/rmcguire/go-app v0.6.3 h1:dXYHJxK/1vmWBj1wqbqEUncFt3O92agy9gNWoa9NpA0=
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.6.3/go.mod h1:S3/vdMEiRWWIdD0Fr+tjJc627VzxNzO4Ia2HgTBXe+g=
|
gitea.libretechconsulting.com/rmcguire/go-app v0.6.3/go.mod h1:S3/vdMEiRWWIdD0Fr+tjJc627VzxNzO4Ia2HgTBXe+g=
|
||||||
|
gitea.libretechconsulting.com/rmcguire/go-app v0.7.0 h1:yhRRwV/dxN4Bey1Qv8/rHHV5QvALrZuDJFI+zFPc7sU=
|
||||||
|
gitea.libretechconsulting.com/rmcguire/go-app v0.7.0/go.mod h1:EM3Z9QcRD+b7UlKGA9y37ppfUBC0Reyf5sYEC6vFZcY=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
|
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
|
||||||
@ -15,6 +17,8 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
|
|||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
@ -63,15 +67,28 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p
|
|||||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
|
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
|
||||||
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||||
|
github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k=
|
||||||
|
github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
|
github.com/prometheus/procfs v0.16.0 h1:xh6oHhKwnOJKMYiYBDWmkHqQPyiY40sny36Cmx2bbsM=
|
||||||
|
github.com/prometheus/procfs v0.16.0/go.mod h1:8veyXUu3nGP7oaCxhX6yeaM5u4stL2FeMXnCqhDthZg=
|
||||||
|
github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM=
|
||||||
|
github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
|
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||||
|
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
|
||||||
|
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/swaggest/jsonschema-go v0.3.73 h1:gU1pBzF3pkZ1GDD3dRMdQoCjrA0sldJ+QcM7aSSPgvc=
|
||||||
|
github.com/swaggest/jsonschema-go v0.3.73/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU=
|
||||||
|
github.com/swaggest/refl v1.3.1 h1:XGplEkYftR7p9cz1lsiwXMM2yzmOymTE9vneVVpaOh4=
|
||||||
|
github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 h1:x7wzEgXfnzJcHDwStJT+mxOz4etr2EcexjqhBvmoakw=
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 h1:x7wzEgXfnzJcHDwStJT+mxOz4etr2EcexjqhBvmoakw=
|
||||||
@ -117,8 +134,12 @@ golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
|||||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb h1:p31xT4yrYrSM/G4Sn2+TNUkVhFCbG9y8itM2S6Th950=
|
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb h1:p31xT4yrYrSM/G4Sn2+TNUkVhFCbG9y8itM2S6Th950=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:jbe3Bkdp+Dh2IrslsFCklNhweNTBgSYanP1UXhJDhKg=
|
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:jbe3Bkdp+Dh2IrslsFCklNhweNTBgSYanP1UXhJDhKg=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250313205543-e70fdf4c4cb4 h1:IFnXJq3UPB3oBREOodn1v1aGQeZYQclEmvWRMN0PSsY=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:c8q6Z6OCqnfVIqUFJkCzKcrj8eCvUrz+K4KRzSTuANg=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb h1:TLPQVbx1GJ8VKZxz52VAxl1EBgKXXbTiU9Fc5fZeLn4=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb h1:TLPQVbx1GJ8VKZxz52VAxl1EBgKXXbTiU9Fc5fZeLn4=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 h1:iK2jbkWL86DXjEx0qiHcRE9dE4/Ahua5k6V8OWFb//c=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
|
||||||
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
|
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
|
||||||
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
||||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||||
@ -130,3 +151,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
|
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
|
||||||
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||||
|
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e h1:KqK5c/ghOm8xkHYhlodbp6i6+r+ChV2vuAuVRdFbLro=
|
||||||
|
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||||
|
@ -15,13 +15,13 @@ type: application
|
|||||||
# This is the chart version. This version number should be incremented each time you make changes
|
# This is the chart version. This version number should be incremented each time you make changes
|
||||||
# to the chart and its templates, including the app version.
|
# to the chart and its templates, including the app version.
|
||||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||||
version: 0.1.2
|
version: 0.1.4
|
||||||
|
|
||||||
# This is the version number of the application being deployed. This version number should be
|
# This is the version number of the application being deployed. This version number should be
|
||||||
# incremented each time you make changes to the application. Versions are not expected to
|
# incremented each time you make changes to the application. Versions are not expected to
|
||||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||||
# It is recommended to use it with quotes.
|
# It is recommended to use it with quotes.
|
||||||
appVersion: "v0.10.2"
|
appVersion: "v0.11.2"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
- name: hull
|
- name: hull
|
||||||
|
66
main.go
66
main.go
@ -2,25 +2,24 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
||||||
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"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
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"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/ambienthttp"
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
||||||
weathergrpc "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultMetricPrefix = "weather"
|
defaultMetricPrefix = "weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var schema bool
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt, unix.SIGTERM)
|
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt, unix.SIGTERM)
|
||||||
defer cncl()
|
defer cncl()
|
||||||
@ -36,6 +35,12 @@ func main() {
|
|||||||
// and set up logging, tracing, etc..
|
// and set up logging, tracing, etc..
|
||||||
aw := ambient.New(ctx, awConfig).Init()
|
aw := ambient.New(ctx, awConfig).Init()
|
||||||
|
|
||||||
|
// Just show schema if that's all we were asked to do
|
||||||
|
if schema {
|
||||||
|
printSchema(awConfig)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
// Load http and grpc routes, prepare the app
|
// Load http and grpc routes, prepare the app
|
||||||
awApp := prepareApp(ctx, aw)
|
awApp := prepareApp(ctx, aw)
|
||||||
|
|
||||||
@ -44,49 +49,16 @@ func main() {
|
|||||||
<-awApp.Done()
|
<-awApp.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareApp(ctx context.Context, aw *ambient.AmbientWeather) *app.App {
|
// flag.Parse will be called by go-app
|
||||||
// Load ambient routes into app
|
func init() {
|
||||||
awApp := &app.App{
|
flag.BoolVar(&schema, "schema", false, "generate json schema and exit")
|
||||||
AppContext: ctx,
|
}
|
||||||
|
|
||||||
// HTTP Endpoints for Ambient Weather Stations
|
func printSchema(config *config.AmbientLocalExporterConfig) {
|
||||||
HTTP: &httpopts.AppHTTP{
|
bytes, err := app.CustomSchema(config)
|
||||||
Funcs: []httpopts.HTTPFunc{
|
if err != nil {
|
||||||
{
|
panic(err)
|
||||||
Path: "/weatherstation/updateweatherstation.php",
|
|
||||||
HandlerFunc: aw.GetWundergroundHandlerFunc(ctx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/data/report",
|
|
||||||
HandlerFunc: aw.GetAWNHandlerFunc(ctx),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// HTTP Listener that fixes broken requests generated by
|
|
||||||
// some versions of awn firmware
|
|
||||||
CustomListener: ambienthttp.NewAWNMutatingListener(ctx,
|
|
||||||
aw.Config.HTTP.Listen), // Necessary to fix certain bad AWN firmware
|
|
||||||
|
|
||||||
// Health check funcs
|
|
||||||
HealthChecks: []httpopts.HealthCheckFunc{
|
|
||||||
// TODO: Implement
|
|
||||||
func(ctx context.Context) error {
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// GRPC Service for retrieving weather
|
|
||||||
GRPC: &grpcopts.AppGRPC{
|
|
||||||
Services: []*grpcopts.GRPCService{
|
|
||||||
{
|
|
||||||
Name: "Weather Service",
|
|
||||||
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
|
|
||||||
Service: weathergrpc.NewGRPCWeather(ctx, aw.GetRecorder()),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return awApp
|
fmt.Println(string(bytes))
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,10 @@ import (
|
|||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/provider/wunderground"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/provider/wunderground"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/memory"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/noop"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defUpdatesToKeep = 120
|
const defUpdatesToKeep = 120
|
||||||
@ -70,10 +74,27 @@ func (aw *AmbientWeather) Init() *AmbientWeather {
|
|||||||
}
|
}
|
||||||
span.SetAttributes(attribute.Int("updatesToKeep", updatesToKeep))
|
span.SetAttributes(attribute.Int("updatesToKeep", updatesToKeep))
|
||||||
|
|
||||||
// TODO: Support other recorders (don't rely on default)
|
// Choose weather recorder for grpc / api requests,
|
||||||
aw.weatherRecorder = recorder.NewWeatherRecorder(&recorder.Opts{
|
// default is memory recorder
|
||||||
Ctx: aw.appCtx,
|
var r recorders.Recorder
|
||||||
KeepLast: updatesToKeep,
|
if aw.Config == nil || aw.Config.RecorderConfig == nil {
|
||||||
|
r = &memory.MemoryRecorder{}
|
||||||
|
} else {
|
||||||
|
switch aw.Config.RecorderConfig.Type {
|
||||||
|
case config.TypeMemory:
|
||||||
|
r = &memory.MemoryRecorder{}
|
||||||
|
case config.TypeRedis:
|
||||||
|
r = &redis.RedisRecorder{}
|
||||||
|
case config.TypeNoop:
|
||||||
|
r = &noop.NoopRecorder{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aw.weatherRecorder = recorder.MustNewWeatherRecorder(&recorder.Opts{
|
||||||
|
AppConfig: aw.Config,
|
||||||
|
Ctx: aw.appCtx,
|
||||||
|
KeepLast: updatesToKeep,
|
||||||
|
Recorder: r,
|
||||||
})
|
})
|
||||||
|
|
||||||
aw.l.Trace().Any("awConfig", aw.Config).Send()
|
aw.l.Trace().Any("awConfig", aw.Config).Send()
|
||||||
|
@ -6,24 +6,25 @@ import (
|
|||||||
|
|
||||||
// This configuration includes all config from go-app/config.AppConfig
|
// This configuration includes all config from go-app/config.AppConfig
|
||||||
type AmbientLocalExporterConfig struct {
|
type AmbientLocalExporterConfig struct {
|
||||||
MetricPrefix string `yaml:"metricPrefix" default:"weather" env:"AMBIENT_METRIC_PREFIX"`
|
MetricPrefix string `yaml:"metricPrefix" default:"weather" env:"AMBIENT_METRIC_PREFIX" json:"metricPrefix,omitempty"`
|
||||||
UpdatesToKeep *int `yaml:"updatesToKeep" default:"1" env:"AMBIENT_UPDATES_TO_KEEP"`
|
UpdatesToKeep *int `yaml:"updatesToKeep" default:"1" env:"AMBIENT_UPDATES_TO_KEEP" json:"updatesToKeep,omitempty"`
|
||||||
WeatherStations []WeatherStation `yaml:"weatherStations" env:"weatherStations"` // No env, too complex, not worth the time
|
WeatherStations []WeatherStation `yaml:"weatherStations" json:"weatherStations,omitempty"` // No env, too complex, not worth the time
|
||||||
|
RecorderConfig *RecorderConfig `yaml:"recorderConfig" json:"recorderConfig,omitempty"`
|
||||||
*config.AppConfig // Extends app config
|
*config.AppConfig // Extends app config
|
||||||
}
|
}
|
||||||
|
|
||||||
type WeatherStation struct {
|
type WeatherStation struct {
|
||||||
Name string `yaml:"name"` // Human Friendly Name (e.g. Back Yard Weather)
|
Name string `yaml:"name" json:"name,omitempty"` // Human Friendly Name (e.g. Back Yard Weather)
|
||||||
Equipment string `yaml:"equipment"` // Equipment Type (e.g. WS-5000)
|
Equipment string `yaml:"equipment" json:"equipment,omitempty"` // Equipment Type (e.g. WS-5000)
|
||||||
|
|
||||||
// Required if proxying to awn/wu is enabled
|
// Required if proxying to awn/wu is enabled
|
||||||
WundergroundID string `yaml:"wundergroundID"`
|
WundergroundID string `yaml:"wundergroundID" json:"wundergroundID,omitempty"`
|
||||||
WundergroundPassword string `yaml:"wundergroundPassword"`
|
WundergroundPassword string `yaml:"wundergroundPassword" json:"wundergroundPassword,omitempty"`
|
||||||
AWNPassKey string `yaml:"awnPassKey"`
|
AWNPassKey string `yaml:"awnPassKey" json:"awnPassKey,omitempty"`
|
||||||
|
|
||||||
// Proxy updates to AWN or Wunderground
|
// Proxy updates to AWN or Wunderground
|
||||||
ProxyToAWN bool `yaml:"proxyToAWN"`
|
ProxyToAWN bool `yaml:"proxyToAWN" json:"proxyToAWN,omitempty"`
|
||||||
ProxyToWunderground bool `yaml:"proxyToWunderground"`
|
ProxyToWunderground bool `yaml:"proxyToWunderground" json:"proxyToWunderground,omitempty"`
|
||||||
|
|
||||||
// Unreliable / unwanted metrics by name of WeatherUpdate Field
|
// Unreliable / unwanted metrics by name of WeatherUpdate Field
|
||||||
// will be excluded if present in discardMetrics
|
// will be excluded if present in discardMetrics
|
||||||
@ -32,8 +33,8 @@ type WeatherStation struct {
|
|||||||
// ignoring discardMetrics.
|
// ignoring discardMetrics.
|
||||||
//
|
//
|
||||||
// Check weather.WeatherUpdateField for options
|
// Check weather.WeatherUpdateField for options
|
||||||
KeepMetrics []string `yaml:"keepMetrics"`
|
KeepMetrics []string `yaml:"keepMetrics" json:"keepMetrics,omitempty"`
|
||||||
DropMetrics []string `yaml:"dropMetrics"`
|
DropMetrics []string `yaml:"dropMetrics" json:"dropMetrics,omitempty"`
|
||||||
|
|
||||||
// Relabels battery and sensor names
|
// Relabels battery and sensor names
|
||||||
// Temp+Humidity Sensors:
|
// Temp+Humidity Sensors:
|
||||||
@ -43,5 +44,5 @@ type WeatherStation struct {
|
|||||||
// - OutdoorSensor
|
// - OutdoorSensor
|
||||||
// - RainSensor
|
// - RainSensor
|
||||||
// - CO2Sensor
|
// - CO2Sensor
|
||||||
SensorMappings map[string]string `yaml:"sensorMappings"`
|
SensorMappings map[string]string `yaml:"sensorMappings" json:"sensorMappings,omitempty"`
|
||||||
}
|
}
|
||||||
|
25
pkg/ambient/config/config_recorder.go
Normal file
25
pkg/ambient/config/config_recorder.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type RecorderType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
TypeMemory RecorderType = "memory" // Stores weather updates in memory
|
||||||
|
TypeRedis RecorderType = "redis" // Required for replicas > 1
|
||||||
|
TypeNoop RecorderType = "noop" // No-op implementation
|
||||||
|
)
|
||||||
|
|
||||||
|
type RecorderConfig struct {
|
||||||
|
Type RecorderType `yaml:"type" env:"RECORDER_TYPE" json:"type,omitempty" enum:"memory,redis,noop"`
|
||||||
|
KeepLast int `yaml:"keepLast" env:"RECORDER_KEEP_LAST" json:"keepLast,omitempty" default:"120"`
|
||||||
|
RedisConfig *RedisConfig `yaml:"redisConfig,omitempty" json:"redisConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RedisConfig struct {
|
||||||
|
RedisHost string `yaml:"redisHost" env:"REDIS_HOST" default:"127.0.0.1" json:"redisHost,omitempty"`
|
||||||
|
RedisPort int `yaml:"redisPort" env:"REDIS_PORT" default:"6379" json:"redisPort,omitempty"`
|
||||||
|
RedisUser string `yaml:"redisUser" env:"REDIS_USER" json:"redisUser,omitempty"`
|
||||||
|
RedisPassword string `yaml:"redisPassword" env:"REDIS_PASSWORD" json:"redisPassword,omitempty"`
|
||||||
|
RedisDB int `yaml:"redisDB" env:"REDIS_DB" default:"0" json:"redisDB,omitempty"`
|
||||||
|
RedisTLS bool `yaml:"redisTLS" env:"REDIS_TLS" default:"false" json:"redisTLS,omitempty"`
|
||||||
|
RedisTLSInsecure bool `yaml:"redisTLSInsecure" env:"REDIS_TLS_INSECURE" default:"false" json:"redisTLSInsecure,omitempty"`
|
||||||
|
}
|
@ -1,6 +1,19 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import "k8s.io/utils/ptr"
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
|
)
|
||||||
|
|
||||||
|
const defaultLimit = -1
|
||||||
|
|
||||||
func DerefStr(s *string) string {
|
func DerefStr(s *string) string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
@ -15,3 +28,77 @@ func Int32ptr(i *int) *int32 {
|
|||||||
}
|
}
|
||||||
return ptr.To(int32(*i))
|
return ptr.To(int32(*i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates a hash that will be consistent
|
||||||
|
// across all running replicas
|
||||||
|
func GetAppHash(conf *config.AppConfig) string {
|
||||||
|
hashName := fmt.Sprintf("%s-%s-%s",
|
||||||
|
conf.Name,
|
||||||
|
conf.Environment,
|
||||||
|
conf.Version,
|
||||||
|
)
|
||||||
|
|
||||||
|
hash := md5.Sum([]byte(hashName))
|
||||||
|
return hex.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a limit from req, applying a default if unset or not sane
|
||||||
|
func GetLimitFromReq(req *pb.GetWeatherRequest) int {
|
||||||
|
if req == nil || req.Limit == nil {
|
||||||
|
return defaultLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.GetLimit() == 0 {
|
||||||
|
return defaultLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(req.GetLimit())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple helper to trim a list of updates
|
||||||
|
func LimitUpdates(updates []*weather.WeatherUpdate, limit int) []*weather.WeatherUpdate {
|
||||||
|
if limit < 0 {
|
||||||
|
return updates // No limit
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(updates) > limit {
|
||||||
|
return updates[len(updates)-limit:] // Trim to limit
|
||||||
|
}
|
||||||
|
|
||||||
|
return updates // Within limit
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApplyOptsToUpdates(updates []*weather.WeatherUpdate, limit int, opts *pb.GetWeatherOpts) []*weather.WeatherUpdate {
|
||||||
|
if opts == nil {
|
||||||
|
return updates
|
||||||
|
} else if opts.StationName == nil && opts.StationType == nil {
|
||||||
|
return updates
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered := make([]*weather.WeatherUpdate, 0, limit)
|
||||||
|
|
||||||
|
for i := len(updates) - 1; i >= 0; i-- {
|
||||||
|
update := updates[i]
|
||||||
|
match := true
|
||||||
|
|
||||||
|
if opts.GetStationName() != "" {
|
||||||
|
if update.GetStationName() != opts.GetStationName() {
|
||||||
|
match = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if opts.GetStationType() != "" {
|
||||||
|
if DerefStr(update.StationType) != opts.GetStationType() {
|
||||||
|
match = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if match {
|
||||||
|
filtered = append(filtered, update)
|
||||||
|
if limit > 0 && len(filtered) >= limit {
|
||||||
|
return slices.Clip(filtered)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return slices.Clip(filtered)
|
||||||
|
}
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Converts a slice of weather.WeatherUpdate to proto structs
|
||||||
func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
||||||
updates := make([]*pb.WeatherUpdate, len(u))
|
updates := make([]*pb.WeatherUpdate, len(u))
|
||||||
for i, update := range u {
|
for i, update := range u {
|
||||||
@ -14,7 +20,16 @@ func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
|||||||
return updates
|
return updates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maps a weather.WeatherUpdate to the proto version.
|
||||||
|
//
|
||||||
|
// This should be auto-generated code, but as the proto should be
|
||||||
|
// stable, it is probably not worth the effort.
|
||||||
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
||||||
|
if u.DateUTC == nil {
|
||||||
|
now := time.Now()
|
||||||
|
u.DateUTC = &now
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.WeatherUpdate{
|
return &pb.WeatherUpdate{
|
||||||
StationName: u.StationConfig.Name,
|
StationName: u.StationConfig.Name,
|
||||||
StationType: util.DerefStr(u.StationType),
|
StationType: util.DerefStr(u.StationType),
|
||||||
@ -43,28 +58,33 @@ func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
|||||||
DewPointF: u.DewPointF,
|
DewPointF: u.DewPointF,
|
||||||
WindChillF: u.WindChillF,
|
WindChillF: u.WindChillF,
|
||||||
TempHumiditySensors: thSensorsToPbSensors(u.TempHumiditySensors),
|
TempHumiditySensors: thSensorsToPbSensors(u.TempHumiditySensors),
|
||||||
|
UpdateTimestamp: timestamppb.New(*u.DateUTC),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
|
func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
|
||||||
pbBatteries := make([]*pb.BatteryStatus, len(batteries))
|
pbBatteries := make([]*pb.BatteryStatus, 0, len(batteries))
|
||||||
for i, b := range batteries {
|
for _, b := range batteries {
|
||||||
pbBatteries[i] = &pb.BatteryStatus{
|
if b.Status != nil {
|
||||||
Component: b.Component,
|
pbBatteries = append(pbBatteries, &pb.BatteryStatus{
|
||||||
Status: util.Int32ptr(b.Status),
|
Component: b.Component,
|
||||||
|
Status: util.Int32ptr(b.Status),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pbBatteries
|
return slices.Clip(pbBatteries)
|
||||||
}
|
}
|
||||||
|
|
||||||
func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
|
func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
|
||||||
pbSensors := make([]*pb.TempHumiditySensor, len(sensors))
|
pbSensors := make([]*pb.TempHumiditySensor, 0, len(sensors))
|
||||||
for i, s := range sensors {
|
for _, s := range sensors {
|
||||||
pbSensors[i] = &pb.TempHumiditySensor{
|
if s.TempF != nil || s.Humidity != nil {
|
||||||
Name: s.Name,
|
pbSensors = append(pbSensors, &pb.TempHumiditySensor{
|
||||||
TempF: s.TempF,
|
Name: s.Name,
|
||||||
Humidity: util.Int32ptr(s.Humidity),
|
TempF: s.TempF,
|
||||||
|
Humidity: util.Int32ptr(s.Humidity),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pbSensors
|
return slices.Clip(pbSensors)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
"k8s.io/utils/ptr"
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
@ -12,8 +13,10 @@ import (
|
|||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var now = time.Now()
|
||||||
|
|
||||||
var mockUpdate = &weather.WeatherUpdate{
|
var mockUpdate = &weather.WeatherUpdate{
|
||||||
DateUTC: &time.Time{},
|
DateUTC: &now,
|
||||||
StationConfig: &config.WeatherStation{
|
StationConfig: &config.WeatherStation{
|
||||||
Name: "50W",
|
Name: "50W",
|
||||||
Equipment: "WS-5000",
|
Equipment: "WS-5000",
|
||||||
@ -100,6 +103,7 @@ func TestUpdateToPbUpdate(t *testing.T) {
|
|||||||
Humidity: nil,
|
Humidity: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
UpdateTimestamp: timestamppb.New(now),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"go.opentelemetry.io/otel/metric"
|
"go.opentelemetry.io/otel/metric"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/memory"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type WeatherRecorder struct {
|
type WeatherRecorder struct {
|
||||||
@ -22,25 +23,30 @@ type WeatherRecorder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
Ctx context.Context
|
AppConfig *config.AmbientLocalExporterConfig
|
||||||
Recorder recorders.Recorder // If nil, will use memory recorder
|
Ctx context.Context
|
||||||
KeepLast int
|
Recorder recorders.Recorder // If nil, will use memory recorder
|
||||||
|
KeepLast int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWeatherRecorder(opts *Opts) *WeatherRecorder {
|
func MustNewWeatherRecorder(opts *Opts) *WeatherRecorder {
|
||||||
if opts.KeepLast < 1 {
|
if opts.KeepLast < 1 {
|
||||||
opts.KeepLast = 1
|
opts.KeepLast = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Recorder == nil {
|
if opts.Recorder == nil {
|
||||||
opts.Recorder = &memory.MemoryRecorder{}
|
panic("no recorder provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Recorder.Init(opts.Ctx, &recorders.RecorderOpts{
|
opts.Recorder.Init(opts.Ctx, &recorders.RecorderOpts{
|
||||||
|
AppConfig: opts.AppConfig,
|
||||||
RetainLast: opts.KeepLast,
|
RetainLast: opts.KeepLast,
|
||||||
BaseCtx: opts.Ctx,
|
BaseCtx: opts.Ctx,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
zerolog.Ctx(opts.Ctx).Info().Str("recorderType", opts.Recorder.Name()).
|
||||||
|
Msg("weather update recorder ready")
|
||||||
|
|
||||||
return &WeatherRecorder{
|
return &WeatherRecorder{
|
||||||
ctx: opts.Ctx,
|
ctx: opts.Ctx,
|
||||||
recorder: opts.Recorder,
|
recorder: opts.Recorder,
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"k8s.io/utils/ptr"
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,10 +26,16 @@ func (w *WeatherRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
|||||||
req.Limit = ptr.To(int32(1))
|
req.Limit = ptr.To(int32(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filterSN, filterST string
|
||||||
|
if req.Opts != nil {
|
||||||
|
filterSN = req.Opts.GetStationName()
|
||||||
|
filterST = req.Opts.GetStationType()
|
||||||
|
}
|
||||||
|
|
||||||
ctx, span := w.tracer.Start(ctx, "getWeatherRecorder")
|
ctx, span := w.tracer.Start(ctx, "getWeatherRecorder")
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
attribute.String("stationNameFilter", util.DerefStr(req.Opts.StationName)),
|
attribute.String("stationNameFilter", filterSN),
|
||||||
attribute.String("stationTypeFilter", util.DerefStr(req.Opts.StationType)),
|
attribute.String("stationTypeFilter", filterST),
|
||||||
attribute.Int("last", int(*req.Limit)),
|
attribute.Int("last", int(*req.Limit)),
|
||||||
attribute.Int("currentSize", w.Count(ctx)),
|
attribute.Int("currentSize", w.Count(ctx)),
|
||||||
)
|
)
|
||||||
|
@ -6,16 +6,28 @@ import (
|
|||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *WeatherRecorder) Set(ctx context.Context, u *weather.WeatherUpdate) error {
|
func (w *WeatherRecorder) Set(ctx context.Context, u *weather.WeatherUpdate) error {
|
||||||
|
if u.StationConfig == nil {
|
||||||
|
u.StationConfig = &config.WeatherStation{
|
||||||
|
Name: "unregistered",
|
||||||
|
Equipment: "unknown",
|
||||||
|
ProxyToAWN: false,
|
||||||
|
ProxyToWunderground: false,
|
||||||
|
KeepMetrics: []string{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx, span := w.tracer.Start(ctx, "setRecorderUpdate", trace.WithAttributes(
|
ctx, span := w.tracer.Start(ctx, "setRecorderUpdate", trace.WithAttributes(
|
||||||
attribute.String("stationName", u.StationConfig.Name),
|
attribute.String("stationName", u.StationConfig.Name),
|
||||||
attribute.String("stationType", util.DerefStr(u.StationType)),
|
attribute.String("stationType", util.DerefStr(u.StationType)),
|
||||||
attribute.String("stationEquipment", u.StationConfig.Equipment),
|
attribute.String("stationEquipment", u.StationConfig.Equipment),
|
||||||
))
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
return w.recorder.Set(ctx, u)
|
return w.recorder.Set(ctx, u)
|
||||||
}
|
}
|
||||||
|
24
pkg/weather/recorder/recorders/memory/count.go
Normal file
24
pkg/weather/recorder/recorders/memory/count.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package memory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *MemoryRecorder) Count(ctx context.Context) int {
|
||||||
|
_, span := r.tracer.Start(ctx, "countWeatherRecorder")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
count := r.count()
|
||||||
|
|
||||||
|
span.SetAttributes(attribute.Int("count", count))
|
||||||
|
span.SetStatus(codes.Ok, "")
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MemoryRecorder) count() int {
|
||||||
|
return len(r.updates)
|
||||||
|
}
|
@ -3,19 +3,19 @@ package memory
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"slices"
|
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
|
||||||
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *MemoryRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
func (r *MemoryRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
||||||
[]*weather.WeatherUpdate, error,
|
[]*weather.WeatherUpdate, error,
|
||||||
) {
|
) {
|
||||||
ctx, span := r.tracer.Start(ctx, "memoryRecorder.Get")
|
_, span := r.tracer.Start(ctx, "memoryRecorder.Get")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
r.RLock()
|
r.RLock()
|
||||||
@ -23,34 +23,17 @@ func (r *MemoryRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
|||||||
|
|
||||||
span.AddEvent("acquired lock on recorder cache")
|
span.AddEvent("acquired lock on recorder cache")
|
||||||
|
|
||||||
updates := r.updates
|
limit := util.GetLimitFromReq(req)
|
||||||
|
|
||||||
if r.count() == 0 {
|
if r.count() == 0 {
|
||||||
err := errors.New("no recorded updates to get")
|
err := errors.New("no recorded updates to get")
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if r.count() <= int(*req.Limit) {
|
} else if limit > 0 && r.count() <= limit {
|
||||||
span.RecordError(errors.New("requested more updates than recorded"))
|
span.RecordError(errors.New("requested more updates than recorded"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by Station Name if requested
|
updates := r.getUpdatesFromReq(req)
|
||||||
if req.Opts.StationName != nil && *req.Opts.StationName != "" {
|
span.AddEvent("request limit/opts applied to updates")
|
||||||
updates = slices.DeleteFunc(updates, func(u *weather.WeatherUpdate) bool {
|
|
||||||
return u.StationConfig == nil || u.StationConfig.Name != *req.Opts.StationName
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter by Station Type if requested
|
|
||||||
if req.Opts.StationType != nil && *req.Opts.StationType != "" {
|
|
||||||
updates = slices.DeleteFunc(updates, func(u *weather.WeatherUpdate) bool {
|
|
||||||
return u.StationType == nil || *u.StationType != *req.Opts.StationType
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit results
|
|
||||||
if len(updates) > int(*req.Limit) {
|
|
||||||
updates = updates[len(updates)-int(*req.Limit):]
|
|
||||||
}
|
|
||||||
|
|
||||||
span.SetAttributes(attribute.Int("retrieved", len(updates)))
|
span.SetAttributes(attribute.Int("retrieved", len(updates)))
|
||||||
span.SetStatus(codes.Ok, "")
|
span.SetStatus(codes.Ok, "")
|
||||||
@ -58,18 +41,10 @@ func (r *MemoryRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
|||||||
return updates, nil
|
return updates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MemoryRecorder) Count(ctx context.Context) int {
|
func (r *MemoryRecorder) getUpdatesFromReq(req *pb.GetWeatherRequest) []*weather.WeatherUpdate {
|
||||||
_, span := r.tracer.Start(ctx, "countWeatherRecorder")
|
if req.Opts == nil {
|
||||||
defer span.End()
|
return util.LimitUpdates(r.updates, util.GetLimitFromReq(req))
|
||||||
|
}
|
||||||
|
|
||||||
count := r.count()
|
return util.ApplyOptsToUpdates(r.updates, util.GetLimitFromReq(req), req.Opts)
|
||||||
|
|
||||||
span.SetAttributes(attribute.Int("count", count))
|
|
||||||
span.SetStatus(codes.Ok, "")
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *MemoryRecorder) count() int {
|
|
||||||
return len(r.updates)
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,10 @@ import (
|
|||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defRetainLast = 120
|
const (
|
||||||
|
DEF_RETAIN_LAST = 120
|
||||||
|
NAME = "memory recorder"
|
||||||
|
)
|
||||||
|
|
||||||
type MemoryRecorder struct {
|
type MemoryRecorder struct {
|
||||||
baseCtx context.Context
|
baseCtx context.Context
|
||||||
@ -24,7 +27,7 @@ type MemoryRecorder struct {
|
|||||||
|
|
||||||
func (r *MemoryRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts) {
|
func (r *MemoryRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts) {
|
||||||
if opts.RetainLast < 1 {
|
if opts.RetainLast < 1 {
|
||||||
opts.RetainLast = defRetainLast
|
opts.RetainLast = DEF_RETAIN_LAST
|
||||||
}
|
}
|
||||||
|
|
||||||
r.updates = make([]*weather.WeatherUpdate, 0, opts.RetainLast)
|
r.updates = make([]*weather.WeatherUpdate, 0, opts.RetainLast)
|
||||||
@ -33,3 +36,5 @@ func (r *MemoryRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts)
|
|||||||
r.RWMutex = &sync.RWMutex{}
|
r.RWMutex = &sync.RWMutex{}
|
||||||
r.tracer = otel.GetTracer(r.baseCtx, "memoryRecorder")
|
r.tracer = otel.GetTracer(r.baseCtx, "memoryRecorder")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *MemoryRecorder) Name() string { return NAME }
|
||||||
|
23
pkg/weather/recorder/recorders/noop/noop.go
Normal file
23
pkg/weather/recorder/recorders/noop/noop.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package noop
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NoopRecorder struct{}
|
||||||
|
|
||||||
|
func (n *NoopRecorder) Init(context.Context, *recorders.RecorderOpts) {}
|
||||||
|
|
||||||
|
func (n *NoopRecorder) Set(context.Context, *weather.WeatherUpdate) error { return nil }
|
||||||
|
|
||||||
|
func (n *NoopRecorder) Get(context.Context, *pb.GetWeatherRequest) ([]*weather.WeatherUpdate, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NoopRecorder) Count(context.Context) int { return 0 }
|
||||||
|
|
||||||
|
func (r *NoopRecorder) Name() string { return "no-op recorder" }
|
@ -4,12 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RecorderOpts struct {
|
type RecorderOpts struct {
|
||||||
RetainLast int
|
RetainLast int
|
||||||
BaseCtx context.Context
|
BaseCtx context.Context
|
||||||
|
AppConfig *config.AmbientLocalExporterConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type Recorder interface {
|
type Recorder interface {
|
||||||
@ -17,4 +19,5 @@ type Recorder interface {
|
|||||||
Set(context.Context, *weather.WeatherUpdate) error
|
Set(context.Context, *weather.WeatherUpdate) error
|
||||||
Get(context.Context, *pb.GetWeatherRequest) ([]*weather.WeatherUpdate, error)
|
Get(context.Context, *pb.GetWeatherRequest) ([]*weather.WeatherUpdate, error)
|
||||||
Count(context.Context) int // Best Effort
|
Count(context.Context) int // Best Effort
|
||||||
|
Name() string
|
||||||
}
|
}
|
||||||
|
38
pkg/weather/recorder/recorders/redis/count.go
Normal file
38
pkg/weather/recorder/recorders/redis/count.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package redis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Count(ctx context.Context) int {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.count")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
r.RLock()
|
||||||
|
defer r.RUnlock()
|
||||||
|
|
||||||
|
return r.count(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) count(ctx context.Context) int {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.count.redis", trace.WithAttributes(
|
||||||
|
attribute.String("updatesKey", r.Key())))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
count, err := r.redis.LLen(ctx, r.Key()).Result()
|
||||||
|
if err != nil {
|
||||||
|
span.RecordError(err)
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
r.log.Err(err).Send()
|
||||||
|
return int(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
span.SetAttributes(attribute.Int64("updatesCount", count))
|
||||||
|
span.SetStatus(codes.Ok, "")
|
||||||
|
|
||||||
|
return int(count)
|
||||||
|
}
|
98
pkg/weather/recorder/recorders/redis/get.go
Normal file
98
pkg/weather/recorder/recorders/redis/get.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package redis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Get(ctx context.Context, req *pb.GetWeatherRequest) (
|
||||||
|
[]*weather.WeatherUpdate, error,
|
||||||
|
) {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.get", trace.WithAttributes(
|
||||||
|
attribute.Int("limit", util.GetLimitFromReq(req)),
|
||||||
|
))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
return r.get(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) get(ctx context.Context, req *pb.GetWeatherRequest) (
|
||||||
|
[]*weather.WeatherUpdate, error,
|
||||||
|
) {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.get.redis")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
limit := util.GetLimitFromReq(req)
|
||||||
|
if limit < 1 {
|
||||||
|
limit = r.keep
|
||||||
|
}
|
||||||
|
|
||||||
|
span.SetAttributes(attribute.Int("limit", limit))
|
||||||
|
r.log.Debug().Int("limit", limit).Msg("getting updates from redis")
|
||||||
|
|
||||||
|
datas, err := r.redis.LRange(ctx, r.Key(), 0, int64(limit)-1).Result()
|
||||||
|
if err != nil {
|
||||||
|
span.RecordError(err)
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
r.log.Err(err).Send()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
span.AddEvent("redis queried")
|
||||||
|
r.log.Debug().Int("results", len(datas)).Msg("redis queried")
|
||||||
|
|
||||||
|
updates, err := jsonDatasToUpdates(datas)
|
||||||
|
if err != nil {
|
||||||
|
span.RecordError(err)
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
r.log.Err(err).Send()
|
||||||
|
} else {
|
||||||
|
span.SetStatus(codes.Ok, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
span.AddEvent("results unmarshalled")
|
||||||
|
span.SetAttributes(attribute.Int("results", len(updates)))
|
||||||
|
|
||||||
|
filtered := util.ApplyOptsToUpdates(updates, limit, req.Opts)
|
||||||
|
|
||||||
|
span.AddEvent("results filtered")
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.Int("filteredResults", len(filtered)),
|
||||||
|
attribute.Int("resultsFiltered", len(updates)-len(filtered)),
|
||||||
|
)
|
||||||
|
|
||||||
|
r.log.Debug().
|
||||||
|
Int("updatesRetrieved", len(updates)).
|
||||||
|
Int("updatesAfterFiltering", len(filtered)).
|
||||||
|
Int("updatesFiltered", len(updates)-len(filtered)).
|
||||||
|
Msg("updates retrieved from redis")
|
||||||
|
|
||||||
|
return filtered, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsonDatasToUpdates(datas []string) ([]*weather.WeatherUpdate, error) {
|
||||||
|
var errs error
|
||||||
|
updates := make([]*weather.WeatherUpdate, 0, len(datas))
|
||||||
|
|
||||||
|
for _, data := range datas {
|
||||||
|
update := new(weather.WeatherUpdate)
|
||||||
|
err := json.Unmarshal([]byte(data), update)
|
||||||
|
errs = errors.Join(errs, err)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
updates = append(updates, update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return slices.Clip(updates), errs
|
||||||
|
}
|
114
pkg/weather/recorder/recorders/redis/redis.go
Normal file
114
pkg/weather/recorder/recorders/redis/redis.go
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
package redis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
redis "github.com/redis/go-redis/v9"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DEF_RETAIN = 120
|
||||||
|
UPDATES_KEY = "weatherUpdates"
|
||||||
|
NAME = "redis recorder"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RedisRecorder struct {
|
||||||
|
baseCtx context.Context
|
||||||
|
tracer trace.Tracer
|
||||||
|
redis *redis.Client
|
||||||
|
config *config.AmbientLocalExporterConfig
|
||||||
|
log *zerolog.Logger
|
||||||
|
appKey string // prefix for redis keys, uses app name, environment, and version
|
||||||
|
keep int
|
||||||
|
*sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts) {
|
||||||
|
if opts.AppConfig.RecorderConfig.RedisConfig == nil {
|
||||||
|
panic("refusing to init redis recorder with no redisConfig")
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.RetainLast < 1 {
|
||||||
|
opts.RetainLast = DEF_RETAIN
|
||||||
|
}
|
||||||
|
|
||||||
|
r.config = opts.AppConfig
|
||||||
|
r.keep = opts.RetainLast
|
||||||
|
r.RWMutex = &sync.RWMutex{}
|
||||||
|
r.baseCtx = opts.BaseCtx
|
||||||
|
r.log = zerolog.Ctx(r.baseCtx)
|
||||||
|
|
||||||
|
r.tracer = otel.GetTracer(r.baseCtx, "redisRecorder")
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.init", trace.WithAttributes(
|
||||||
|
attribute.String("redisHost", opts.AppConfig.RecorderConfig.RedisConfig.RedisHost),
|
||||||
|
attribute.Int("retainLast", opts.RetainLast),
|
||||||
|
attribute.Int("redisPort", opts.AppConfig.RecorderConfig.RedisConfig.RedisPort),
|
||||||
|
attribute.Bool("tls", opts.AppConfig.RecorderConfig.RedisConfig.RedisTLS),
|
||||||
|
))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
// Unique key prefix for this version/env/name of exporter
|
||||||
|
// will be consistent across replicas, but resets on upgrade
|
||||||
|
// as it is using version
|
||||||
|
r.appKey = util.GetAppHash(r.config.AppConfig)
|
||||||
|
|
||||||
|
r.MustInitRedis(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) MustInitRedis(ctx context.Context) {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.init.redis")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
rc := r.config.RecorderConfig.RedisConfig
|
||||||
|
|
||||||
|
var tlsConfig *tls.Config
|
||||||
|
if rc.RedisTLS {
|
||||||
|
tlsConfig = &tls.Config{
|
||||||
|
ServerName: rc.RedisHost,
|
||||||
|
InsecureSkipVerify: rc.RedisTLSInsecure,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r.redis = redis.NewClient(&redis.Options{
|
||||||
|
Addr: fmt.Sprintf("%s:%d", rc.RedisHost, rc.RedisPort),
|
||||||
|
ClientName: fmt.Sprintf("%s-%s", r.config.Name, r.config.Environment),
|
||||||
|
Username: rc.RedisUser,
|
||||||
|
Password: rc.RedisPassword,
|
||||||
|
DB: rc.RedisDB,
|
||||||
|
TLSConfig: tlsConfig,
|
||||||
|
})
|
||||||
|
|
||||||
|
span.AddEvent("redis client ready")
|
||||||
|
|
||||||
|
resp := r.redis.Ping(ctx)
|
||||||
|
if resp.Err() != nil {
|
||||||
|
span.RecordError(resp.Err())
|
||||||
|
span.SetStatus(codes.Error, resp.Err().Error())
|
||||||
|
r.log.Fatal().Err(resp.Err()).Msg("failed to ping redis")
|
||||||
|
}
|
||||||
|
|
||||||
|
span.AddEvent("redis client ping ok")
|
||||||
|
span.SetStatus(codes.Ok, "")
|
||||||
|
|
||||||
|
r.log.Info().Str("appKey", r.appKey).
|
||||||
|
Msg("redis ping ok, client ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Key() string {
|
||||||
|
return fmt.Sprintf("%s:%s", r.appKey, UPDATES_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Name() string { return NAME }
|
74
pkg/weather/recorder/recorders/redis/set.go
Normal file
74
pkg/weather/recorder/recorders/redis/set.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package redis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/util"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *RedisRecorder) Set(ctx context.Context, u *weather.WeatherUpdate) error {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.set", trace.WithAttributes(
|
||||||
|
attribute.String("stationName", u.GetStationName()),
|
||||||
|
attribute.String("stationType", util.DerefStr(u.StationType)),
|
||||||
|
))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
r.Lock()
|
||||||
|
defer r.Unlock()
|
||||||
|
|
||||||
|
// First ensure we can prepare our payload
|
||||||
|
data, err := json.Marshal(u)
|
||||||
|
if err != nil {
|
||||||
|
span.RecordError(err)
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
|
||||||
|
r.log.Err(err).Send()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.set(ctx, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisRecorder) set(ctx context.Context, data []byte) error {
|
||||||
|
ctx, span := r.tracer.Start(ctx, "redisRecorder.set.push", trace.WithAttributes(
|
||||||
|
attribute.Int("updateBytes", len(data)),
|
||||||
|
))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
// Atomic, push and trim
|
||||||
|
var count *redis.IntCmd
|
||||||
|
rErr, err := r.redis.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||||
|
pipe.LPush(ctx, r.Key(), data)
|
||||||
|
pipe.LTrim(ctx, r.Key(), 0, int64(r.keep)-1)
|
||||||
|
count = pipe.LLen(ctx, r.Key())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
for _, cmd := range rErr {
|
||||||
|
span.RecordError(cmd.Err())
|
||||||
|
}
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
r.log.Err(err).Send()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get new update count
|
||||||
|
|
||||||
|
r.log.Debug().
|
||||||
|
Int("updateBytes", len(data)).
|
||||||
|
Int64("updateCount", count.Val()).
|
||||||
|
Str("redis", r.redis.String()).
|
||||||
|
Str("key", r.Key()).
|
||||||
|
Msg("pushed update to redis")
|
||||||
|
|
||||||
|
span.SetAttributes(attribute.Int64("updateCount", count.Val()))
|
||||||
|
span.SetStatus(codes.Ok, "")
|
||||||
|
return nil
|
||||||
|
}
|
@ -48,6 +48,7 @@ message WeatherUpdate {
|
|||||||
optional double dew_point_f = 25;
|
optional double dew_point_f = 25;
|
||||||
optional double wind_chill_f = 26;
|
optional double wind_chill_f = 26;
|
||||||
repeated TempHumiditySensor temp_humidity_sensors = 27;
|
repeated TempHumiditySensor temp_humidity_sensors = 27;
|
||||||
|
google.protobuf.Timestamp update_timestamp = 28;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents a temperature and humidity sensor
|
// Represents a temperature and humidity sensor
|
||||||
|
Reference in New Issue
Block a user