Skip to content

Commit

Permalink
feat: use InfluxDB OSS API definitions to generated APIs (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored May 28, 2021
1 parent 3235d4e commit f851303
Show file tree
Hide file tree
Showing 279 changed files with 9,053 additions and 5,586 deletions.
20 changes: 19 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
default: &default-python "circleci/python:3.6-buster"
influxdb-image:
type: string
default: "influxdb:latest"
default: &default-influxdb "influxdb:latest"
enabled-ciso-8601:
type: boolean
default: true
Expand Down Expand Up @@ -108,6 +108,23 @@ jobs:
command: |
pip install pydocstyle --user
pydocstyle --count influxdb_client
check-examples:
docker:
- image: *default-python
environment:
PIPENV_VENV_IN_PROJECT: true
- image: *default-influxdb
environment:
INFLUXD_HTTP_BIND_ADDRESS: :8086
steps:
- prepare
- run:
name: Checks that examples are runnable
command: |
pip install -e . --user
export PYTHONPATH="$PWD"
python examples/monitoring_and_alerting.py
python examples/buckets_management.py
check-aws-lambda-layer:
docker:
- image: docker:19
Expand All @@ -129,6 +146,7 @@ workflows:
- check-code-style
- check-docstyle
- check-twine
- check-examples
- tests-python:
name: test-3.6
- tests-python:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
## 1.18.0 [unreleased]

### Breaking Changes

This release introduces a support for new InfluxDB OSS API definitions - [oss.yml](https://github.com/influxdata/openapi/blob/master/contracts/oss.yml). The following breaking changes are in underlying API services and doesn't affect common apis such as - `WriteApi`, `QueryApi`, `BucketsApi`, `OrganizationsApi`...
- `AuthorizationsService` uses `AuthorizationPostRequest` to create `Authorization`
- `BucketsService` uses `PatchBucketRequest` to update `Bucket`
- `DashboardsService` uses `PatchDashboardRequest` to update `Dashboard`
- `DeleteService` is used to delete tome series date instead of `DefaultService`
- `DBRPs` contains list of `DBRP` in `content` property
- `OrganizationsService` uses `PostOrganizationRequest` to create `Organization`
- `Run` contains list of `LogEvent` in `log` property
- `OrganizationsService` uses `PatchOrganizationRequest` to update `Organization`
- `OnboardingResponse` uses `UserResponse` as `user` property
- `ResourceMember` and `ResourceOwner` inherits from `UserResponse`
- `Users` contains list of `UserResponse` in `users` property
- `UsersService` uses `UserResponse` as a response to requests

### Features
1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination.
1. [#241](https://github.com/influxdata/influxdb-client-python/pull/241): Add detail error message for not supported type of `Point.field`
Expand All @@ -12,6 +28,9 @@
### Documentation
1. [#255](https://github.com/influxdata/influxdb-client-python/pull/255): Fix invalid description for env var `INFLUXDB_V2_CONNECTION_POOL_MAXSIZE`

### API
1. [#261](https://github.com/influxdata/influxdb-client-python/pull/261): Use InfluxDB OSS API definitions to generated APIs

## 1.17.0 [2021-04-30]

### Features
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

## Management API
- [buckets_management.py](buckets_management.py) - How to create, list and delete Buckets
- [monitoring_and_alerting.py](monitoring_and_alerting.py) - How to create the Check with Slack notification.

## Others
- [influx_cloud.py](influx_cloud.py) - How to connect to InfluxDB 2 Cloud
Expand Down
121 changes: 121 additions & 0 deletions examples/monitoring_and_alerting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
How to create a check with Slack notification.
"""
import datetime

from influxdb_client.service.notification_rules_service import NotificationRulesService

from influxdb_client.domain.rule_status_level import RuleStatusLevel

from influxdb_client.domain.status_rule import StatusRule

from influxdb_client.domain.slack_notification_rule import SlackNotificationRule

from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.domain.check_status_level import CheckStatusLevel
from influxdb_client.domain.dashboard_query import DashboardQuery
from influxdb_client.domain.lesser_threshold import LesserThreshold
from influxdb_client.domain.query_edit_mode import QueryEditMode
from influxdb_client.domain.slack_notification_endpoint import SlackNotificationEndpoint
from influxdb_client.domain.task_status_type import TaskStatusType
from influxdb_client.domain.threshold_check import ThresholdCheck
from influxdb_client.service.checks_service import ChecksService
from influxdb_client.service.notification_endpoints_service import NotificationEndpointsService

"""
Define credentials
"""
url = "http://localhost:8086"
token = "my-token"
org_name = "my-org"
bucket_name = "my-bucket"


with InfluxDBClient(url=url, token=token, org=org_name, debug=False) as client:
uniqueId = str(datetime.datetime.now())

"""
Find Organization ID by Organization API.
"""
org = client.organizations_api().find_organizations(org=org_name)[0]

"""
Prepare data
"""
client.write_api(write_options=SYNCHRONOUS).write(record="mem,production=true free=40", bucket=bucket_name)

"""
Create Threshold Check - set status to `Critical` if the current value is lesser than `35`.
"""
threshold = LesserThreshold(value=35.0,
level=CheckStatusLevel.CRIT)
query = f'''
from(bucket:"{bucket_name}")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mem")
|> filter(fn: (r) => r["_field"] == "free")
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
|> yield(name: "mean")
'''

check = ThresholdCheck(name=f"Check created by Remote API_{uniqueId}",
status_message_template="The value is on: ${ r._level } level!",
every="5s",
offset="0s",
query=DashboardQuery(edit_mode=QueryEditMode.ADVANCED, text=query),
thresholds=[threshold],
org_id=org.id,
status=TaskStatusType.ACTIVE)

checks_service = ChecksService(api_client=client.api_client)
checks_service.create_check(check)

"""
Create Slack Notification endpoint
"""
notification_endpoint = SlackNotificationEndpoint(name=f"Slack Dev Channel_{uniqueId}",
url="https://hooks.slack.com/services/x/y/z",
org_id=org.id)
notification_endpoint_service = NotificationEndpointsService(api_client=client.api_client)
notification_endpoint = notification_endpoint_service.create_notification_endpoint(notification_endpoint)

"""
Create Notification Rule to notify critical value to Slack Channel
"""
notification_rule = SlackNotificationRule(name=f"Critical status to Slack_{uniqueId}",
every="10s",
offset="0s",
message_template="${ r._message }",
status_rules=[StatusRule(current_level=RuleStatusLevel.CRIT)],
tag_rules=[],
endpoint_id=notification_endpoint.id,
org_id=org.id,
status=TaskStatusType.ACTIVE)

notification_rules_service = NotificationRulesService(api_client=client.api_client)
notification_rules_service.create_notification_rule(notification_rule)

"""
List all Checks
"""
print(f"\n------- Checks: -------\n")
checks = checks_service.get_checks(org_id=org.id).checks
print("\n".join([f" ---\n ID: {it.id}\n Name: {it.name}\n Type: {type(it)}" for it in checks]))
print("---")

"""
List all Endpoints
"""
print(f"\n------- Notification Endpoints: -------\n")
notification_endpoints = notification_endpoint_service.get_notification_endpoints(org_id=org.id).notification_endpoints
print("\n".join([f" ---\n ID: {it.id}\n Name: {it.name}\n Type: {type(it)}" for it in notification_endpoints]))
print("---")

"""
List all Notification Rules
"""
print(f"\n------- Notification Rules: -------\n")
notification_rules = notification_rules_service.get_notification_rules(org_id=org.id).notification_rules
print("\n".join([f" ---\n ID: {it.id}\n Name: {it.name}\n Type: {type(it)}" for it in notification_rules]))
print("---")
34 changes: 27 additions & 7 deletions influxdb_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# flake8: noqa

"""
Influx API Service.
Influx OSS API Service.
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
OpenAPI spec version: 0.1.0
OpenAPI spec version: 2.0.0
Generated by: https://openapi-generator.tech
"""

Expand All @@ -21,6 +21,7 @@
from influxdb_client.service.checks_service import ChecksService
from influxdb_client.service.dbr_ps_service import DBRPsService
from influxdb_client.service.dashboards_service import DashboardsService
from influxdb_client.service.delete_service import DeleteService
from influxdb_client.service.health_service import HealthService
from influxdb_client.service.labels_service import LabelsService
from influxdb_client.service.notification_endpoints_service import NotificationEndpointsService
Expand Down Expand Up @@ -52,19 +53,22 @@
from influxdb_client.domain.analyze_query_response_errors import AnalyzeQueryResponseErrors
from influxdb_client.domain.array_expression import ArrayExpression
from influxdb_client.domain.authorization import Authorization
from influxdb_client.domain.authorization_post_request import AuthorizationPostRequest
from influxdb_client.domain.authorization_update_request import AuthorizationUpdateRequest
from influxdb_client.domain.authorizations import Authorizations
from influxdb_client.domain.axes import Axes
from influxdb_client.domain.axis import Axis
from influxdb_client.domain.axis_scale import AxisScale
from influxdb_client.domain.bad_statement import BadStatement
from influxdb_client.domain.band_view_properties import BandViewProperties
from influxdb_client.domain.binary_expression import BinaryExpression
from influxdb_client.domain.block import Block
from influxdb_client.domain.boolean_literal import BooleanLiteral
from influxdb_client.domain.bucket import Bucket
from influxdb_client.domain.bucket_links import BucketLinks
from influxdb_client.domain.bucket_retention_rules import BucketRetentionRules
from influxdb_client.domain.buckets import Buckets
from influxdb_client.domain.builder_aggregate_function_type import BuilderAggregateFunctionType
from influxdb_client.domain.builder_config import BuilderConfig
from influxdb_client.domain.builder_config_aggregate_window import BuilderConfigAggregateWindow
from influxdb_client.domain.builder_functions_type import BuilderFunctionsType
Expand All @@ -74,10 +78,10 @@
from influxdb_client.domain.cell import Cell
from influxdb_client.domain.cell_links import CellLinks
from influxdb_client.domain.cell_update import CellUpdate
from influxdb_client.domain.cell_with_view_properties import CellWithViewProperties
from influxdb_client.domain.check import Check
from influxdb_client.domain.check_base import CheckBase
from influxdb_client.domain.check_base_links import CheckBaseLinks
from influxdb_client.domain.check_base_tags import CheckBaseTags
from influxdb_client.domain.check_discriminator import CheckDiscriminator
from influxdb_client.domain.check_patch import CheckPatch
from influxdb_client.domain.check_status_level import CheckStatusLevel
Expand All @@ -87,18 +91,22 @@
from influxdb_client.domain.constant_variable_properties import ConstantVariableProperties
from influxdb_client.domain.create_cell import CreateCell
from influxdb_client.domain.create_dashboard_request import CreateDashboardRequest
from influxdb_client.domain.custom_check import CustomCheck
from influxdb_client.domain.dbrp import DBRP
from influxdb_client.domain.dbrp_update import DBRPUpdate
from influxdb_client.domain.dbr_ps import DBRPs
from influxdb_client.domain.dashboard import Dashboard
from influxdb_client.domain.dashboard_color import DashboardColor
from influxdb_client.domain.dashboard_query import DashboardQuery
from influxdb_client.domain.dashboard_with_view_properties import DashboardWithViewProperties
from influxdb_client.domain.dashboards import Dashboards
from influxdb_client.domain.date_time_literal import DateTimeLiteral
from influxdb_client.domain.deadman_check import DeadmanCheck
from influxdb_client.domain.decimal_places import DecimalPlaces
from influxdb_client.domain.delete_predicate_request import DeletePredicateRequest
from influxdb_client.domain.dialect import Dialect
from influxdb_client.domain.dict_expression import DictExpression
from influxdb_client.domain.dict_item import DictItem
from influxdb_client.domain.document import Document
from influxdb_client.domain.document_create import DocumentCreate
from influxdb_client.domain.document_links import DocumentLinks
Expand Down Expand Up @@ -138,7 +146,6 @@
from influxdb_client.domain.label_update import LabelUpdate
from influxdb_client.domain.labels_response import LabelsResponse
from influxdb_client.domain.language_request import LanguageRequest
from influxdb_client.domain.legend import Legend
from influxdb_client.domain.lesser_threshold import LesserThreshold
from influxdb_client.domain.line_plus_single_stat_properties import LinePlusSingleStatProperties
from influxdb_client.domain.line_protocol_error import LineProtocolError
Expand All @@ -152,6 +159,7 @@
from influxdb_client.domain.member_assignment import MemberAssignment
from influxdb_client.domain.member_expression import MemberExpression
from influxdb_client.domain.model_property import ModelProperty
from influxdb_client.domain.mosaic_view_properties import MosaicViewProperties
from influxdb_client.domain.node import Node
from influxdb_client.domain.notification_endpoint import NotificationEndpoint
from influxdb_client.domain.notification_endpoint_base import NotificationEndpointBase
Expand Down Expand Up @@ -180,6 +188,10 @@
from influxdb_client.domain.pager_duty_notification_rule_base import PagerDutyNotificationRuleBase
from influxdb_client.domain.paren_expression import ParenExpression
from influxdb_client.domain.password_reset_body import PasswordResetBody
from influxdb_client.domain.patch_bucket_request import PatchBucketRequest
from influxdb_client.domain.patch_dashboard_request import PatchDashboardRequest
from influxdb_client.domain.patch_organization_request import PatchOrganizationRequest
from influxdb_client.domain.patch_retention_rule import PatchRetentionRule
from influxdb_client.domain.permission import Permission
from influxdb_client.domain.permission_resource import PermissionResource
from influxdb_client.domain.pipe_expression import PipeExpression
Expand All @@ -188,6 +200,7 @@
from influxdb_client.domain.post_check import PostCheck
from influxdb_client.domain.post_notification_endpoint import PostNotificationEndpoint
from influxdb_client.domain.post_notification_rule import PostNotificationRule
from influxdb_client.domain.post_organization_request import PostOrganizationRequest
from influxdb_client.domain.property_key import PropertyKey
from influxdb_client.domain.query import Query
from influxdb_client.domain.query_edit_mode import QueryEditMode
Expand All @@ -199,6 +212,7 @@
from influxdb_client.domain.renamable_field import RenamableField
from influxdb_client.domain.resource_member import ResourceMember
from influxdb_client.domain.resource_members import ResourceMembers
from influxdb_client.domain.resource_members_links import ResourceMembersLinks
from influxdb_client.domain.resource_owner import ResourceOwner
from influxdb_client.domain.resource_owners import ResourceOwners
from influxdb_client.domain.return_statement import ReturnStatement
Expand All @@ -209,12 +223,12 @@
from influxdb_client.domain.rule_status_level import RuleStatusLevel
from influxdb_client.domain.run import Run
from influxdb_client.domain.run_links import RunLinks
from influxdb_client.domain.run_log import RunLog
from influxdb_client.domain.run_manually import RunManually
from influxdb_client.domain.runs import Runs
from influxdb_client.domain.smtp_notification_rule import SMTPNotificationRule
from influxdb_client.domain.smtp_notification_rule_base import SMTPNotificationRuleBase
from influxdb_client.domain.scatter_view_properties import ScatterViewProperties
from influxdb_client.domain.schema_type import SchemaType
from influxdb_client.domain.scraper_target_request import ScraperTargetRequest
from influxdb_client.domain.scraper_target_response import ScraperTargetResponse
from influxdb_client.domain.scraper_target_responses import ScraperTargetResponses
Expand All @@ -228,9 +242,11 @@
from influxdb_client.domain.source_links import SourceLinks
from influxdb_client.domain.sources import Sources
from influxdb_client.domain.statement import Statement
from influxdb_client.domain.static_legend import StaticLegend
from influxdb_client.domain.status_rule import StatusRule
from influxdb_client.domain.string_literal import StringLiteral
from influxdb_client.domain.table_view_properties import TableViewProperties
from influxdb_client.domain.table_view_properties_table_options import TableViewPropertiesTableOptions
from influxdb_client.domain.tag_rule import TagRule
from influxdb_client.domain.task import Task
from influxdb_client.domain.task_create_request import TaskCreateRequest
Expand All @@ -240,19 +256,23 @@
from influxdb_client.domain.tasks import Tasks
from influxdb_client.domain.telegraf import Telegraf
from influxdb_client.domain.telegraf_plugin import TelegrafPlugin
from influxdb_client.domain.telegraf_plugins import TelegrafPlugins
from influxdb_client.domain.telegraf_request import TelegrafRequest
from influxdb_client.domain.telegraf_request_metadata import TelegrafRequestMetadata
from influxdb_client.domain.telegrafs import Telegrafs
from influxdb_client.domain.telegram_notification_endpoint import TelegramNotificationEndpoint
from influxdb_client.domain.telegram_notification_rule import TelegramNotificationRule
from influxdb_client.domain.telegram_notification_rule_base import TelegramNotificationRuleBase
from influxdb_client.domain.test_statement import TestStatement
from influxdb_client.domain.threshold import Threshold
from influxdb_client.domain.threshold_base import ThresholdBase
from influxdb_client.domain.threshold_check import ThresholdCheck
from influxdb_client.domain.unary_expression import UnaryExpression
from influxdb_client.domain.unsigned_integer_literal import UnsignedIntegerLiteral
from influxdb_client.domain.user import User
from influxdb_client.domain.user_links import UserLinks
from influxdb_client.domain.user_response import UserResponse
from influxdb_client.domain.user_response_links import UserResponseLinks
from influxdb_client.domain.users import Users
from influxdb_client.domain.users_links import UsersLinks
from influxdb_client.domain.variable import Variable
from influxdb_client.domain.variable_assignment import VariableAssignment
from influxdb_client.domain.variable_links import VariableLinks
Expand Down
4 changes: 2 additions & 2 deletions influxdb_client/api_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf-8
"""
Influx API Service.
Influx OSS API Service.
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
OpenAPI spec version: 0.1.0
OpenAPI spec version: 2.0.0
Generated by: https://openapi-generator.tech
"""

Expand Down
Loading

0 comments on commit f851303

Please sign in to comment.