Skip to content
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

chore: update vendored proto file #115

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Added

- Add `AppInstanceSettings::api_version` and `DataSourceInstanceSettings::api_version` fields.

### Changed

- Update the vendored protobuf definitions to match version 0.249.0 of the Go SDK.
This has also added a new field, `api_version`, to the `AppInstanceSettings` and
`DataSourceInstanceSettings` structs.

## [0.5.0] - 2024-09-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/grafana-plugin-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.5.0"
authors = ["Ben Sully <ben.sully@grafana.com>"]
license = "MIT/Apache-2.0"
edition = "2021"
rust-version = "1.63"
rust-version = "1.77"
repository = "https://github.com/grafana/grafana-plugin-sdk-rust"
description = "SDK for building Grafana backend plugins."

Expand Down
18 changes: 15 additions & 3 deletions crates/grafana-plugin-sdk/src/backend/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use futures_util::StreamExt;
use serde::de::DeserializeOwned;

use crate::{
backend::{self, ConvertFromError, InstanceSettings, TimeRange},
backend::{
self, error_source::ErrorSource, ConvertFromError, GrafanaPlugin, InstanceSettings,
PluginType, TimeRange,
},
data, pluginv2,
};

use super::{GrafanaPlugin, PluginType};

/// A request for data made by Grafana.
///
/// Details of the request source can be found in `plugin_context`,
Expand Down Expand Up @@ -184,6 +185,13 @@ pub trait DataQueryError: std::error::Error {
fn status(&self) -> DataQueryStatus {
DataQueryStatus::Unknown
}

/// The source of the error.
///
/// Defaults to [`ErrorSource::Plugin`] if not overridden.
fn source(&self) -> ErrorSource {
ErrorSource::default()
}
}

/// Status codes for [`DataQueryError`].
Expand Down Expand Up @@ -454,6 +462,7 @@ where
status: DataQueryStatus::Internal.as_i32(),
error: e.to_string(),
json_meta: vec![],
error_source: ErrorSource::Plugin.to_string(),
},
)
},
Expand All @@ -465,13 +474,15 @@ where
status: DataQueryStatus::OK.as_i32(),
error: "".to_string(),
json_meta: vec![],
error_source: "".to_string(),
},
)
},
)
}
Err(e) => {
let status = e.status().as_i32();
let source = e.source().to_string();
let err_string = e.to_string();
(
e.ref_id(),
Expand All @@ -480,6 +491,7 @@ where
status,
error: err_string,
json_meta: vec![],
error_source: source,
},
)
}
Expand Down
23 changes: 23 additions & 0 deletions crates/grafana-plugin-sdk/src/backend/error_source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::fmt;

/// The source of an error.
///
/// This is used to indicate whether the error occurred in the plugin or downstream.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorSource {
/// The error occurred in the plugin.
#[default]
Plugin,
/// The error occurred downstream of the plugin.
Downstream,
}

impl fmt::Display for ErrorSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Plugin => f.write_str("plugin"),
Self::Downstream => f.write_str("downstream"),
}
}
}
14 changes: 14 additions & 0 deletions crates/grafana-plugin-sdk/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub use tonic::async_trait;

mod data;
mod diagnostics;
mod error_source;
mod noop;
mod resource;
mod stream;
Expand All @@ -170,6 +171,7 @@ pub use diagnostics::{
CheckHealthRequest, CheckHealthResponse, CollectMetricsRequest, CollectMetricsResponse,
DiagnosticsService, HealthStatus, Payload as MetricsPayload,
};
pub use error_source::ErrorSource;
pub use resource::{
BoxResourceFuture, BoxResourceStream, CallResourceRequest, ErrIntoHttpResponse,
IntoHttpResponse, ResourceService,
Expand Down Expand Up @@ -879,6 +881,10 @@ pub struct AppInstanceSettings<JsonData, SecureJsonData> {
pub decrypted_secure_json_data: SecureJsonData,
/// The last time the configuration for the app plugin instance was updated.
pub updated: DateTime<Utc>,

/// The API version when the settings were saved.
/// NOTE: this may be an older version than the current apiVersion.
pub api_version: String,
}

impl<JsonData, SecureJsonData> Debug for AppInstanceSettings<JsonData, SecureJsonData>
Expand All @@ -890,6 +896,7 @@ where
.field("json_data", &self.json_data)
.field("decrypted_secure_json_data", &"<redacted>")
.field("updated", &self.updated)
.field("api_version", &self.api_version)
.finish()
}
}
Expand Down Expand Up @@ -918,6 +925,7 @@ where
.ok_or(ConvertFromError::InvalidTimestamp {
timestamp: proto.last_updated_ms,
})?,
api_version: proto.api_version,
})
})
.transpose()
Expand Down Expand Up @@ -988,6 +996,10 @@ pub struct DataSourceInstanceSettings<JsonData, SecureJsonData> {

/// The last time the configuration for the datasource instance was updated.
pub updated: DateTime<Utc>,

/// The API version when the settings were saved.
/// NOTE: this may be an older version than the current apiVersion.
pub api_version: String,
}

impl<JsonData, SecureJsonData> Debug for DataSourceInstanceSettings<JsonData, SecureJsonData>
Expand All @@ -1008,6 +1020,7 @@ where
.field("json_data", &self.json_data)
.field("decrypted_secure_json_data", &"<redacted>")
.field("updated", &self.updated)
.field("api_version", &self.api_version)
.finish()
}
}
Expand Down Expand Up @@ -1045,6 +1058,7 @@ where
.ok_or(ConvertFromError::InvalidTimestamp {
timestamp: proto.last_updated_ms,
})?,
api_version: proto.api_version,
})
})
.transpose()
Expand Down
Loading
Loading