-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a site locations exporter to Mentix (#972)
- Loading branch information
1 parent
78953c2
commit 5a9dab8
Showing
18 changed files
with
240 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Added a site locations exporter to Mentix. | ||
|
||
Mentix now offers an endpoint that exposes location information of all sites in the mesh. This can be used in Grafana's world map view to show the exact location of every site. | ||
|
||
https://github.com/cs3org/reva/pull/972 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
docs/content/en/docs/config/http/services/mentix/siteloc/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: "siteloc" | ||
linkTitle: "siteloc" | ||
weight: 10 | ||
description: > | ||
Configuration for the Site Locations exporter of the Mentix service | ||
--- | ||
|
||
{{% pageinfo %}} | ||
The Site Locations exporter exposes location information of all sites to be consumed by Grafana via an HTTP endpoint. | ||
{{% /pageinfo %}} | ||
|
||
{{% dir name="endpoint" type="string" default="/" %}} | ||
The endpoint where the locations data can be queried. | ||
{{< highlight toml >}} | ||
[http.services.mentix.siteloc] | ||
endpoint = "/loc" | ||
{{< /highlight >}} | ||
{{% /dir %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2018-2020 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package siteloc | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/cs3org/reva/pkg/mentix/meshdata" | ||
) | ||
|
||
// HandleDefaultQuery processes a basic query. | ||
func HandleDefaultQuery(meshData *meshdata.MeshData, params url.Values) ([]byte, error) { | ||
// Convert the mesh data | ||
locData, err := convertMeshDataToLocationData(meshData) | ||
if err != nil { | ||
return []byte{}, fmt.Errorf("unable to convert the mesh data to location data: %v", err) | ||
} | ||
|
||
// Marshal the location data as JSON | ||
data, err := json.MarshalIndent(locData, "", "\t") | ||
if err != nil { | ||
return []byte{}, fmt.Errorf("unable to marshal the location data: %v", err) | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
func convertMeshDataToLocationData(meshData *meshdata.MeshData) ([]*SiteLocation, error) { | ||
// Gather the locations of all sites | ||
locations := make([]*SiteLocation, 0, len(meshData.Sites)) | ||
for _, site := range meshData.Sites { | ||
locations = append(locations, &SiteLocation{ | ||
Site: site.Name, | ||
FullName: site.FullName, | ||
Longitude: site.Longitude, | ||
Latitude: site.Latitude, | ||
}) | ||
} | ||
|
||
return locations, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2018-2020 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package siteloc | ||
|
||
// SiteLocation represents the location information of a site. | ||
type SiteLocation struct { | ||
Site string `json:"key"` | ||
FullName string `json:"name"` | ||
Longitude float32 `json:"longitude"` | ||
Latitude float32 `json:"latitude"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2018-2020 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package exporters | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
|
||
"github.com/cs3org/reva/pkg/mentix/config" | ||
"github.com/cs3org/reva/pkg/mentix/exporters/siteloc" | ||
) | ||
|
||
// SiteLocationsExporter implements the Site Locations exporter to use with Grafana. | ||
type SiteLocationsExporter struct { | ||
BaseRequestExporter | ||
} | ||
|
||
// Activate activates the exporter. | ||
func (exporter *SiteLocationsExporter) Activate(conf *config.Configuration, log *zerolog.Logger) error { | ||
if err := exporter.BaseExporter.Activate(conf, log); err != nil { | ||
return err | ||
} | ||
|
||
// Store SiteLocations specifics | ||
exporter.endpoint = conf.SiteLocations.Endpoint | ||
exporter.defaultMethodHandler = siteloc.HandleDefaultQuery | ||
|
||
return nil | ||
} | ||
|
||
// GetName returns the display name of the exporter. | ||
func (exporter *SiteLocationsExporter) GetName() string { | ||
return "Site Locations" | ||
} | ||
|
||
func init() { | ||
registerExporter(config.ExporterIDSiteLocations, &SiteLocationsExporter{}) | ||
} |
Oops, something went wrong.