-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat(ui): python onboarding updating to influxdb3 python #6770
Merged
mavarius
merged 3 commits into
master
from
6761-python-onboarding-updating-to-influxdb3-python
Jul 28, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx
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,79 @@ | ||
import React from 'react' | ||
import CodeSnippet from 'src/shared/components/CodeSnippet' | ||
|
||
import {SafeBlankLink} from 'src/utils/SafeBlankLink' | ||
import {event} from 'src/cloud/utils/reporting' | ||
|
||
const logCopyCodeSnippet = () => { | ||
event('firstMile.pythonWizard.executeAggregateQuery.code.copied') | ||
} | ||
|
||
const logDocsOpened = () => { | ||
event('firstMile.pythonWizard.executeAggregateQuery.docs.opened') | ||
} | ||
|
||
type OwnProps = { | ||
bucket: string | ||
} | ||
|
||
export const ExecuteAggregateQuerySql = (props: OwnProps) => { | ||
const {bucket} = props | ||
|
||
const sqlSnippet = `SELECT mean(count) | ||
FROM 'census' | ||
WHERE time > now() - '10m'` | ||
|
||
const querySnippet = `query = """SELECT mean(count) | ||
FROM 'census' | ||
WHERE time > now() - '10m'""" | ||
|
||
# Execute the query | ||
table = client.query(query=query, database="${bucket}", language='influxql') ) | ||
|
||
# Convert to dataframe | ||
df = table.to_pandas().sort_values(by="time") | ||
print(df) | ||
` | ||
|
||
return ( | ||
<> | ||
<h1>Execute an Aggregate Query</h1> | ||
<p> | ||
<SafeBlankLink | ||
href="https://docs.influxdata.com/flux/v0.x/function-types/#aggregates" | ||
onClick={logDocsOpened} | ||
> | ||
Aggregate functions | ||
</SafeBlankLink>{' '} | ||
take the values of all rows in a table and use them to perform an | ||
aggregate operation. The result is output as a new value in a single-row | ||
table. | ||
</p> | ||
<CodeSnippet | ||
text={sqlSnippet} | ||
showCopyControl={false} | ||
onCopy={logCopyCodeSnippet} | ||
language="sql" | ||
/> | ||
<p> | ||
In this example, we use the{' '} | ||
<code className="homepage-wizard--code-highlight">mean()</code> function | ||
to calculate the average value of data points in the last 10 minutes. | ||
<br /> | ||
<br /> | ||
Run the following: | ||
</p> | ||
<CodeSnippet | ||
text={querySnippet} | ||
onCopy={logCopyCodeSnippet} | ||
language="python" | ||
/> | ||
<p> | ||
In this example we use{' '} | ||
<code className="homepage-wizard--code-highlight">InfluxQL</code> to | ||
perform our aggregation. SQL and InfluxQL can be used interchangeably in | ||
the Python client. | ||
</p> | ||
</> | ||
) | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/homepageExperience/components/steps/python/InitializeClientSql.tsx
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,54 @@ | ||
import React from 'react' | ||
import {useSelector} from 'react-redux' | ||
|
||
import CodeSnippet from 'src/shared/components/CodeSnippet' | ||
import {event} from 'src/cloud/utils/reporting' | ||
|
||
import {getOrg} from 'src/organizations/selectors' | ||
import {selectCurrentIdentity} from 'src/identity/selectors' | ||
|
||
const logCopyCodeSnippet = () => { | ||
event('firstMile.pythonWizard.initializeClient.code.copied') | ||
} | ||
|
||
export const InitializeClientSql = () => { | ||
const org = useSelector(getOrg) | ||
const {org: quartzOrg} = useSelector(selectCurrentIdentity) | ||
|
||
const url = quartzOrg.clusterHost || window.location.origin | ||
|
||
const pythonCode = `import os, time | ||
from influxdb_client_3 import InfluxDBClient3, Point | ||
|
||
token = os.environ.get("INFLUXDB_TOKEN") | ||
org = "${org.name}" | ||
host = "${url}" | ||
|
||
client = InfluxDBClient3(host=host, token=token, org=org)` | ||
|
||
return ( | ||
<> | ||
<h1>Initialize Client</h1> | ||
<p> | ||
Run this command in your terminal to open the interactive Python shell: | ||
</p> | ||
<CodeSnippet language="properties" text="python3" /> | ||
<p> | ||
Paste the following code after the prompt (>>>) and press | ||
Enter. | ||
</p> | ||
<CodeSnippet | ||
language="python" | ||
onCopy={logCopyCodeSnippet} | ||
text={pythonCode} | ||
/> | ||
<p> | ||
Here, we initialize the token, organization info, and server url host | ||
that are needed to set up the initial connection to InfluxDB. The client | ||
connection is then established with the{' '} | ||
<code className="homepage-wizard--code-highlight">InfluxDBClient</code>{' '} | ||
initialization. | ||
</p> | ||
</> | ||
) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This flow is cleaner than before 👍