Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH 1451 #1454

Closed
wants to merge 5 commits into from
Closed

GH 1451 #1454

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,6 @@ local-test
.local-*

/artifacts/

# Python Virtual Env
**/venv
2 changes: 2 additions & 0 deletions scripts/integrations/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DEFAULT]
LICENSE = MIT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be apache 2.0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?
I'm less familiar with opensource licenses and regulations,
I've placed it just for default value concept and will change it to whatever needed :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apache-2.0 for compatibility with SPDX, but I agree.

96 changes: 96 additions & 0 deletions scripts/integrations/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import typer
import configparser
import json
import os
import sys
import shutil
from rich import print

app = typer.Typer()
dirs = ["assets", "info", "samples", "schema", "test"]


def createIntegrationDirs(directory, force):
if os.path.isdir(directory):
if force:
force = typer.confirm(
f"Are you sure you want to delete {directory}?")
if force:
shutil.rmtree(directory)
os.makedirs(directory)
for dir in dirs:
os.makedirs(os.path.join(directory, dir))
else:
print(f"[red]Directory {directory} already exists[/red]")
sys.exit(1)
else:
os.makedirs(directory)
for dir in dirs:
os.makedirs(os.path.join(directory, dir))


def populateDefaultVars(var_name):
config = configparser.ConfigParser()
config.read('config.ini')
return (config.get("DEFAULT", var_name))


def generateJson(directory, integration_name, integration_desc, schema, license):
data = {
"name": integration_name,
"version": {
"integ": "0.1.0",
"schema": schema,
"resource": "^1.23.0",
"license": license
},
"description": integration_desc,
"identification": "instrumentationScope.attributes.identification",
"categories": [],
"collection": [{}],
"repo": {
"github": "https://github.com/opensearch-project/observability/tree/main/integrarions/"+integration_name
}}

with open(os.path.join(directory, "config.json"), 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only be for local data dump - should we think about how can we add this globally, not just on this cluster? Automated way to create a PR, etc.?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derek-ho
Is that a design question for the team or something for me to rethink about?
ain't sure :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see design RFC



def error(txt):
print(txt)
sys.exit(1)


def main(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the general flow for this CLI would be as follows:

  • General: select the schema from a closed list
    For each collections:
  "collection":[
    {
      "logs": [{
        "info": "access logs",
        "input_type":"logfile",
        "dataset":"nginx.access",
        "labels" :["nginx","access"],
        "schema": "./schema/logs/access.json"
      },
...
  • Collections: select number of collections
  • For Each :
    • Select schema category for collection (sub folder in the schema )
    • input info, dataset , labels, schema
    • select input_type from a list given from file names (without suffixes ) under the schema folder

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where can I source the list of collections and their respective schemas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment ...

integration_name: str = typer.Option(
"", "--name", "-n", help="Your new integration name"),
integration_desc: str = typer.Option(
"", "--description", "-d", help="Your new integration description"),
license: str = typer.Option(populateDefaultVars(
"LICENSE"), "--license", "-l", help="Opensource license (e.g. Apache, MIT)"),
data_source: str = typer.Option(
"", "--data-source", "-s", help="The data source to ingest from, as well as which version(s) to support."),
schema: str = typer.Option(
"", "--schema", "-s", help="Which schema, and at which version, to use. The data will be ingested with this schema."),
catalog: str = typer.Option(
"", "--catalog", "-c", help="The specific catalog to target, such as `observability` or `security`."),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have an functionality that will scan the /schema folder and present the results for the customer to select from ?
see https://github.com/opensearch-project/observability/tree/2.6/schema

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part to scan in particular?
folder names? (e.g. metrics and traces) or something else?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the option to provide a checkout tag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the next PR has additional clarification on the catalog folder structure and information
see catalog.json

force: bool = typer.Option(
False, "--force", "-f", help="Force integration directoy removal and recreation")
):

directory = integration_name.lower().replace("_", "-")

createIntegrationDirs(directory, force)

generateJson(directory,
integration_name,
integration_desc,
schema, license)


if __name__ == "__main__":
if len(sys.argv) <= 1:
typer.run(
error("No options has been provided\nIf unsure, run again with --help\n"))
else:
typer.run(main)
6 changes: 6 additions & 0 deletions scripts/integrations/requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
click==8.1.3
markdown-it-py==2.2.0
mdurl==0.1.2
Pygments==2.14.0
rich==13.3.2
typer==0.7.0
Loading