Skip to content

Commit 7cfaa32

Browse files
authored
Merge pull request #46 from cbullinger/docsp-49329-push-artifact-repo-config-fix
DOCSP-49329: Copier App config fix to push artifact repo files out
2 parents 1f56be5 + 918025a commit 7cfaa32

File tree

3 files changed

+179
-1
lines changed

3 files changed

+179
-1
lines changed

config.json

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,58 @@
66
"target_branch" : "copy-test",
77
"target_directory" : "."
88
},
9+
{
10+
"notes": "atlas-sdk-go/project-copy/cmd subdirectory",
11+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/cmd",
12+
"target_repo" : "atlas-architecture-go-sdk",
13+
"target_branch" : "copy-test",
14+
"target_directory" : "cmd"
15+
},
16+
{
17+
"notes": "atlas-sdk-go/project-copy/cmd/get_logs subdirectory",
18+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/cmd/get_logs",
19+
"target_repo" : "atlas-architecture-go-sdk",
20+
"target_branch" : "copy-test",
21+
"target_directory" : "cmd/get_logs"
22+
},
23+
{
24+
"notes": "atlas-sdk-go/project-copy/cmd/get_metrics_process subdirectory",
25+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/cmd/get_metrics_process",
26+
"target_repo" : "atlas-architecture-go-sdk",
27+
"target_branch" : "copy-test",
28+
"target_directory" : "cmd/get_metrics_process"
29+
},
30+
{
31+
"notes": "atlas-sdk-go/project-copy/cmd/get_metrics_disk subdirectory",
32+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/cmd/get_metrics_disk",
33+
"target_repo" : "atlas-architecture-go-sdk",
34+
"target_branch" : "copy-test",
35+
"target_directory" : "cmd/get_metrics_disk"
36+
},
37+
{
38+
"notes": "atlas-sdk-go/project-copy/configs",
39+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/configs",
40+
"target_repo" : "atlas-architecture-go-sdk",
41+
"target_branch" : "copy-test",
42+
"target_directory" : "configs"
43+
},
44+
{
45+
"notes": "atlas-sdk-go/project-copy/internal subdirectory",
46+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/internal",
47+
"target_repo" : "atlas-architecture-go-sdk",
48+
"target_branch" : "copy-test",
49+
"target_directory" : "internal"
50+
},
51+
{
52+
"notes": "atlas-sdk-go/project-copy/internal/auth subdirectory",
53+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/internal/auth",
54+
"target_repo" : "atlas-architecture-go-sdk",
55+
"target_branch" : "copy-test",
56+
"target_directory" : "internal/auth"
57+
},
958
{
1059
"notes": "Copy atlas-sdk-go project files to user-facing Atlas Architecture Center artifact repo root",
11-
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/**",
60+
"source_directory" : "generated-usage-examples/go/atlas-sdk-go/project-copy/",
1261
"target_repo" : "atlas-architecture-go-sdk",
1362
"target_branch" : "copy-test-2",
1463
"target_directory" : "."
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"atlas-sdk-go/internal/auth"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
"go.mongodb.org/atlas-sdk/v20250219001/admin"
9+
"log"
10+
)
11+
12+
// getDiskMetrics fetches metrics for a specified disk partition in a project and prints results to the console
13+
func getDiskMetrics(ctx context.Context, atlasClient admin.APIClient, params *admin.GetDiskMeasurementsApiParams) (*admin.ApiMeasurementsGeneralViewAtlas, error) {
14+
15+
resp, _, err := atlasClient.MonitoringAndLogsApi.GetDiskMeasurementsWithParams(ctx, params).Execute()
16+
if err != nil {
17+
if apiError, ok := admin.AsError(err); ok {
18+
return nil, fmt.Errorf("failed to get metrics for partition: %s (API error: %v)", err, apiError.GetDetail())
19+
}
20+
return nil, fmt.Errorf("failed to get metrics: %w", err)
21+
}
22+
if resp == nil || resp.HasMeasurements() == false {
23+
return nil, fmt.Errorf("no metrics found for partition %s in project %s", params.PartitionName, params.GroupId)
24+
}
25+
jsonData, err := json.MarshalIndent(resp, "", " ")
26+
if err != nil {
27+
return nil, fmt.Errorf("failed to marshal response: %w", err)
28+
}
29+
fmt.Println(string(jsonData))
30+
return resp, nil
31+
}
32+
33+
func main() {
34+
ctx := context.Background()
35+
36+
// Create an Atlas client authenticated using OAuth2 with service account credentials
37+
atlasClient, _, config, err := auth.CreateAtlasClient()
38+
if err != nil {
39+
log.Fatalf("Failed to create Atlas client: %v", err)
40+
}
41+
42+
// Fetch disk metrics using the following parameters:
43+
partitionName := "data"
44+
diskMetricsGranularity := admin.PtrString("P1D")
45+
diskMetricsPeriod := admin.PtrString("P1D")
46+
diskMetrics := []string{
47+
"DISK_PARTITION_SPACE_FREE", "DISK_PARTITION_SPACE_USED",
48+
}
49+
50+
diskMeasurementsParams := &admin.GetDiskMeasurementsApiParams{
51+
GroupId: config.ProjectID,
52+
ProcessId: config.ProcessID,
53+
PartitionName: partitionName,
54+
M: &diskMetrics,
55+
Granularity: diskMetricsGranularity,
56+
Period: diskMetricsPeriod,
57+
}
58+
_, err = getDiskMetrics(ctx, *atlasClient, diskMeasurementsParams)
59+
if err != nil {
60+
fmt.Printf("Error fetching disk metrics: %v", err)
61+
}
62+
}
63+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"atlas-sdk-go/internal/auth"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
"go.mongodb.org/atlas-sdk/v20250219001/admin"
9+
"log"
10+
)
11+
12+
// getProcessMetrics fetches metrics for a specified host process in a project and prints results to the console
13+
func getProcessMetrics(ctx context.Context, atlasClient admin.APIClient, params *admin.GetHostMeasurementsApiParams) (*admin.ApiMeasurementsGeneralViewAtlas, error) {
14+
fmt.Printf("Fetching metrics for host process %s in project %s", params.ProcessId, params.GroupId)
15+
16+
resp, _, err := atlasClient.MonitoringAndLogsApi.GetHostMeasurementsWithParams(ctx, params).Execute()
17+
if err != nil {
18+
if apiError, ok := admin.AsError(err); ok {
19+
return nil, fmt.Errorf("failed to get metrics for process in host: %s (API error: %v)", err, apiError.GetDetail())
20+
}
21+
return nil, fmt.Errorf("failed to get metrics: %w", err)
22+
}
23+
24+
if resp == nil || resp.HasMeasurements() == false {
25+
return nil, fmt.Errorf("no metrics found for host process %s in project %s", params.ProcessId, params.GroupId)
26+
}
27+
jsonData, err := json.MarshalIndent(resp, "", " ")
28+
if err != nil {
29+
return nil, fmt.Errorf("failed to marshal response: %w", err)
30+
}
31+
fmt.Println(string(jsonData))
32+
return resp, nil
33+
}
34+
35+
func main() {
36+
ctx := context.Background()
37+
38+
// Create an Atlas client authenticated using OAuth2 with service account credentials
39+
atlasClient, _, config, err := auth.CreateAtlasClient()
40+
if err != nil {
41+
log.Fatalf("Failed to create Atlas client: %v", err)
42+
}
43+
44+
// Fetch process metrics using the following parameters:
45+
processMetricGranularity := admin.PtrString("PT1H")
46+
processMetricPeriod := admin.PtrString("P7D")
47+
processMetrics := []string{
48+
"OPCOUNTER_INSERT", "OPCOUNTER_QUERY", "OPCOUNTER_UPDATE", "TICKETS_AVAILABLE_READS",
49+
"TICKETS_AVAILABLE_WRITE", "CONNECTIONS", "QUERY_TARGETING_SCANNED_OBJECTS_PER_RETURNED",
50+
"QUERY_TARGETING_SCANNED_PER_RETURNED", "SYSTEM_CPU_GUEST", "SYSTEM_CPU_IOWAIT",
51+
"SYSTEM_CPU_IRQ", "SYSTEM_CPU_KERNEL", "SYSTEM_CPU_NICE", "SYSTEM_CPU_SOFTIRQ",
52+
"SYSTEM_CPU_STEAL", "SYSTEM_CPU_USER",
53+
}
54+
hostMeasurementsParams := &admin.GetHostMeasurementsApiParams{
55+
GroupId: config.ProjectID,
56+
ProcessId: config.ProcessID,
57+
M: &processMetrics,
58+
Granularity: processMetricGranularity,
59+
Period: processMetricPeriod,
60+
}
61+
_, err = getProcessMetrics(ctx, *atlasClient, hostMeasurementsParams)
62+
if err != nil {
63+
fmt.Printf("Error fetching host process metrics: %v", err)
64+
}
65+
}
66+

0 commit comments

Comments
 (0)