forked from cs3org/reva
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7df77d1
commit 05e7746
Showing
39 changed files
with
1,784 additions
and
13 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
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ | |
- Mohitty <[email protected]> | ||
- Thomas Boerger <[email protected]> | ||
- Miroslav Bauer <[email protected]> | ||
- Daniel Mueller <[email protected]> |
27 changes: 27 additions & 0 deletions
27
docs/content/en/docs/Config/HTTP/Services/Mentix/GOCDB/_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,27 @@ | ||
--- | ||
title: "gocdb" | ||
linkTitle: "gocdb" | ||
weight: 10 | ||
description: > | ||
Configuration for the GOCDB connector of the Mentix service | ||
--- | ||
|
||
{{% pageinfo %}} | ||
When using the [GOCDB](https://wiki.egi.eu/wiki/GOCDB/Documentation_Index) connector, at least its address has to be configured. | ||
{{% /pageinfo %}} | ||
|
||
{{% dir name="address" type="string" default="" %}} | ||
The address of the GOCDB instance; must be a valid URL (e.g., http://gocdb.uni-muenster.de). **Note:** The public API must be reachable under `<address>/gocdbpi/public`. | ||
{{< highlight toml >}} | ||
[http.services.mentix.gocdb] | ||
address = "http://gocdb.example.com" | ||
{{< /highlight >}} | ||
{{% /dir %}} | ||
|
||
{{% dir name="scope" type="string" default="SM" %}} | ||
The scope to use for filtering sites and services. | ||
{{< highlight toml >}} | ||
[http.services.mentix.gocdb] | ||
scope = "SM" | ||
{{< /highlight >}} | ||
{{% /dir %}} |
19 changes: 19 additions & 0 deletions
19
docs/content/en/docs/Config/HTTP/Services/Mentix/PromFileSD/_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: "prom_filesd" | ||
linkTitle: "prom_filesd" | ||
weight: 10 | ||
description: > | ||
Configuration for the Prometheus File SD exporter of the Mentix service | ||
--- | ||
|
||
{{% pageinfo %}} | ||
When using the Prometheus File SD exporter, the output filename has to be configured first. | ||
{{% /pageinfo %}} | ||
|
||
{{% dir name="output_file" type="string" default="" %}} | ||
The target filename of the generated Prometheus File SD scrape config. | ||
{{< highlight toml >}} | ||
[http.services.mentix.prom_filesd] | ||
output_file = "/var/shared/prometheus/sciencemesh.json" | ||
{{< /highlight >}} | ||
{{% /dir %}} |
19 changes: 19 additions & 0 deletions
19
docs/content/en/docs/Config/HTTP/Services/Mentix/WebAPI/_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: "webapi" | ||
linkTitle: "webapi" | ||
weight: 10 | ||
description: > | ||
Configuration for the WebAPI of the Mentix service | ||
--- | ||
|
||
{{% pageinfo %}} | ||
The WebAPI exporter supports multiple endpoints for exporting data. As there currently is only one such endpoint, the WebAPI settings should not be modified. | ||
{{% /pageinfo %}} | ||
|
||
{{% dir name="endpoint" type="string" default="/" %}} | ||
The endpoint where the mesh data can be queried. | ||
{{< highlight toml >}} | ||
[http.services.mentix.webapi] | ||
endpoint = "data" | ||
{{< /highlight >}} | ||
{{% /dir %}} |
63 changes: 63 additions & 0 deletions
63
docs/content/en/docs/Config/HTTP/Services/Mentix/_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,63 @@ | ||
--- | ||
title: "mentix" | ||
linkTitle: "mentix" | ||
weight: 10 | ||
description: > | ||
Configuration for the Mentix service | ||
--- | ||
|
||
{{% pageinfo %}} | ||
Mentix (_**Me**sh E**nti**ty E**x**porter_) is a service to read mesh topology data from a source (e.g., a GOCDB instance) and export it to various targets like an HTTP endpoint or Prometheus. | ||
{{% /pageinfo %}} | ||
|
||
{{% dir name="prefix" type="string" default="mentix" %}} | ||
The relative root path of all exposed HTTP endpoints of Mentix. | ||
{{< highlight toml >}} | ||
[http.services.mentix] | ||
prefix = "/mentix" | ||
{{< /highlight >}} | ||
{{% /dir %}} | ||
|
||
{{% dir name="connector" type="string" default="gocdb" %}} | ||
Mentix is decoupled from the actual source of the mesh data by using a so-called _connector_. A connector is used to gather the data from a certain source, which are then converted into Mentix' own internal format. | ||
|
||
Supported values are: | ||
|
||
- **gocdb** | ||
The [GOCDB](https://wiki.egi.eu/wiki/GOCDB/Documentation_Index) is a database specifically designed to organize the topology of a mesh of distributed sites and services. In order to use GOCDB with Mentix, its instance address has to be configured (see [here](gocdb)). | ||
|
||
{{< highlight toml >}} | ||
[http.services.mentix] | ||
connector = "gocdb" | ||
{{< /highlight >}} | ||
{{% /dir %}} | ||
|
||
{{% dir name="exporters" type="[]string" default="[webapi,prom_filesd]" %}} | ||
Mentix exposes its gathered data by using one or more _exporters_. Such exporters can, for example, write the data to a file in a specific format, or offer the data via an HTTP endpoint. | ||
|
||
Supported values are: | ||
|
||
- **webapi** | ||
Mentix exposes its data via an HTTP endpoint using the `webapi` exporter. Data can be retrieved at the configured relative endpoint (see [here](webapi)). The web API currently doesn't support any parameters but will most likely be extended in the future. | ||
- **prom_filesd** | ||
[Prometheus](https://prometheus.io/) supports discovering new services it should monitor via external configuration files (hence, this is called _file-based service discovery_). Mentix can create such files using the `prom_filesd` exporter. To use this exporter, you have to specify the target output file in the configuration (see [here](prom_filesd)). You also have to set up the discovery service in Prometheus by adding a scrape configuration like the following example to the Prometheus configuration (for more information, visit the official [Prometheus documentation](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config)): | ||
``` scrape_configs: | ||
- job_name: 'sciencemesh' | ||
file_sd_configs: | ||
- files: | ||
- '/usr/share/prom/sciencemesh_services.json' | ||
``` | ||
|
||
{{< highlight toml >}} | ||
[http.services.mentix] | ||
exporters = ["webapi", "prom_filesd"] | ||
{{< /highlight >}} | ||
{{% /dir %}} | ||
|
||
{{% dir name="update_interval" type="string" default="1h" %}} | ||
How frequently Mentix should pull and update the mesh data. Supports common time duration strings, like "1h30m", "1d" etc. | ||
{{< highlight toml >}} | ||
[http.services.mentix] | ||
update_interval = "15m" | ||
{{< /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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[shared] | ||
jwt_secret = "Ment1x-T0pS3cr3t" | ||
|
||
[http] | ||
address = "0.0.0.0:9600" | ||
enabled_services = ["mentix"] | ||
|
||
[http.services.mentix] | ||
connector = "gocdb" | ||
exporters = ["webapi"] | ||
# Enable the Prometheus File Service Discovery: | ||
# exporters = ["webapi", "prom_filesd"] | ||
update_interval = "15m" | ||
|
||
[http.services.mentix.gocdb] | ||
address = "http://sciencemesh-test.uni-muenster.de" | ||
|
||
[http.services.mentix.webapi] | ||
endpoint = "/" | ||
|
||
# Configure the Prometheus File Service Discovery: | ||
# [http.services.mentix.prom_filesd] | ||
# Prometheus must be configured to read the following file: | ||
# output_file = "/usr/share/prom/sciencemesh_services.json" |
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,146 @@ | ||
// 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 mentix | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"github.com/pkg/errors" | ||
"github.com/rs/zerolog" | ||
|
||
"github.com/cs3org/reva/pkg/mentix" | ||
"github.com/cs3org/reva/pkg/mentix/config" | ||
"github.com/cs3org/reva/pkg/mentix/exporters" | ||
"github.com/cs3org/reva/pkg/rhttp/global" | ||
) | ||
|
||
func init() { | ||
global.Register(serviceName, New) | ||
} | ||
|
||
type svc struct { | ||
conf *config.Configuration | ||
mntx *mentix.Mentix | ||
log *zerolog.Logger | ||
|
||
stopSignal chan struct{} | ||
} | ||
|
||
const ( | ||
serviceName = "mentix" | ||
) | ||
|
||
func (s *svc) Close() error { | ||
// Trigger and close the stopSignal signal channel to stop Mentix | ||
s.stopSignal <- struct{}{} | ||
close(s.stopSignal) | ||
|
||
return nil | ||
} | ||
|
||
func (s *svc) Prefix() string { | ||
return s.conf.Prefix | ||
} | ||
|
||
func (s *svc) Unprotected() []string { | ||
// Get all endpoints exposed by the RequestExporters | ||
exporters := s.mntx.GetRequestExporters() | ||
endpoints := make([]string, len(exporters)) | ||
for _, exporter := range exporters { | ||
endpoints = append(endpoints, exporter.Endpoint()) | ||
} | ||
return endpoints | ||
} | ||
|
||
func (s *svc) Handler() http.Handler { | ||
// Forward requests to Mentix | ||
return http.HandlerFunc(s.mntx.RequestHandler) | ||
} | ||
|
||
func (s *svc) startBackgroundService() { | ||
// Just run Mentix in the background | ||
go func() { | ||
if err := s.mntx.Run(s.stopSignal); err != nil { | ||
s.log.Err(err).Msg("error while running mentix") | ||
} | ||
}() | ||
} | ||
|
||
func parseConfig(m map[string]interface{}) (*config.Configuration, error) { | ||
cfg := &config.Configuration{} | ||
if err := mapstructure.Decode(m, &cfg); err != nil { | ||
return nil, errors.Wrap(err, "mentix: error decoding configuration") | ||
} | ||
applyDefaultConfig(cfg) | ||
return cfg, nil | ||
} | ||
|
||
func applyDefaultConfig(*config.Configuration) { | ||
conf := &config.Configuration{} | ||
|
||
if conf.Prefix == "" { | ||
conf.Prefix = serviceName | ||
} | ||
|
||
if conf.Connector == "" { | ||
conf.Connector = config.ConnectorIDGOCDB // Use GOCDB | ||
} | ||
|
||
if len(conf.Exporters) == 0 { | ||
conf.Exporters = exporters.RegisteredExporterIDs() // Enable all exporters | ||
} | ||
|
||
if conf.UpdateInterval == "" { | ||
conf.UpdateInterval = "1h" // Update once per hour | ||
} | ||
|
||
if conf.GOCDB.Scope == "" { | ||
conf.GOCDB.Scope = "SM" // TODO(Daniel-WWU-IT): This might change in the future | ||
} | ||
|
||
if conf.WebAPI.Endpoint == "" { | ||
conf.WebAPI.Endpoint = "/" | ||
} | ||
} | ||
|
||
// New returns a new Mentix service. | ||
func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) { | ||
// Prepare the configuration | ||
conf, err := parseConfig(m) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Create the Mentix instance | ||
mntx, err := mentix.New(conf, log) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "mentix: error creating Mentix") | ||
} | ||
|
||
// Create the service and start its background activity | ||
s := &svc{ | ||
conf: conf, | ||
mntx: mntx, | ||
log: log, | ||
stopSignal: make(chan struct{}), | ||
} | ||
s.startBackgroundService() | ||
return s, nil | ||
} |
Oops, something went wrong.