Skip to content

Commit d4f4b72

Browse files
authored
feat(feo11y): Add collector endpoint on data source (#2044)
1 parent d608af1 commit d4f4b72

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

docs/data-sources/frontend_o11y_app.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ data "grafana_frontend_o11y_app" "test-app" {
3636
### Read-Only
3737

3838
- `allowed_origins` (List of String) A list of allowed origins for CORS.
39+
- `collector_endpoint` (String) The collector URL Grafana Cloud Frontend Observability. Use this endpoint to send your Telemetry.
3940
- `extra_log_attributes` (Map of String) The extra attributes to append in each signal.
4041
- `id` (Number) The Terraform Resource ID. This auto-generated from Frontend Observability API.
4142
- `settings` (Map of String) The settings of the Frontend Observability App.

docs/resources/frontend_o11y_app.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "grafana_frontend_o11y_app" "test-app" {
4747

4848
### Read-Only
4949

50+
- `collector_endpoint` (String) The collector URL Grafana Cloud Frontend Observability. Use this endpoint to send your Telemetry.
5051
- `id` (Number) The Terraform Resource ID. This is auto-generated from Frontend Observability API.
5152

5253
## Import

internal/common/frontendo11yapi/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type App struct {
7474
CORSAllowedOrigins []AllowedOrigin `json:"corsOrigins,omitempty"`
7575
AllowedRate uint64 `json:"allowedRate,omitempty"`
7676
Settings map[string]string `json:"settings,omitempty"`
77+
CollectEndpointURL string `json:"collectEndpointURL,omitempty"`
7778

7879
CreatedAt *time.Time `json:"createdAt,omitempty"`
7980
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
@@ -229,6 +230,7 @@ func (a *App) UnmarshalJSON(input []byte) error {
229230
a.CreatedAt = raw.CreatedAt
230231
a.UpdatedAt = raw.UpdatedAt
231232
a.DeletedAt = raw.DeletedAt
233+
a.CollectEndpointURL = raw.CollectEndpointURL
232234

233235
return nil
234236
}

internal/resources/frontendo11y/data_source_frontend_o11y_app.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (r *datasourceFrontendO11yApp) Schema(ctx context.Context, req datasource.S
6262
Description: "The name of the Frontend Observability App. Part of the Terraform Resource ID.",
6363
Required: true,
6464
},
65+
"collector_endpoint": schema.StringAttribute{
66+
Description: "The collector URL Grafana Cloud Frontend Observability. Use this endpoint to send your Telemetry.",
67+
Computed: true,
68+
},
6569
"allowed_origins": schema.ListAttribute{
6670
Description: "A list of allowed origins for CORS.",
6771
ElementType: types.StringType,

internal/resources/frontendo11y/models.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package frontendo11y
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/hashicorp/terraform-plugin-framework/attr"
78
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -17,6 +18,7 @@ type FrontendO11yAppTFModel struct {
1718
AllowedOrigins types.List `tfsdk:"allowed_origins"`
1819
ExtraLogAtrributes types.Map `tfsdk:"extra_log_attributes"`
1920
Settings types.Map `tfsdk:"settings"`
21+
CollectorEndpoint types.String `tfsdk:"collector_endpoint"`
2022
}
2123

2224
// toClientModel converts a FrontendO11yAppTFModel instance to a frontendo11yapi.App instance.
@@ -63,6 +65,7 @@ func (tfData FrontendO11yAppTFModel) toClientModel(ctx context.Context) (fronten
6365
CORSAllowedOrigins: allowedOrigins,
6466
ExtraLogLabels: extraLogLabels,
6567
Settings: actualSettings,
68+
CollectEndpointURL: tfData.CollectorEndpoint.ValueString(),
6669
}, conversionDiags
6770
}
6871

@@ -100,6 +103,7 @@ func convertClientModelToTFModel(stackID int64, app frontendo11yapi.App) (Fronte
100103
AllowedOrigins: tfAllowedOriginsValue,
101104
ExtraLogAtrributes: tfExtraLogAttributes,
102105
Settings: tfSettings,
106+
CollectorEndpoint: types.StringValue(fmt.Sprintf("%s/%s", app.CollectEndpointURL, app.Key)),
103107
}
104108

105109
return resp, diags

internal/resources/frontendo11y/resource_frontend_o11y_app.go

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func (r *resourceFrontendO11yApp) Schema(ctx context.Context, req resource.Schem
8686
stringplanmodifier.RequiresReplace(),
8787
},
8888
},
89+
"collector_endpoint": schema.StringAttribute{
90+
Description: "The collector URL Grafana Cloud Frontend Observability. Use this endpoint to send your Telemetry.",
91+
Computed: true,
92+
PlanModifiers: []planmodifier.String{
93+
stringplanmodifier.UseStateForUnknown(),
94+
},
95+
},
8996
"allowed_origins": schema.ListAttribute{
9097
Description: "A list of allowed origins for CORS.",
9198
ElementType: types.StringType,

0 commit comments

Comments
 (0)