Skip to content

Commit

Permalink
replace permission-search requests with device-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Sep 2, 2024
1 parent e512493 commit e5521cf
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 191 deletions.
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"auth_username": "",
"auth_password": "",

"permission_search_url": "https://api.senergy.infai.org/permissions/query",
"device_manager_url": "https://api.senergy.infai.org/device-manager",
"device_repository_url": "https://api.senergy.infai.org/device-repository",
"connector_mqtt_broker_url": "tcp://connector.senergy.infai.org:2883",
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/SENERGY-Platform/snowflake-canary

go 1.22
go 1.23

toolchain go1.23.0

require (
github.com/SENERGY-Platform/device-repository v0.0.30
github.com/SENERGY-Platform/models/go v0.0.0-20240627082833-157bd627a94f
github.com/SENERGY-Platform/permission-search v0.0.16
github.com/SENERGY-Platform/device-repository v0.1.13
github.com/SENERGY-Platform/models/go v0.0.0-20240829060132-21bc8cc47937
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/google/uuid v1.6.0
github.com/prometheus/client_golang v1.19.1
Expand All @@ -17,7 +18,8 @@ require (
github.com/IBM/sarama v1.43.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.4 // indirect
github.com/SENERGY-Platform/service-commons v0.0.0-20240708085423-94423a495d7f // indirect
github.com/SENERGY-Platform/permission-search v0.0.22 // indirect
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/Rr4=
github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ=
github.com/SENERGY-Platform/device-repository v0.0.30 h1:ro01JKwlkjH6AX8tTQqa21cTVPELqdEl0GraT8Od3DU=
github.com/SENERGY-Platform/device-repository v0.0.30/go.mod h1:5FPODq2Hs8V9AcjSkAUrCUvuN6nU0ARM0Jq/s6IP/78=
github.com/SENERGY-Platform/models/go v0.0.0-20240627082833-157bd627a94f h1:nFZkMoKp6RtsbYijj071sVQ3uZqloDILMWCIDaInUSI=
github.com/SENERGY-Platform/models/go v0.0.0-20240627082833-157bd627a94f/go.mod h1:bCREPNRN4P8oxLgpC3/ZKK4jXSy4MSPXoiomhohE+aw=
github.com/SENERGY-Platform/permission-search v0.0.16 h1:MhKNr9Fnwcf50AguaSb8697ScD0iNw/Tkk1L1ccZnP0=
github.com/SENERGY-Platform/permission-search v0.0.16/go.mod h1:b2ckm6kM+XuDBZxx+cdv6YbM6SRk2EJi7Ny5ffTWhfc=
github.com/SENERGY-Platform/service-commons v0.0.0-20240708085423-94423a495d7f h1:5DpZzncRU3bV9pd/0NgysOLGcGWpKH1AKNLCsFYdw4c=
github.com/SENERGY-Platform/service-commons v0.0.0-20240708085423-94423a495d7f/go.mod h1:1p2CQPNtler5leXqNgaOfr7DlgZUydrQlQYA97ycm4k=
github.com/SENERGY-Platform/device-repository v0.1.13 h1:SU9FtnBOgFqx2hCGfqvAJM16dWNzxz+yOmQykPvGbe8=
github.com/SENERGY-Platform/device-repository v0.1.13/go.mod h1:iyyi5GRb5OrTGDH5UsMnRgWiVRRsJi/Y6rieNL5aAM8=
github.com/SENERGY-Platform/models/go v0.0.0-20240829060132-21bc8cc47937 h1:rVwsIxEOG2xVqVyiYQVZPZYuRc/J92SyFxyzPaVqbsM=
github.com/SENERGY-Platform/models/go v0.0.0-20240829060132-21bc8cc47937/go.mod h1:bCREPNRN4P8oxLgpC3/ZKK4jXSy4MSPXoiomhohE+aw=
github.com/SENERGY-Platform/permission-search v0.0.22 h1:VfgLspYQUg9P4BTIPhGniTsStGHiWs0S5HYrpm5QY/Y=
github.com/SENERGY-Platform/permission-search v0.0.22/go.mod h1:b2ckm6kM+XuDBZxx+cdv6YbM6SRk2EJi7Ny5ffTWhfc=
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc h1:FbGDfHiDukp8wD1w4YNxjwiDpSNkRUG+Ymq9jjz3Auc=
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc/go.mod h1:1p2CQPNtler5leXqNgaOfr7DlgZUydrQlQYA97ycm4k=
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
6 changes: 1 addition & 5 deletions pkg/canary/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package canary
import (
"context"
devicerepo "github.com/SENERGY-Platform/device-repository/lib/client"
"github.com/SENERGY-Platform/permission-search/lib/client"
"github.com/SENERGY-Platform/snowflake-canary/pkg/configuration"
"github.com/SENERGY-Platform/snowflake-canary/pkg/devicemetadata"
"github.com/SENERGY-Platform/snowflake-canary/pkg/events"
Expand All @@ -40,7 +39,6 @@ type Canary struct {
promHttpHandler http.Handler
isRunningMux sync.Mutex
isRunning bool
permissions client.Client
guaranteeChangeAfter time.Duration
devicerepo devicerepo.Interface
process Process
Expand All @@ -55,8 +53,7 @@ func New(ctx context.Context, wg *sync.WaitGroup, config configuration.Config) (
m := metrics.NewMetrics(reg)

d := devicerepo.NewClient(config.DeviceRepositoryUrl)
permissions := client.NewClient(config.PermissionSearchUrl)
devicemeta := devicemetadata.NewDeviceMetaData(permissions, d, m, config, guaranteeChangeAfter)
devicemeta := devicemetadata.NewDeviceMetaData(d, m, config, guaranteeChangeAfter)

p := process.New(config, d, m, guaranteeChangeAfter)

Expand All @@ -66,7 +63,6 @@ func New(ctx context.Context, wg *sync.WaitGroup, config configuration.Config) (
reg: reg,
metrics: m,
config: config,
permissions: permissions,
devicerepo: d,
guaranteeChangeAfter: guaranteeChangeAfter,
devicemeta: devicemeta,
Expand Down
26 changes: 5 additions & 21 deletions pkg/canary/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/SENERGY-Platform/permission-search/lib/client"
"github.com/SENERGY-Platform/permission-search/lib/model"
"github.com/SENERGY-Platform/device-repository/lib/model"
"github.com/SENERGY-Platform/models/go/models"
"github.com/SENERGY-Platform/snowflake-canary/pkg/configuration"
"github.com/SENERGY-Platform/snowflake-canary/pkg/devicemetadata"
paho "github.com/eclipse/paho.mqtt.golang"
Expand All @@ -39,31 +39,15 @@ type PermDevice = devicemetadata.PermDevice
func (this *Canary) checkDeviceConnState(token string, info DeviceInfo, expectedConnState bool) {
this.metrics.PermissionsRequestCount.Inc()
start := time.Now()
result, _, err := client.Query[[]PermDevice](this.permissions, token, client.QueryMessage{
Resource: "devices",
ListIds: &client.QueryListIds{
QueryListCommons: model.QueryListCommons{
Limit: 1,
Offset: 0,
Rights: "r",
},
Ids: []string{info.Id},
},
})
device, err, _ := this.devicerepo.ReadExtendedDevice(info.Id, token, model.READ)
this.metrics.PermissionsRequestLatencyMs.Set(float64(time.Since(start).Milliseconds()))
if err != nil {
log.Println("ERROR: checkDeviceConnState()", err)
this.metrics.PermissionsRequestErr.Inc()
return
}
if len(result) == 0 {
this.metrics.UncategorizedErr.Inc()
log.Printf("Unexpected conn state result: \n%#v\n", result)
debug.PrintStack()
return
}
if result[0].Annotations["connected"] != expectedConnState {
log.Printf("Unexpected permissions device state: annotation(%#v) != expected(%#v)\n", result[0].Annotations["connected"], expectedConnState)
if (device.ConnectionState == models.ConnectionStateOnline) != expectedConnState {
log.Printf("Unexpected device donnection-state: actual(%#v); expected(connected=%#v)\n", device.ConnectionState, expectedConnState)
if expectedConnState {
this.metrics.UnexpectedPermissionsDeviceOfflineStateErr.Inc()
} else {
Expand Down
32 changes: 14 additions & 18 deletions pkg/canary/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package canary
import (
"bytes"
"encoding/json"
"github.com/SENERGY-Platform/permission-search/lib/client"
"github.com/SENERGY-Platform/device-repository/lib/client"
"github.com/SENERGY-Platform/snowflake-canary/pkg/devicemetadata"
"log"
"net/http"
Expand Down Expand Up @@ -64,30 +64,26 @@ type HubInfo struct {

func (this *Canary) listCanaryHubs(token string) (hubs []HubInfo, err error) {
start := time.Now()
hubs, _, err = client.Query[[]HubInfo](this.permissions, token, client.QueryMessage{
Resource: "hubs",
Find: &client.QueryFind{
QueryListCommons: client.QueryListCommons{
Limit: 1,
Offset: 0,
Rights: "w",
SortBy: "name",
},
Filter: &client.Selection{
Condition: client.ConditionConfig{
Feature: "features.name",
Operation: client.QueryEqualOperation,
Value: this.config.CanaryHubName,
},
},
},
temp, err, _ := this.devicerepo.ListHubs(token, client.HubListOptions{
Search: this.config.CanaryHubName,
Limit: 1,
Offset: 0,
})
this.metrics.PermissionsRequestCount.Inc()
this.metrics.PermissionsRequestLatencyMs.Set(float64(time.Since(start).Milliseconds()))
if err != nil {
this.metrics.PermissionsRequestErr.Inc()
log.Println("ERROR:", err)
debug.PrintStack()
return hubs, err
}
for _, hub := range temp {
hubs = append(hubs, HubInfo{
Id: hub.Id,
Name: hub.Name,
DeviceIds: hub.DeviceIds,
DeviceLocalIds: hub.DeviceLocalIds,
})
}
return hubs, err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Config struct {
AuthUsername string `json:"auth_username" config:"secret"`
AuthPassword string `json:"auth_password" config:"secret"`

PermissionSearchUrl string `json:"permission_search_url"`
DeviceManagerUrl string `json:"device_manager_url"`
DeviceRepositoryUrl string `json:"device_repository_url"`
ConnectorMqttBrokerUrl string `json:"connector_mqtt_broker_url"`
Expand Down
Loading

0 comments on commit e5521cf

Please sign in to comment.