forked from alibaba/opentelemetry-go-auto-instrumentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add metrics for elasticsearch, fiberv2 and mongo (alibaba#278)
- Loading branch information
1 parent
624cd9e
commit a082dcd
Showing
15 changed files
with
403 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
_ "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" | ||
_ "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||
_ "go.opentelemetry.io/otel/exporters/prometheus" | ||
"go.opentelemetry.io/otel/sdk/metric/metricdata" | ||
|
||
_ "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" | ||
|
||
_ "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" | ||
|
||
_ "go.opentelemetry.io/otel/exporters/otlp/otlptrace" | ||
|
||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/alibaba/opentelemetry-go-auto-instrumentation/test/verifier" | ||
"github.com/elastic/go-elasticsearch/v8" | ||
_ "go.opentelemetry.io/otel" | ||
) | ||
|
||
var ( | ||
client *elasticsearch.Client | ||
url = "http://127.0.0.1:" + os.Getenv("OTEL_ES_PORT") | ||
) | ||
|
||
func main() { | ||
port, err := strconv.Atoi(os.Getenv("OTEL_ES_PORT")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
client, err = elasticsearch.NewClient(elasticsearch.Config{ | ||
Addresses: []string{url}, | ||
Password: "123456", | ||
Username: "elastic", | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// creating an index | ||
_, err = client.Indices.Create("my_index") | ||
if err != nil { | ||
log.Printf("failed to create index %v\n", err) | ||
} | ||
|
||
time.Sleep(3 * time.Second) | ||
verifier.WaitAndAssertMetrics(map[string]func(metricdata.ResourceMetrics){ | ||
"http.client.request.duration": func(mrs metricdata.ResourceMetrics) { | ||
if len(mrs.ScopeMetrics) <= 0 { | ||
panic("No http.client.request.duration metrics received!") | ||
} | ||
point := mrs.ScopeMetrics[0].Metrics[0].Data.(metricdata.Histogram[float64]) | ||
if point.DataPoints[0].Count <= 0 { | ||
panic("http.client.request.duration metrics count is not positive, actually " + strconv.Itoa(int(point.DataPoints[0].Count))) | ||
} | ||
verifier.VerifyHttpClientMetricsAttributes(point.DataPoints[0].Attributes.ToSlice(), "PUT", "", "", "http", "1.1", port, 200) | ||
}, | ||
}) | ||
} |
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,67 @@ | ||
// Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/alibaba/opentelemetry-go-auto-instrumentation/test/verifier" | ||
"github.com/elastic/go-elasticsearch/v8" | ||
"go.opentelemetry.io/otel/sdk/metric/metricdata" | ||
) | ||
|
||
var ( | ||
client *elasticsearch.TypedClient | ||
url = "http://127.0.0.1:" + os.Getenv("OTEL_ES_PORT") | ||
) | ||
|
||
func main() { | ||
var err error | ||
client, err = elasticsearch.NewTypedClient(elasticsearch.Config{ | ||
Addresses: []string{url}, | ||
Password: "123456", | ||
Username: "elastic", | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ctx := context.Background() | ||
// creating an index | ||
_, err = client.Indices.Create("my_index").Do(ctx) | ||
if err != nil { | ||
log.Printf("failed to create index %v\n", err) | ||
} | ||
time.Sleep(3 * time.Second) | ||
port, err := strconv.Atoi(os.Getenv("OTEL_ES_PORT")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
verifier.WaitAndAssertMetrics(map[string]func(metricdata.ResourceMetrics){ | ||
"http.client.request.duration": func(mrs metricdata.ResourceMetrics) { | ||
if len(mrs.ScopeMetrics) <= 0 { | ||
panic("No http.client.request.duration metrics received!") | ||
} | ||
point := mrs.ScopeMetrics[0].Metrics[0].Data.(metricdata.Histogram[float64]) | ||
if point.DataPoints[0].Count <= 0 { | ||
panic("http.client.request.duration metrics count is not positive, actually " + strconv.Itoa(int(point.DataPoints[0].Count))) | ||
} | ||
verifier.VerifyHttpClientMetricsAttributes(point.DataPoints[0].Attributes.ToSlice(), "PUT", "", "", "http", "1.1", port, 200) | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.