Skip to content

Commit

Permalink
Included Authenticators (opensearch-project#988) (opensearch-project#…
Browse files Browse the repository at this point in the history
…1005)

Signed-off-by: vamsi-amazon <[email protected]>
Co-authored-by: vamsi-amazon <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and vmmusings authored Nov 1, 2022
1 parent 344aada commit 434aace
Show file tree
Hide file tree
Showing 31 changed files with 708 additions and 190 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -19,13 +20,11 @@ public class CatalogMetadata {
@JsonProperty(required = true)
private String name;

@JsonProperty(required = true)
private String uri;

@JsonProperty(required = true)
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
private ConnectorType connector;

private AbstractAuthenticationData authentication;
@JsonProperty(required = true)
private Map<String, String> properties;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* * Copyright OpenSearch Contributors
* * SPDX-License-Identifier: Apache-2.0
*
*/

package org.opensearch.sql.catalog.model.auth;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum AuthenticationType {

BASICAUTH("basicauth"), AWSSIGV4AUTH("awssigv4");

private String name;

private static final Map<String, AuthenticationType> ENUM_MAP;

AuthenticationType(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

static {
Map<String, AuthenticationType> map = new HashMap<>();
for (AuthenticationType instance : AuthenticationType.values()) {
map.put(instance.getName().toLowerCase(), instance);
}
ENUM_MAP = Collections.unmodifiableMap(map);
}

public static AuthenticationType get(String name) {
return ENUM_MAP.get(name.toLowerCase());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
*
* * Copyright OpenSearch Contributors
* * SPDX-License-Identifier: Apache-2.0
*
*/

package org.opensearch.sql.storage;

import java.util.Map;
import org.opensearch.sql.catalog.model.ConnectorType;

public interface StorageEngineFactory {

ConnectorType getConnectorType();

StorageEngine getStorageEngine(String catalogName, Map<String, String> requiredConfig);

}
31 changes: 14 additions & 17 deletions docs/user/ppl/admin/catalog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ Definitions of catalog and connector
Example Prometheus Catalog Definition ::

[{
"name" : "prometheus",
"name" : "my_prometheus",
"connector": "prometheus",
"uri" : "http://localhost:9090",
"authentication" : {
"type" : "basicauth",
"username" : "admin",
"password" : "admin"
"properties" : {
"prometheus.uri" : "http://localhost:8080",
"prometheus.auth.type" : "basicauth",
"prometheus.auth.username" : "admin",
"prometheus.auth.password" : "admin"
}
}]
Catalog configuration Restrictions.

* ``name``, ``uri``, ``connector`` are required fields in the catalog configuration.
* All the catalog names should be unique.
* Catalog names should match with the regex of an identifier[``[@*A-Za-z]+?[*a-zA-Z_\-0-9]*``].
* ``prometheus`` is the only connector allowed.
* ``name``, ``connector``, ``properties`` are required fields in the catalog configuration.
* All the catalog names should be unique and match the following regex[``[@*A-Za-z]+?[*a-zA-Z_\-0-9]*``].
* Allowed Connectors.
* ``prometheus`` [More details: `Prometheus Connector <prometheus_connector.rst>`_]
* All the allowed config parameters in ``properties`` are defined in individual connector pages mentioned above.

Configuring catalog in OpenSearch
====================================
Expand Down Expand Up @@ -73,14 +74,10 @@ so we can refer a metric and apply stats over it in the following way.

Example source command with prometheus catalog ::

>> source = prometheus.prometheus_http_requests_total | stats avg(@value) by job;
>> source = my_prometheus.prometheus_http_requests_total | stats avg(@value) by job;


Limitations of catalog
====================================
* Catalog settings are global and all PPL users are allowed to fetch data from all the defined catalogs.
* In each catalog, PPL users can access all the data available with the credentials provided in the catalog definition.
* With the current release, Basic and AWSSigV4 are the only authentication mechanisms supported with the underlying data sources.



Catalog settings are global and users with PPL access are allowed to fetch data from all the defined catalogs.
PPL access can be controlled using roles.(More details: `Security Settings <security.rst>`_)
74 changes: 74 additions & 0 deletions docs/user/ppl/admin/prometheus_connector.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.. highlight:: sh

====================
Prometheus Connector
====================

.. rubric:: Table of contents

.. contents::
:local:
:depth: 1


Introduction
============

This page covers prometheus connector properties for catalog configuration
and the nuances associated with prometheus connector.


Prometheus Connector Properties in Catalog Configuration
========================================================
Prometheus Connector Properties.

* ``prometheus.uri`` [Required].
* This parameters provides the URI information to connect to a prometheus instance.
* ``prometheus.auth.type`` [Optional]
* This parameters provides the authentication type information.
* Prometheus connector currently supports ``basicauth`` and ``awssigv4`` authentication mechanisms.
* If prometheus.auth.type is basicauth, following are required parameters.
* ``prometheus.auth.username`` and ``prometheus.auth.password``.
* If prometheus.auth.type is awssigv4, following are required parameters.
* ``prometheus.auth.region``, ``prometheus.auth.access_key`` and ``prometheus.auth.secret_key``

Example prometheus catalog configuration with different authentications
=======================================================================

No Auth ::

[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:9090"
}
}]

Basic Auth ::

[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:9090",
"prometheus.auth.type" : "basicauth",
"prometheus.auth.username" : "admin",
"prometheus.auth.password" : "admin"
}
}]

AWSSigV4 Auth::

[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:8080",
"prometheus.auth.type" : "awssigv4",
"prometheus.auth.region" : "us-east-1",
"prometheus.auth.access_key" : "{{accessKey}}"
"prometheus.auth.secret_key" : "{{secretKey}}"
}
}]

2 changes: 2 additions & 0 deletions docs/user/ppl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The query start with search command and then flowing a set of command delimited

- `Catalog Settings <admin/catalog.rst>`_

- `Prometheus Connector <admin/prometheus_connector.rst>`_

* **Commands**

- `Syntax <cmd/syntax.rst>`_
Expand Down
4 changes: 3 additions & 1 deletion doctest/catalog/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"name" : "my_prometheus",
"connector": "prometheus",
"uri" : "http://localhost:9090"
"properties" : {
"prometheus.uri" : "http://localhost:9090"
}
}
]
5 changes: 5 additions & 0 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ apply plugin: 'java'
apply plugin: 'io.freefair.lombok'
apply plugin: 'com.wiredforcode.spawn'

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

ext {
projectSubstitutions = [:]
Expand All @@ -63,6 +67,7 @@ configurations.all {
resolutionStrategy.force "com.fasterxml.jackson.core:jackson-databind:${jackson_databind_version}"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0"
resolutionStrategy.force "com.squareup.okhttp3:okhttp:4.9.3"
}

dependencies {
Expand Down
4 changes: 3 additions & 1 deletion integ-test/src/test/resources/catalog/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"name" : "my_prometheus",
"connector": "prometheus",
"uri" : "http://localhost:9090"
"properties" : {
"prometheus.uri" : "http://localhost:9090"
}
}
]
3 changes: 3 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ext {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

opensearchplugin {
Expand Down Expand Up @@ -91,6 +92,7 @@ configurations.all {
resolutionStrategy.force "com.fasterxml.jackson.core:jackson-databind:${jackson_databind_version}"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0"
resolutionStrategy.force "com.squareup.okhttp3:okhttp:4.9.3"
}
compileJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
Expand All @@ -106,6 +108,7 @@ dependencies {
api "com.fasterxml.jackson.core:jackson-databind:${jackson_databind_version}"
api "com.fasterxml.jackson.core:jackson-annotations:${jackson_version}"


api project(":ppl")
api project(':legacy')
api project(':opensearch')
Expand Down
Loading

0 comments on commit 434aace

Please sign in to comment.