Skip to content

Commit

Permalink
Pull and extract Go and Java examples (#7446)
Browse files Browse the repository at this point in the history
* Include required query arguments in curl examples

* Pull and extract Go examples

* use prebuild

* Revert "use prebuild"

This reverts commit 6ba1ddb.

* Include make and gawk in build image

* Fix permissions

* touch Makefile.config

* Respect existing files

* Add Java examples

* Hups

* Fail on wrong example format

Co-authored-by: david.jones <david.jones@datadoghq.com>
  • Loading branch information
jirikuncar and davidejones authored May 27, 2020
1 parent 7079c3d commit a31c31b
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ public/
data/service_checks/
integrations_data

# Ignore generated examples
/examples
content/en/api/**/*.go
content/en/api/**/*.java

# Ignoring all automated content
# Developers/integrations
content/en/developers/integrations/*.md
Expand Down
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ build_preview:
script:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- version_static_assets
- touch Makefile.config
- make examples
- sync_integration_descriptions
#- sync_integration_descriptions_cached
- placehold_translations
Expand Down Expand Up @@ -117,6 +119,8 @@ build_live:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- notify_slack "<https://github.com/DataDog/documentation/commit/${CI_COMMIT_SHA}|${CI_COMMIT_SHA:0:8}> sent to gitlab for production deployment. <${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}|details>" "#FFD700"
- version_static_assets
- touch Makefile.config
- make examples
- sync_integration_descriptions
- sync_integration_metrics
- placehold_translations
Expand Down
40 changes: 38 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# make
.PHONY: clean clean-all clean-build clean-exe clean-integrations clean-auto-doc clean-node clean-virt help start stop
.PHONY: clean clean-all clean-build clean-examples clean-go-examples clean-java-examples clean-exe clean-integrations clean-auto-doc clean-node clean-virt help start stop
.DEFAULT_GOAL := help
PY3=$(shell if [ `which pyenv` ]; then \
if [ `pyenv which python3` ]; then \
Expand Down Expand Up @@ -34,6 +34,7 @@ clean-all: stop ## Clean everything.
make clean-auto-doc
make clean-node
make clean-virt
make clean-examples

clean-build: ## Remove build artifacts.
@if [ -d public ]; then rm -r public; fi
Expand Down Expand Up @@ -128,7 +129,7 @@ source-helpers: hugpython ## Source the helper functions used in build, test, d
@find ${LOCALBIN}/* -type f -exec cp {} ${EXEDIR} \;
@cp -r local/githooks/* .git/hooks

start: clean source-helpers ## Build the documentation with all external content.
start: clean source-helpers examples ## Build the documentation with all external content.
@echo "\033[35m\033[1m\nBuilding the documentation with ALL external content:\033[0m"
@if [ ${PY3} != "false" ]; then \
source ${VIRENV}/bin/activate; \
Expand All @@ -152,3 +153,38 @@ stop: ## Stop wepack watch/hugo server.
@echo "stopping previous..."
@pkill -x webpack || true
@pkill -x hugo server --renderToDisk || true

clean-go-examples:
@git clean -xdf content/en/api/**/*.go

clean-java-examples:
@git clean -xdf content/en/api/**/*.java

clean-examples: clean-go-examples clean-java-examples
@rm -rf examples

examples/datadog-api-client-go:
@git clone https://github.com/DataDog/datadog-api-client-go.git examples/datadog-api-client-go

examples/datadog-api-client-java:
@git clone https://github.com/DataDog/datadog-api-client-java.git examples/datadog-api-client-java

.PHONY: examples/go examples/java examples

examples/go: examples/datadog-api-client-go clean-go-examples local/bin/awk/extract-code-blocks-go.awk
@ls examples/datadog-api-client-go/api/v1/datadog/docs/*Api.md | xargs -n1 local/bin/awk/extract-code-blocks-go.awk -v output=examples/content/en/api/v1
@ls examples/datadog-api-client-go/api/v2/datadog/docs/*Api.md | xargs -n1 local/bin/awk/extract-code-blocks-go.awk -v output=examples/content/en/api/v2

#for f in examples/content/en/api/v*/*/*.go ; do \
# gofmt -w $$f || rm $f; \
#done;

cp -Rn examples/content ./

examples/java: examples/datadog-api-client-java clean-java-examples local/bin/awk/extract-code-blocks-java.awk
@ls examples/datadog-api-client-java/api_docs/v1/*Api.md | xargs -n1 local/bin/awk/extract-code-blocks-java.awk -v output=examples/content/en/api/v1
@ls examples/datadog-api-client-java/api_docs/v2/*Api.md | xargs -n1 local/bin/awk/extract-code-blocks-java.awk -v output=examples/content/en/api/v2

cp -Rn examples/content ./

examples: examples/go examples/java
8 changes: 4 additions & 4 deletions content/en/agent/logs/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ further_reading:

Log collection requires the Datadog Agent v6.0+. Older versions of the Agent do not include the `log collection` interface.

As of Agent v6.14/v7.14, Datadog recommends the use of and enforcing **HTTPS** transport (see [agent Transport for Logs][2]).
If you are using the HTTPS transport for logs, please refer to the [agent proxy documentation][1] and use the same set of proxy settings as other data types.
As of Agent v6.14/v7.14, Datadog recommends the use of and enforcing **HTTPS** transport (see [agent Transport for Logs][1]).
If you are using the HTTPS transport for logs, please refer to the [agent proxy documentation][2] and use the same set of proxy settings as other data types.


## TCP log forwarding
Expand Down Expand Up @@ -295,5 +295,5 @@ stream {

{{< partial name="whats-next/whats-next.html" >}}

[1]: /agent/proxy/
[2]: /agent/logs/log_transport?tab=https
[1]: /agent/logs/log_transport?tab=https
[2]: /agent/proxy/
5 changes: 2 additions & 3 deletions content/en/integrations/faq/azure-status-metric.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Use the `azure.*.count` metric to:
- Create monitors to alert you about the status of different Azure resources.

**Note**: In some cases, the default visualization settings can make it appear as though resources are being double counted intermittently in charts or query widgets. This will not affect monitors or widgets scoped to a specific status.
You can reduce this effect by turning off [interpolation][3] in charts or query widgets by setting Interpolation > none or using ‘.fill(null)’.
You can reduce this effect by turning off [interpolation][2] in charts or query widgets by setting Interpolation > none or using ‘.fill(null)’.

For most resource types, the possible statuses are running, unavailable, or unknown. Virtual machines have more detailed statuses, including:

Expand Down Expand Up @@ -68,5 +68,4 @@ azure provider register Microsoft.ResourceHealth
The `azure.*.status` metric should show in Datadog within 5 - 10 minutes.

[1]: /integrations/azure/
[2]: /help/
[3]: /dashboards/faq/interpolation-the-fill-modifier-explained/
[2]: /dashboards/faq/interpolation-the-fill-modifier-explained/
17 changes: 8 additions & 9 deletions content/en/monitors/monitor_types/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ To create a [logs monitor][2] in Datadog, use the main navigation: *Monitors -->

As you define the search query, the graph above the search fields updates.

1. Construct a search query using the same logic as a [log explorer search][4].
2. Choose to monitor over a log count, [facet][5], or [measure][5]:
1. Construct a search query using the same logic as a [log explorer search][3].
2. Choose to monitor over a log count, [facet][4], or [measure][4]:
* **Monitor over a log count**: Use the search bar (optional) and do **not** select a facet or measure. Datadog evaluates the number of logs over a selected time frame, then compares it to the threshold conditions.
* **Monitor over a facet**: If a [facet][5] is selected, the monitor alerts over the `Unique value count` of the facet.
* **Monitor over measure**: If a [measure][5] is selected, the monitor alerts over the numerical value of the log facet (similar to a metric monitor) and aggregation needs to be selected (`min`, `avg`, `sum`, `median`, `pc75`, `pc90`, `pc95`, `pc98`, `pc99`, or `max`).
* **Monitor over a facet**: If a [facet][4] is selected, the monitor alerts over the `Unique value count` of the facet.
* **Monitor over measure**: If a [measure][4] is selected, the monitor alerts over the numerical value of the log facet (similar to a metric monitor) and aggregation needs to be selected (`min`, `avg`, `sum`, `median`, `pc75`, `pc90`, `pc95`, `pc98`, `pc99`, or `max`).
3. Define the alert grouping (optional). **Note**: With or without alert grouping defined, you get **one** alert when the aggregated value meets the set conditions. Even if you split the query by host, a single notification is sent if several hosts meet the set conditions. This is done to reduce notification noise.


Expand All @@ -55,7 +55,7 @@ When splitting the monitor by any dimension (tag or facet) and using a `below` c

### Notifications

For detailed instructions on the **Say what's happening** and **Notify your team** sections, see the [Notifications][6] page.
For detailed instructions on the **Say what's happening** and **Notify your team** sections, see the [Notifications][5] page.

#### Log samples

Expand Down Expand Up @@ -84,7 +84,6 @@ Include a sample of 10 logs in the alert notification:

[1]: /logs/
[2]: https://app.datadoghq.com/monitors#create/log
[3]: /logs/indexes/
[4]: /logs/explorer/search/
[5]: /logs/explorer/facets/
[6]: /monitors/notifications/
[3]: /logs/explorer/search/
[4]: /logs/explorer/facets/
[5]: /monitors/notifications/
57 changes: 57 additions & 0 deletions local/bin/awk/extract-code-blocks-go.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env -S awk -f
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Based on https://codereview.stackexchange.com/questions/194986/print-code-fenced-sections-of-a-markdown-document/195030#195030
BEGIN {
in_code_block = 0;
tag = "";
operation_id = "";
}

function slug(value) {
head = "";
tail = value;
while ( match(tail,/[[:upper:]][[:lower:]]/) ) {
tgt = substr(tail,RSTART,1);
if ( substr(tail,RSTART-1,1) ~ /[[:lower:]]/ ) {
tgt = "-" tolower(tgt);
}
head = head substr(tail,1,RSTART-1) tgt;
tail = substr(tail,RSTART+1);
}
return tolower(head) tail;
}

/^# \\.+Api/ {
tag = slug(substr($2, 2, length($2)-4));
}
/^## / {
operation_id = $2;
}
/^```go/ {
if (in_code_block == 0) {
in_code_block = 1;
if (out_file) {
close(out_file);
}
system("mkdir -p " output "/" tag);
out_file=output "/" tag "/" operation_id ".go";
print out_file;
} else {
print "Can't parse " FILENAME > "/dev/stderr"
exit 1
}
next;
}
/^```/ {
in_code_block = 0;
}

in_code_block {
# Make sure that the file is newly created
if (in_code_block == 1) {
in_code_block = 2;
print > out_file;
} else {
print >> out_file;
}
}
56 changes: 56 additions & 0 deletions local/bin/awk/extract-code-blocks-java.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env -S awk -f
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Based on https://codereview.stackexchange.com/questions/194986/print-code-fenced-sections-of-a-markdown-document/195030#195030
BEGIN {
in_code_block = 0;
tag = "";
operation_id = "";
}

function slug(value) {
head = "";
tail = value;
while ( match(tail,/[[:upper:]][[:lower:]]/) ) {
tgt = substr(tail,RSTART,1);
if ( substr(tail,RSTART-1,1) ~ /[[:lower:]]/ ) {
tgt = "-" tolower(tgt);
}
head = head substr(tail,1,RSTART-1) tgt;
tail = substr(tail,RSTART+1);
}
return tolower(head) tail;
}

/^# .+Api/ {
tag = slug(substr($2, 0, length($2)-3));
}
/^## / {
operation_id = toupper( substr( $2, 1, 1 ) ) substr( $2, 2 );
}
/^```java/ {
if (in_code_block == 0) {
in_code_block = 1;
if (out_file) {
close(out_file);
}
system("mkdir -p " output "/" tag);
out_file=output "/" tag "/" operation_id ".java";
print out_file;
} else {
print "Can't parse " FILENAME > "/dev/stderr"
exit 1
}
next;
}
/^```/ {
in_code_block = 0;
}
in_code_block {
# Make sure that the file is newly created
if (in_code_block == 1) {
in_code_block = 2;
print > out_file;
} else {
print >> out_file;
}
}

0 comments on commit a31c31b

Please sign in to comment.